In 4 steps access SharePoint online data using postman tool

In 4 steps access SharePoint online data using postman tool

4 comments

Loading

Access SharePoint Online data using postman tool – today in this article we will learn about accessing SharePoint data using the postman tool and SharePoint REST API. Before that, we should have a basic understanding of SharePoint REST API, the use of the REST API in SharePoint, and HTTP operation in SharePoint using REST API. In my previous article, I have written on this Basic understanding of REST API in SharePoint online – CRUD Operations  – so you may go thru this before following this. Then we should have basic knowledge about what is postman tool and why should I use It. How to use postman to manage and execute your APIs.

Before getting into this article, you may also want to read this: The Ultimate Postman Tutorial: A Beginner’s Guide to REST API Testing

Table of Contents – Access SharePoint Online data using postman tool:

  • What is the postman tool?
  • What is the use of the Postman tool?
  • Download postman for windows – where can we download the postman tool?
  • Authentication Policies – SharePoint online
  • Authorize Postman to access SharePoint
  • Register Add-In – SharePoint online
  • Grant Permissions to Add-In – SharePoint online
  • Add-in permissions in SharePoint – App permission
  • Differences between add-in permission rights and user rights
  • Retrieve the Tenant ID in the Postman tool
  • Generate access token – how to generate an access token in postman?
  • Access SharePoint Online using Postman
  • Generate code snippet in postman
  • Generated code for C# – RestSharp – GET operation
  • Generated code for HTTP – GET operation
  • SharePoint API -create a new item in the list using Postman
  • Add a new item to SharePoint online list using the postman tool – verification
  • Generated code for C# – RestSharp – POST operation:
  • Generated code for HTTP – POST operation

What is the postman tool – access sharepoint online data using postman tool?

The postman is a Google Chrome app for interacting with HTTP APIs. It provides a friendly GUI for constructing requests and reading responses.

The Postman is currently one of the most popular tools used in API testing. The use of the postman started in 2012 – the purpose of the postman was to simplify API workflow in testing and development. This works based on the REST API foundation – API stands for Application Programming Interface which allows software applications to communicate with each other via API calls.

We can send requests in Postman to connect to APIs you are working with like SharePoint’s inbuilt REST API. The REST API requests can retrieve, add, delete, and update data. The REST API requests can send parameters, authorization details, and anybody data you require.

When you send a request, the postman will display the response received from the API server in a way that lets you examine, visualize, and if necessary troubleshoot it.

What is the use of the Postman tool?

Postman tool is one of the most popular REST API testing tools available in the market –  over 4 million users use postman nowadays. Why do people use this?  Because of the below features people around the world use this.

  • A quick test of REST API
  • Generate Code Snippets
  • Accessibility
  • Use of Collections
  • Collaboration
  • Creating Environments
  • Creation of Tests
  • Automation Testing
  • Debugging
  • Continuous Integration

However, from the above list, I personally like the most top-two “Quick test of REST API” and “Generate Code Snippets” features.

Using “Quick test of REST API” we can quickly perform the testing of any REST API thru the UI rather than writing some coding. Example SharePoint REST API to GET or POST items.

On successful API testing, similarly using the Generate Code Snippets” feature we can generate the outbox of the equivalent coding in almost all languages like C#, C, Java, PowerShell, etc. And the generated API code we can directly use in our actual project is the awesomeness of postman which really speedups up the development work.

Download postman for windows – where can we download the postman tool?

The postman tool can be downloaded from this link – Get Postman for Windows.

Download Postman tool: Get Postman for Windows - Download Postman

Get Postman for Windows – Download Postman

The main agenda of this article is how to get connected with SharePoint online and do the GET and POST operations with its resources.

So in order to get this done – we need to know about “Authentication Policies” and “Request Headers” – which we will be using frequently over time in this article.

Authentication Policies – SharePoint online:

We can use any of the below policies to authenticate the Add-In – in SharePoint online.

  • User Policy
  • Add-In Policy – We are using this policy to authenticate the external system to
  • Access SharePoint
  • User +Add-In Policy

Request Headers:

We need to have the value of the below keys:

  • Client Id – will get it from the SharePoint online page.
  • Client Secret – will get it from the SharePoint online page.
  • Realm (Tenant Id) – will get it from the postman tool.
  • Access Token – will get it from the postman tool.

Authorize Postman to access SharePoint

