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!
- error CAML Query containing special characters
- [Solved] SharePoint Illegal operation attempted on a registry key that has been marked for deletion
- Trigger Flow on selected Listitem from SharePoint view - create button with JSON column formatting
- SharePoint Excel error - The workbook cannot be opened because it contains the following features that are not supported by Excel in the browser
- Send Email with attachment using SharePoint PowerShell, SMTP server
- How to show or hide columns in SharePoint Online List Library from
- SharePoint excel error - A problem occurred while connecting to the server. If the problem continues, contact your administrator.
- How to get SharePoint Online user details from person or group column using REST API
- How to get SharePoint List Item URL using PowerShell
- How to get the SharePoint Tenant Login URL
- Special character & not working with SharePoint REST API
- How to disable SharePoint subsite creation option for owners
- Managed Metadata error - The data returned from the tagging UI was not formatted correctly
- Deploy SharePoint wsp solution package using PowerShell
- How to create classic site in SharePoint Online
- See actual SharePoint error exception modify web.config
- 'Edit Document' Requires a Windows Sharepoint Services-compatible application and Microsoft Internet Explorer 6.0 or higher
- How to enable anonymous public access for SharePoint Online site collection, file, folder without login ?
- SharePoint installation error - Setup is unable to proceed due to the following error This product requires Microsoft .Net Framework 4.5
- How to add animated Gif to SharePoint Online Page
- [Solved] SharePoint Search Internal server error exception
- How to create SharePoint Document Library
- SharePoint - Use Today's Date Time in list view filter and calculated column
- How to redirect SharePoint Site Collection to different URL
- SharePoint error cannot connect to the configuration database
- Copy file from a remote server to current local directory system using SCP command - HowTos
- Java JDBC Connection with MySQL Driver in VS Code + Troubleshooting - Java
- How to extend retiring SharePoint 2010 Workflows and continue with Office 365 - SharePoint
- How to add hint text in bootstrap input text field and text area - Bootstrap
- How to Subscribe to AWS SNS Topic [SMS/Email/Lambda] via CLI - AWS
- How to create a Git Project in Eclipse (Step-by-step) - Eclipse
- Install Oh My Zsh on Ubuntu Docker complete steps - Ubuntu
- Selenium Maven Dependency for pom.xml - Java