You can perform basic CRUD operations on SharePoint lists, libraries, sites using REST API's.
Here is an example with sample code to create list item with REST endpoint.
The post covers steps to test the query from Postman. Once tested successfully, it can be used with your code (C#, Python, Java, Power Automate, SPFX, etc.).
⚡️ Create SharePoint list item from Postman
Assumptions for this example, you have configuration like below.- SharePoint Tenant Name = c2c
- SharePoint Site Name = SPDev
- SharePoint List Name = Projects
- SharePoint List Columns = Title, Comments
- SharePoint Add-in App is already configured with Client Id and Secret for accessing externally, refer below reference articles.
o Steps to generate SharePoint Client Id and Secret
o Steps to test SharePoint REST API from Postman
- Launch the Postman tool.
- Select POST Method for Request (refer image below).
- In the "Enter request URL" textbox, enter URL in this format.
- Navigate to the Header section and add below 3 KEY's (steps to generate Token)
- Navigate to the Body section and select raw/JSON. Copy-paste below JSON code which will create a ListItem in SharePoint List.
- Click Send button to submit the request.
- If all configurations are correct, you will see a success response with Status "201 Created".
- Navigate to the SharePoint list in order to confirm the list item is created successfully based on the values passed in JSON.
FORMAT --> https://[Tenant].sharepoint.com/sites/[SiteName]/_api/web/lists/GetByTitle('[ListName]')/items
EXAMPLE --> https://c2c.sharepoint.com/sites/SPDev/_api/web/lists/GetByTitle('Projects')/items
Authorization | Bearer [Token] |
Accept | application/json;odata=verbose |
Content-Type | application/json;odata=verbose |
{ "__metadata": {"type": "SP.Data.ProjectsListItem"},
"Title": "New Title 1",
"Comments": "This entry is created from Postman"
}
Important - Value for type will be in this format --> SP.Data.[ListName]ListItem⛏️ Troubleshooting
You may face some errors/exceptions while working with SharePoint REST API's using Postman, here are solutions to some common problems.
403 Forbidden - UnauthorizedAccessException - Access denied
<?xml version="1.0" encoding="utf-8"?>
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<m:code>-2147024891, System.UnauthorizedAccessException</m:code>
<m:message xml:lang="en-US">Access denied. You do not have permission to perform this action or access this resource.</m:message>
</m:error>
Solution - You are missing the Authorization Key in Headers, Postman used the bearer token to connect to SharePoint. Refer earlier steps to add Authorization key in Header section and how to generate the token.
400 Bad Request - InvalidClientQueryException - An unexpected 'PrimitiveValue' node was found
{
"error": {
"code": "-1, Microsoft.SharePoint.Client.InvalidClientQueryException",
"message": {
"lang": "en-US",
"value": "An unexpected 'PrimitiveValue' node was found when reading from the JSON reader. A 'StartObject' node was expected."
}
}
}
Solution - Most probably, your JSON is not well formed. Check for additional or missing braces, quotes. There are many online tools available to validate JSON, use them to fix the JSON code before using.
400 Bad Request - InvalidClientQueryException - The property '__metadata' does not exist
{
"error": {
"code": "-1, Microsoft.SharePoint.Client.InvalidClientQueryException",
"message": {
"lang": "en-US",
"value": "The property '__metadata' does not exist on type 'SP.Data.ProjectsListItem'. Make sure to only use property names that are defined by the type."
}
}
}
Solution - Ensure that the Content-Type request header value is application/json;odata=verbose and not application/json.
Now you can use this code in SPFX web part (modern), or JQuery + HTML (classic), or may be even directly embed in Content Editor web part / Script Editor web part.
Try to extend the basic code to build more complex queries like adding a lookup value, adding user in a people picker field, add values to Managed Metadata columns, etc.
Have Questions? Post them here!
- SharePoint error - An exception occurred when trying to issue security token: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms..
- PowerShell iterate and get all SharePoint sites and sub sites
- SharePoint Online: Editing session has ended Message
- How to Share Microsoft SharePoint Site with Users or Groups
- How to delete SharePoint Online List Item using REST API
- SharePoint List excel import - This table exceeds the maximum number of supported rows
- How to disable SharePoint subsite creation option for owners
- SharePoint 2010 August 2015 Update KB3055049 - Duplicate Document ID issue bug fixed
- SharePoint Server 2016 Preview installation error - This Product Key isn't a valid Microsoft Office 2016 Product Key. Check that you've entered it correctly.
- How to upload file programmatically to SharePoint Document Library using Server Object Model C# .Net
- Access URL for SharePoint Tenant Admin Center (Online Office 365)
- Error when deleting SharePoint Online folder or file
- How to extend retiring SharePoint 2010 Workflows and continue with Office 365
- How to generate client id and secret to register SharePoint App with OAuth
- How to delete SharePoint List Item programmatically using C#.Net
- How to retrieve all SharePoint Online List Items using Rest API
- [Solved] SharePoint Search Internal server error exception
- Create SharePoint Site Collection using PowerShell New-SPSite
- Fix SharePoint PowerShell error - The term Get-SPweb is not recognized as the name of a cmdlet function script file or operable program
- How to enable anonymous public access for SharePoint Online site collection, file, folder without login ?
- SharePoint Server 2016 installation System Hardware requirements
- How to create SharePoint Online List Item using REST API
- Changed AD user display name showing old name in SharePoint
- Recommended size and resolution for SharePoint Online Site logo
- Microsoft 365: How to Turn Off Delve in SharePoint Online for All Users
- 11 Weeks of Android Online Sessions-15-Jun-to-28-Aug-2020 - Android
- [Fix] java: incompatible types: java.lang.String cannot be converted to int - Java
- How to clear Cache, Cookies and History on iPhone Safari - iOS
- Fix: SpringFramework BeanDefinitionValidationException: Could not find an init method named - Java
- Split String in Python with Multiple Delimiters - Python
- How to Uninstall Microsoft Teams on Mac - Teams
- Java SE JDBC Select Statement Example - Java
- PHP Fatal error : Call to a member function bind_param() on a non-object - PHP