To get authorization from the external system, we should pass the access-token value as a request header along with the REST API URL. Before that we need to have the “access_token” – for that, we should generate “Client Id” and “Client Secret” information from the particular SharePoint site by registering as an “App only Add-In” in a SharePoint site.

Authorize Postman to access SharePoint – in high-level steps are as below:

1. Register Add-In
2. Grant Permissions to Add-In
3. Generate the Access Token
4. Access the SharePoint resource

Here I will explain how to “Register Add-In“, “Grant Permissions to Add-In” in SharePoint online and how to get the “Tenant Id”, “Access Token” and data from SharePoint using the Postman tool.

YourSharePointOnlineSiteURL/_api/web?$select=Title

Step #1:

Register Add-In – SharePoint online:

Go to the “appregnew.aspx” page in SharePoint online site where you want to connect.

Syntax:

YourSharePointOnlineSiteUrl/_layouts/15/appregnew.aspx

Example:

globalsharepoint2019.sharepoint.com/sites/SharePointRND/_layouts/15/appregnew.aspx

Click on the “Generate” “Client Id” button and “Client secret” button. And enter below details as like the screenshot:

  • Title – any meaningful text.
  • App Domain – localhost
  • Redirect URI – localhost

Then click on the “Create” button.

App information registration: Register Add-In - SharePoint online - Appregnew.aspx - App Information
Postman tool SharePoint online REST API

After clicking on the “Create” button we will land on the below page:

App information registration status: Register Add-In - SharePoint online - Appregnew.aspx - App Information in SharePoint Online
Postman tool SharePoint online REST API

Note down the above text in notepad then click on the “Ok” button. For example here is my saved “Client Id” and client Secret details:

The app identifier has been successfully created.
Client Id: 97145705-6a29-489a-a577-5a6838efdaed
Client Secret: ANSe8BFLPOo6oS5TrEzZB320Gz4qhMp+t06Ia+AGINk=
Title: Postman to SharePoint AddIn
App Domain: localhost
Redirect URI: localhost

Step #2:

Grant Permissions to Add-In – SharePoint online:

Go to the “appinv.aspx” page of the same SharePoint online site.
Syntax:

YourSharePointOnlineSiteUrl/_layouts/15/appinv.aspx


Example:

globalsharepoint2019.sharepoint.com/sites/SharePointRND/_layouts/15/appinv.aspx

Enter the “Client Id” in the “App Id” box which we have received in the previous step and click on the “Lookup” button as below:

App's Permission Request XML: Grant Permissions to Add-In - SharePoint online - Postman tool SharePoint online REST API
Postman tool SharePoint online REST API

Enter the below XML in the “Permission Request XML” box and click on the “Create” button.

<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="FullControl" />

Permission Request XML in SharePoint online: Grant Permissions to Add-In - SharePoint online - Postman tool SharePoint online REST API
Postman tool SharePoint online REST API

Then we will land on the below page.

Do you trust Postman to SharePoint AddIn?

  • Let it have full control of this site.
  • Let it share its permissions with other users.
  • Let it access basic information about the users of this site.

Click on the “Trust It” button.

Do you trust postman to SharePoint Addin? : Grant Permissions to Add-In - SharePoint online - Postman tool SharePoint online REST API
Postman tool SharePoint online REST API

That’s it, app permission registration is done!!!

Add-in permissions in SharePoint – App permission:

Below are the various “Add-in permissions in SharePoint – App permission” that are available: SharePoint add-in permission request scope URIs and descriptions.

Scope Scope URI Description
Tenancy sharepoint/content/tenant The tenancy where the add-in is installed. Includes all children of this scope.
Site Collection sharepoint/content/sitecollection The site collection where the add-in is installed. Includes all children of this scope.
Website sharepoint/content/sitecollection/web The website where the add-in is installed. Includes all children of this scope.
List sharepoint/content/sitecollection/web/list A single list on the website where the add-in is installed.

Note:

  • Need to add http at the beginning of the Scope URI.

Tenancy Scope – Description:

The tenancy where the add-in is installed. Includes all children of this scope.

Site Collection Scope – Description:

The site collection where the add-in is installed. Includes all children of this scope.

Website Scope – Description:

The website where the add-in is installed. Includes all children of this scope.

ListScope – Description:

If the add-in needs permission to more than one list, it must request permission to web scope.

