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!
- That did'nt work, Issue type User not in directory - SharePoint external access error
- How to get SharePoint Online user details from person or group column using REST API
- Create SharePoint Site Collection with new Content database in existing web application
- Fix Power BI 404 not found error when connecting SharePoint Online List as Data Source
- How to get the SharePoint Tenant Login URL
- How to wrap column text in SharePoint Online Modern List Grid View using JSON formatting
- SharePoint Server 2016 installation System Hardware requirements
- Cannot load PowerApps form in SharePoint Online due to repeated authentication
- Change SharePoint search results FullTextSqlQuery RowLimit 10000
- How to create SharePoint Document Library
- How to exclude results from SharePoint Search
- SharePoint 2010 DataForm Unable to display this Web Part System.StackOverflowException
- Fix Error 2711 SQL RBS client - The installer has encountered an unexpected error. The specified Feature name ('Docs') not found in Feature table
- How to upload file programmatically to SharePoint Document Library using Server Object Model C# .Net
- SharePoint error cannot connect to the configuration database
- Drag drop files here option missing for SharePoint document library
- How to activate and create SharePoint Spaces feature for mixed reality experience - 2D/3D images and web parts
- [Fix] Office 365 Sharepoint One Drive Error: Something went wrong. This is a temporary issue
- SharePoint 2016 error - Could not find file ManageUserProfileServiceApplicationTenantSimplified.xml
- SharePoint List excel import - This table exceeds the maximum number of supported rows
- How to customize SharePoint Modern list form using JSON formatting
- New-SPLogFile PowerShell - create new SharePoint log file
- SharePoint Online REST API not returning all list items and limit to only 100 rows
- How to Get or Set SharePoint Document ID _dlc_DocId using PowerShell
- Get-ADUser PowerShell - Get AD user details using email address
- How to undo last Git Commit on Local Repository? - Git
- [Fix] java.net.MalformedURLException: unknown protocol - Java
- pip/pip3 ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied - PIP
- How to configure PDF iFilter for SharePoint - SharePoint
- How to make div or text in html unselectable using CSS - CSS
- Enable Dark Mode in Google Search - Google
- Fix Microsoft Store Error Code: 0x80072EFD - Microsoft
- Microsoft Teams meeting Full Screen mode option missing - bring it back - Teams