Also, since you, the developer, have no way to control which list the user chooses or to tell the user which one to choose, you must use web scope if there is a list to which your add-in must have permission (but there is a way to narrow the user’s choice to certain subsets of lists; below see Permission request scope with associated properties.)

Differences between add-in permission rights and user rights

Permissions indicate the activities that an add-in is permitted to do within the requested scope. SharePoint supports four rights levels in the content database. For each scope, an add-in can have the following rights:

  • Read
  • Write
  • Manage
  • FullControl

Step #3:

Retrieve the Tenant ID in the Postman tool:

We have got the “Client Id” and “Client Secret”, now we need to retrieve the Tenant ID from SharePoint online tenant using the Postman tool. To do that let’s follow the below steps:

  • Launch Postman chrome extension.
  • Select GET Method
  • Enter the below URL in the “Request URL” textbox

    YourSPOSiteURL/_vti_bin/client.svc/
    
  • Configure the below information in the header section to send along with the url request Method = GET

Headers:

Key Syntax Value
Authorization Bearer Bearer
globalsharepoint2019.sharepoint.com/sites/SharePointRND/_vti_bin/client.svc/
Retrieve the Tenant ID in Postman tool: Postman tool SharePoint online REST API
Postman tool SharePoint online REST API

Click on the “Send” button.

After applying the configuration, click on the Send button. The response returns a lot of headers however, it ends with unauthorized access. To avoid this access issue we need to generate the access token. In the below steps, we will see how to generate an access token.

Postman tool GET operation body status: 401 unauthorized: Postman tool SharePoint online REST API
Postman tool SharePoint online REST API

Step #4:

Generate access token – how to generate an access token in postman?

In this step, we will learn how to generate an access token in the postman. In the response header, we will get WWW-Authenticate as one of the headers as highlighted below, for that key on the right side, we can see the realm value which is nothing but the tenant id for the SharePoint Online site and “client_id” value contains the resource information – these two highlighted value we need use later in this article. So we need to note down the below:

realm=”63cbe529-197e-4e1a-8492-f500e7174ee0″ = SharePoint Online Tenant Id

client_id=”00000003-0000-0ff1-ce00-000000000000″ = Resource information value, it is common for all.

To locate the above navigation we need to follow the below

Headers (Tab) then WWW-Authenticate as highlighted below:

Authorization Bearer realm: Postman tool SharePoint online REST API
Postman tool SharePoint online REST API

After getting the “Tenant ID“, we need to form an URL in the below format:

Syntax:

accounts.accesscontrol.windows.net/"Tenant ID(which we got in previous step)"/tokens/OAuth/2

Example:

accounts.accesscontrol.windows.net/63cbe529-197e-4e1a-8492-f500e7174ee0/tokens/OAuth/2

 

Note:

This URL is needed to get the access token.
Apply the below configurations in the header
Method = POST
Headers

Key Syntax Value
Content-Type application/x-www-form-urlencoded application/x-www-form-urlencoded

Body

Key Syntax Value
grant_type client_credentials client_credentials
client_id ClientID@TenantID Refer below for the value
client_secret ClientSecret Refer below for the value
resource resource/SiteDomain@TenantID Refer below for the value

ClientID@TenantID – Value:

97145705-6a29-489a-a577-5a6838efdaed@63cbe529-197e-4e1a-8492-f500e7174ee0

ClientSecret – Value:

ANSe8BFLPOo6oS5TrEzZB320Gz4qhMp+t06Ia+AGINk=

resource/SiteDomain@TenantIDValue:

00000003-0000-0ff1-ce00-000000000000/globalsharepoint2019.sharepoint.com@63cbe529-197e-4e1a-8492-f500e7174ee0

 

POST operation status 401 unauthorized: Postman tool SharePoint online REST API
Postman tool SharePoint online REST API
POST content type, client_id, client_secret_Postman tool SharePoint online REST API
Postman tool SharePoint online REST API

Click on the Send button:

Now we can see the “Status” as 200 OK which means successful execution. And in the “Body” we can see that “Access_token” has some value – we need to note down this value for the next steps.

Note:

  • Access_token” value is valid just for few a hour – this will be expired after 5 to 6 hours, then again we need to generate the new “Access_token” value.
POST status 200 OK Postman tool SharePoint online REST API
Postman tool SharePoint online REST API

Note down the “access_token” value:

Below is my sample “access_token” value which I have got from the request.

eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6InBpVmxsb1FEU01LeGgxbTJ5Z3FHU1ZkZ0ZwQSIsImtpZCI6InBpVmxsb1FEU01LeGgxbTJ5Z3FHU1ZkZ0ZwQSJ9.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAvZ2xvYmFsc2hhcmVwb2ludDIwMTkuc2hhcmVwb2ludC5jb21ANjNjYmU1MjktMTk3ZS00ZTFhLTg0OTItZjUwMGU3MTc0ZWUwIiwiaXNzIjoiMDAwMDAwMDEtMDAwMC0wMDAwLWMwMDAtMDAwMDAwMDAwMDAwQDYzY2JlNTI5LTE5N2UtNGUxYS04NDkyLWY1MDBlNzE3NGVlMCIsImlhdCI6MTU3ODIwMjE2NiwibmJmIjoxNTc4MjAyMTY2LCJleHAiOjE1NzgyMzEyNjYsImlkZW50aXR5cHJvdmlkZXIiOiIwMDAwMDAwMS0wMDAwLTAwMDAtYzAwMC0wMDAwMDAwMDAwMDBANjNjYmU1MjktMTk3ZS00ZTFhLTg0OTItZjUwMGU3MTc0ZWUwIiwibmFtZWlkIjoiOTcxNDU3MDUtNmEyOS00ODlhLWE1NzctNWE2ODM4ZWZkYWVkQDYzY2JlNTI5LTE5N2UtNGUxYS04NDkyLWY1MDBlNzE3NGVlMCIsIm9pZCI6IjYyZjQyN2E1LWZhOGMtNDU2NS05MTE2LTZlMzRiMDVmOGM0MSIsInN1YiI6IjYyZjQyN2E1LWZhOGMtNDU2NS05MTE2LTZlMzRiMDVmOGM0MSIsInRydXN0ZWRmb3JkZWxlZ2F0aW9uIjoiZmFsc2UifQ.C9jy3VpZDadclNzR-BsulRT_r0YeBTwo7Xn9lk6Yq6-jdHDnL4JdlhyKJI54Pso57qFpbt_TWKYY0oNHiH9Nqi26DihB-4M4qW50H1DsP4c_ZiG_1mUY2V3xEHu7_qfZ2fLalimv2mgVxI-WIl1Mho833t9EG5of_atb1-mhpxIymLgGt2d0-qHYyZTkjnV7I6J3w2m31yTRaUTrP2yqEbQTVSIOCtt7G-jITPEV-Q7Ce5xpRy017kpBOCkXfaVb2WJHkDiF_0-dUuMzhBhdVl1CL6PdASy6wuehF3kFxBDtE6c91ri3m5m-ZHofYuqYAHluN3oNw9wVeDF3Vga_Hw

Access SharePoint Online using Postman:

We have the “access_token” value from SharePoint online – now we will see how we can connect to Sharepoint online and access Sharepoint online using Postman. Build a REST API query to get the SharePoint online list items like the below:

Syntax:

"YourSharePointOnlineSiteUrl"/_api/web?$select=Title

Example:

REST API to get web objects:

globalsharepoint2019.sharepoint.com/sites/SharePointRND/_api/web?$select=Title

REST API to get list item objects:

globalsharepoint2019.sharepoint.com/sites/SharePointRND/_api/web/lists/getbytitle('Customer')/items

 

The select method as GET

In the URL text box enter the below URL:

globalsharepoint2019.sharepoint.com/sites/SharePointRND/_api/web/lists/getbytitle('Customer')/items

Headers

Key Syntax Value
Authorization Bearer access_token Bearer “access_token value”
Accept application/json;odata=verbose application/json;odata=verbose

Note:

  • After “Bearer” we need to have a single space, then the “access_token” value without quotation.

Then click on the “Send” button – we will get the success result status as 200 OK if everything is fine otherwise we will get access denied or unauthorized access error – then we need to check the permission XML which we have registered in “appinv.aspx” SharePoint online page.

Example below:

GET list items status 200 OK: Postman tool SharePoint online REST API
Postman tool SharePoint online REST API

In the above example, we can see the body – it is a valid successful JSON data that has come from the SharePoint custom list.

You may also read this: Top 5 SharePoint Online Authentication Methods You Need to Know About

Generate code snippet postman:

Now we will generate the corresponding code for the above success request using the generate code snippets feature in postman so that we can inject this code into an actual project file, this really speeds up the productivity.

We can generate code snippets in almost all popular languages, like C#, C, Java, PowerShell, etc.

Postman code C#: Generate code snippet postman
Generate code snippet postman

Generated code for C# – RestSharp – GET operation:

Below is the generated code for C# – RestSharp from GET operation.

var client = new RestClient("globalsharepoint2019.sharepoint.com/sites/SharePointRND/_api/web/lists/getbytitle('Customer')/items");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6InBpVmxsb1FEU01LeGgxbTJ5Z3FHU1ZkZ0ZwQSIsImtpZCI6InBpVmxsb1FEU01LeGgxbTJ5Z3FHU1ZkZ0ZwQSJ9.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAvZ2xvYmFsc2hhcmVwb2ludDIwMTkuc2hhcmVwb2ludC5jb21ANjNjYmU1MjktMTk3ZS00ZTFhLTg0OTItZjUwMGU3MTc0ZWUwIiwiaXNzIjoiMDAwMDAwMDEtMDAwMC0wMDAwLWMwMDAtMDAwMDAwMDAwMDAwQDYzY2JlNTI5LTE5N2UtNGUxYS04NDkyLWY1MDBlNzE3NGVlMCIsImlhdCI6MTU3ODIwMjE2NiwibmJmIjoxNTc4MjAyMTY2LCJleHAiOjE1NzgyMzEyNjYsImlkZW50aXR5cHJvdmlkZXIiOiIwMDAwMDAwMS0wMDAwLTAwMDAtYzAwMC0wMDAwMDAwMDAwMDBANjNjYmU1MjktMTk3ZS00ZTFhLTg0OTItZjUwMGU3MTc0ZWUwIiwibmFtZWlkIjoiOTcxNDU3MDUtNmEyOS00ODlhLWE1NzctNWE2ODM4ZWZkYWVkQDYzY2JlNTI5LTE5N2UtNGUxYS04NDkyLWY1MDBlNzE3NGVlMCIsIm9pZCI6IjYyZjQyN2E1LWZhOGMtNDU2NS05MTE2LTZlMzRiMDVmOGM0MSIsInN1YiI6IjYyZjQyN2E1LWZhOGMtNDU2NS05MTE2LTZlMzRiMDVmOGM0MSIsInRydXN0ZWRmb3JkZWxlZ2F0aW9uIjoiZmFsc2UifQ.C9jy3VpZDadclNzR-BsulRT_r0YeBTwo7Xn9lk6Yq6-jdHDnL4JdlhyKJI54Pso57qFpbt_TWKYY0oNHiH9Nqi26DihB-4M4qW50H1DsP4c_ZiG_1mUY2V3xEHu7_qfZ2fLalimv2mgVxI-WIl1Mho833t9EG5of_atb1-mhpxIymLgGt2d0-qHYyZTkjnV7I6J3w2m31yTRaUTrP2yqEbQTVSIOCtt7G-jITPEV-Q7Ce5xpRy017kpBOCkXfaVb2WJHkDiF_0-dUuMzhBhdVl1CL6PdASy6wuehF3kFxBDtE6c91ri3m5m-ZHofYuqYAHluN3oNw9wVeDF3Vga_Hw");
request.AddHeader("Accept", "application/json; odata=verbose");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

Generated code for HTTP – GET operation:

Below is the generated code for HTTP from GET operation.

GET /sites/SharePointRND/_api/web/lists/getbytitle('Customer')/items HTTP/1.1
Host: globalsharepoint2019.sharepoint.com
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6InBpVmxsb1FEU01LeGgxbTJ5Z3FHU1ZkZ0ZwQSIsImtpZCI6InBpVmxsb1FEU01LeGgxbTJ5Z3FHU1ZkZ0ZwQSJ9.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAvZ2xvYmFsc2hhcmVwb2ludDIwMTkuc2hhcmVwb2ludC5jb21ANjNjYmU1MjktMTk3ZS00ZTFhLTg0OTItZjUwMGU3MTc0ZWUwIiwiaXNzIjoiMDAwMDAwMDEtMDAwMC0wMDAwLWMwMDAtMDAwMDAwMDAwMDAwQDYzY2JlNTI5LTE5N2UtNGUxYS04NDkyLWY1MDBlNzE3NGVlMCIsImlhdCI6MTU3ODIwMjE2NiwibmJmIjoxNTc4MjAyMTY2LCJleHAiOjE1NzgyMzEyNjYsImlkZW50aXR5cHJvdmlkZXIiOiIwMDAwMDAwMS0wMDAwLTAwMDAtYzAwMC0wMDAwMDAwMDAwMDBANjNjYmU1MjktMTk3ZS00ZTFhLTg0OTItZjUwMGU3MTc0ZWUwIiwibmFtZWlkIjoiOTcxNDU3MDUtNmEyOS00ODlhLWE1NzctNWE2ODM4ZWZkYWVkQDYzY2JlNTI5LTE5N2UtNGUxYS04NDkyLWY1MDBlNzE3NGVlMCIsIm9pZCI6IjYyZjQyN2E1LWZhOGMtNDU2NS05MTE2LTZlMzRiMDVmOGM0MSIsInN1YiI6IjYyZjQyN2E1LWZhOGMtNDU2NS05MTE2LTZlMzRiMDVmOGM0MSIsInRydXN0ZWRmb3JkZWxlZ2F0aW9uIjoiZmFsc2UifQ.C9jy3VpZDadclNzR-BsulRT_r0YeBTwo7Xn9lk6Yq6-jdHDnL4JdlhyKJI54Pso57qFpbt_TWKYY0oNHiH9Nqi26DihB-4M4qW50H1DsP4c_ZiG_1mUY2V3xEHu7_qfZ2fLalimv2mgVxI-WIl1Mho833t9EG5of_atb1-mhpxIymLgGt2d0-qHYyZTkjnV7I6J3w2m31yTRaUTrP2yqEbQTVSIOCtt7G-jITPEV-Q7Ce5xpRy017kpBOCkXfaVb2WJHkDiF_0-dUuMzhBhdVl1CL6PdASy6wuehF3kFxBDtE6c91ri3m5m-ZHofYuqYAHluN3oNw9wVeDF3Vga_Hw
Accept: application/json; odata=verbose

 

SharePoint API -create a new item in the list using Postman:

In the previous example, we have seen how to get list items from SharePoint online using a postman tool with the GET operation – now we will see how we can insert a new item to a SharePoint list using the postman tool with the POST operation.

Enter the URL below:

Syntax:

"YourSharePointOnlineSiteUrl"/_api/web?$select=Title

Example:

REST API to get web objects from SharePoint online:

globalsharepoint2019.sharepoint.com/sites/SharePointRND/_api/web?$select=Title

REST API to get list items objects from SharePoint online:

globalsharepoint2019.sharepoint.com/sites/SharePointRND/_api/web/lists/getbytitle('Customer')/items

The select method as POST

Headers – In the headers section enter the below key-value parameters:

Key Syntax Value
Authorization Bearer access_token Bearer “access_token value”
Accept application/json;odata=verbose application/json;odata=verbose
content-type application/json;odata=verbose application/json;odata=verbose
Add new item to SharePoint online list, POST: Sharepoint Api -create new item in the list using Postman
Sharepoint API -create a new item in the list using Postman

Sharepoint API -create a new item in the list using Postman

Now click on “Body” tab and in the second ribbon row select “raw” and in the last dropdown list, select as “JSON” then enter the below values:

{ "__metadata": {"type": "SP.Data.CustomerListItem"},
 "Title": "New Title 1", 
"CustomerID": "CustomerIDTest001", "CustomerName": "Test customer1",
 "Address": "Mumbai, India"
}

 

Notes:

  • In the above “SP.Data.CustomerListItem“, “Customer” is list internal name – so the format is “List Internal Name”+ListItem
  • Title, CustomerID, Address are columns in the SharePoint “Customer” list and here we’re passing the values for those columns to add a new item in the list.
  • Similar to the above columns – we can pass as many column values as we want.

Once the above configuration is done – click on the “Send” button. If everything goes fine we will see “Status: 201 Created” like below and in the body section we also can see the valid complete SharePoint successful JSON result.

Add new item to SharePoint online list, POST status 200 accepted: Sharepoint Api - create new item in the list using Postman
Sharepoint API – create a new item in the list using Postman

Add a new item to SharePoint online list using postman tool – verification:

Now let’s navigate to the SharePoint online “Customer” list – there we can see a new item has been added.

New item is added to SharePoint online list: SharePoint REST API - create new item in the list using Postman
SharePoint REST API – create a new item in the list using Postman

Generated code for C# – RestSharp – POST operation:

Below is the generated code for C# – RestSharp – for successful POST operation:

var client = new RestClient("globalsharepoint2019.sharepoint.com/sites/SharePointRND/_api/web/lists/getbytitle('Customer')/items");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json;odata=verbose");
request.AddHeader("Authorization", "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6InBpVmxsb1FEU01LeGgxbTJ5Z3FHU1ZkZ0ZwQSIsImtpZCI6InBpVmxsb1FEU01LeGgxbTJ5Z3FHU1ZkZ0ZwQSJ9.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAvZ2xvYmFsc2hhcmVwb2ludDIwMTkuc2hhcmVwb2ludC5jb21ANjNjYmU1MjktMTk3ZS00ZTFhLTg0OTItZjUwMGU3MTc0ZWUwIiwiaXNzIjoiMDAwMDAwMDEtMDAwMC0wMDAwLWMwMDAtMDAwMDAwMDAwMDAwQDYzY2JlNTI5LTE5N2UtNGUxYS04NDkyLWY1MDBlNzE3NGVlMCIsImlhdCI6MTU3ODIwMjE2NiwibmJmIjoxNTc4MjAyMTY2LCJleHAiOjE1NzgyMzEyNjYsImlkZW50aXR5cHJvdmlkZXIiOiIwMDAwMDAwMS0wMDAwLTAwMDAtYzAwMC0wMDAwMDAwMDAwMDBANjNjYmU1MjktMTk3ZS00ZTFhLTg0OTItZjUwMGU3MTc0ZWUwIiwibmFtZWlkIjoiOTcxNDU3MDUtNmEyOS00ODlhLWE1NzctNWE2ODM4ZWZkYWVkQDYzY2JlNTI5LTE5N2UtNGUxYS04NDkyLWY1MDBlNzE3NGVlMCIsIm9pZCI6IjYyZjQyN2E1LWZhOGMtNDU2NS05MTE2LTZlMzRiMDVmOGM0MSIsInN1YiI6IjYyZjQyN2E1LWZhOGMtNDU2NS05MTE2LTZlMzRiMDVmOGM0MSIsInRydXN0ZWRmb3JkZWxlZ2F0aW9uIjoiZmFsc2UifQ.C9jy3VpZDadclNzR-BsulRT_r0YeBTwo7Xn9lk6Yq6-jdHDnL4JdlhyKJI54Pso57qFpbt_TWKYY0oNHiH9Nqi26DihB-4M4qW50H1DsP4c_ZiG_1mUY2V3xEHu7_qfZ2fLalimv2mgVxI-WIl1Mho833t9EG5of_atb1-mhpxIymLgGt2d0-qHYyZTkjnV7I6J3w2m31yTRaUTrP2yqEbQTVSIOCtt7G-jITPEV-Q7Ce5xpRy017kpBOCkXfaVb2WJHkDiF_0-dUuMzhBhdVl1CL6PdASy6wuehF3kFxBDtE6c91ri3m5m-ZHofYuqYAHluN3oNw9wVeDF3Vga_Hw");
request.AddHeader("Accept", "application/json; odata=verbose");
request.AddParameter("application/json;odata=verbose", "{\n  \"__metadata\": {\"type\": \"SP.Data.CustomerListItem\"},\n  \"Title\": \"New Title 1\",\n  \"CustomerID\": \"CustomerIDTest001\",\n  \"CustomerName\": \"Test customer1\",\n  \"Address\": \"Mumbai, India\"\n\n}",  ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

Generated code for HTTP – POST operation:

Below is the generated code for HTTP – for successful POST operation:

POST /sites/SharePointRND/_api/web/lists/getbytitle('Customer')/items HTTP/1.1
Host: globalsharepoint2019.sharepoint.com
content-type: application/json;odata=verbose
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6InBpVmxsb1FEU01LeGgxbTJ5Z3FHU1ZkZ0ZwQSIsImtpZCI6InBpVmxsb1FEU01LeGgxbTJ5Z3FHU1ZkZ0ZwQSJ9.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAvZ2xvYmFsc2hhcmVwb2ludDIwMTkuc2hhcmVwb2ludC5jb21ANjNjYmU1MjktMTk3ZS00ZTFhLTg0OTItZjUwMGU3MTc0ZWUwIiwiaXNzIjoiMDAwMDAwMDEtMDAwMC0wMDAwLWMwMDAtMDAwMDAwMDAwMDAwQDYzY2JlNTI5LTE5N2UtNGUxYS04NDkyLWY1MDBlNzE3NGVlMCIsImlhdCI6MTU3ODIwMjE2NiwibmJmIjoxNTc4MjAyMTY2LCJleHAiOjE1NzgyMzEyNjYsImlkZW50aXR5cHJvdmlkZXIiOiIwMDAwMDAwMS0wMDAwLTAwMDAtYzAwMC0wMDAwMDAwMDAwMDBANjNjYmU1MjktMTk3ZS00ZTFhLTg0OTItZjUwMGU3MTc0ZWUwIiwibmFtZWlkIjoiOTcxNDU3MDUtNmEyOS00ODlhLWE1NzctNWE2ODM4ZWZkYWVkQDYzY2JlNTI5LTE5N2UtNGUxYS04NDkyLWY1MDBlNzE3NGVlMCIsIm9pZCI6IjYyZjQyN2E1LWZhOGMtNDU2NS05MTE2LTZlMzRiMDVmOGM0MSIsInN1YiI6IjYyZjQyN2E1LWZhOGMtNDU2NS05MTE2LTZlMzRiMDVmOGM0MSIsInRydXN0ZWRmb3JkZWxlZ2F0aW9uIjoiZmFsc2UifQ.C9jy3VpZDadclNzR-BsulRT_r0YeBTwo7Xn9lk6Yq6-jdHDnL4JdlhyKJI54Pso57qFpbt_TWKYY0oNHiH9Nqi26DihB-4M4qW50H1DsP4c_ZiG_1mUY2V3xEHu7_qfZ2fLalimv2mgVxI-WIl1Mho833t9EG5of_atb1-mhpxIymLgGt2d0-qHYyZTkjnV7I6J3w2m31yTRaUTrP2yqEbQTVSIOCtt7G-jITPEV-Q7Ce5xpRy017kpBOCkXfaVb2WJHkDiF_0-dUuMzhBhdVl1CL6PdASy6wuehF3kFxBDtE6c91ri3m5m-ZHofYuqYAHluN3oNw9wVeDF3Vga_Hw
Accept: application/json; odata=verbose

{
  "__metadata": {"type": "SP.Data.CustomerListItem"},
  "Title": "New Title 1",
  "CustomerID": "CustomerIDTest001",
  "CustomerName": "Test customer1",
  "Address": "Mumbai, India"

}

 

Easily we can inject the above codes into our respective programming language wherever it fits.

Summary: Access SharePoint online data using postman tool

Thus, in this article we have learned the below topics with respect to SharePoint online and the postman tool:

  • Introduction to Postman for API Development
  • What is the postman tool?
  • How to Use Postman to Manage and Execute Your APIs?
  • What is the use of REST API in SharePoint?
  • Access SharePoint Online using Postman
  • GET and POST method in SharePoint online using postman tool
  • Accessing SharePoint Data using Postman (SharePoint REST API)
  • Postman tool and SharePoint online REST API
  • Download postman for windows – where can we download the postman tool?
  • Authentication Policies – SharePoint online
  • Authorize Postman to access SharePoint
  • Register Add-In – SharePoint online
  • Grant Permissions to Add-In
  • Add-in permissions in SharePoint – App permission
  • Differences between add-in permission rights and user rights
  • Retrieve the Tenant ID in the Postman tool
  • Generate access token – how to generate an access token in postman?
  • Access SharePoint Online using Postman
  • Generate code snippet postman
  • Generated code for C# – RestSharp – GET operation
  • Generated code for HTTP – GET operation
  • SharePoint API -create a new item in the list using Postman:

See Also: Access SharePoint online data using postman tool

You may also be interested in the following articles:

Request: If this article helps you, please appreciate our efforts by writing a comment below or if you have a better idea/solution to this topic, please write a comment, we will include that in this article. Thank you, happy reading, learning, and Sharing. 🙂

About Post Author

4 comments on “In 4 steps access SharePoint online data using postman tool”

Do you have a better solution or question on this topic? Please leave a comment