SharePoint API CRUD + Upload File Guided Steps using Postman (2022)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone welcome to phonetech in today's video i'll be sharing how to use the sharepoint api via postman i'll be demonstrating how to perform crowd operations on sharepoint lists and how to upload files to a document library if you want a sharepoint of your own to follow along this tutorial watch my previous video to find out how you can get a microsoft subscription for free the first thing we must do is register our application on sharepoint save your tenant name and site name in this case my tenant name is devwoon and my site name is dev navigate to your url which ends with average new click generate your client id save your client id generate your client secret do take note that this secret expires in one year the only way to renew this is via an azure ad powershell script for this tutorial we'll be using a random title in this case sharepoint api for app domain we'll just be using www.localhost.com for our redirect uri we're using https colon forward slash forward slash www.localhost.com for this first step you must be the owner of the site with site collection administrator access the second step is to set permissions to the application we just created navigate to your url which ends with app inv for the app id it is the client id value which you have just saved previously paste that in the field and click lookup all the fields we've entered previously should populate next copy this permission xml and paste it in the box below allow app only policy means sharepoint only checks for the app permissions there are also user only policies and user app policies but we won't go into that you can also define the scope to be on the tenant site collection web or even list library level you can also define the rights to be read write manage full control documentation in the link below click create and you'll be brought to a page to trust application with the permissions you've defined the third step is to get our sharepoint site tenant id navigate to your url which ends with app principles the app identifier is in the format value pipe sign value pipe sign client id at 1090 so we want to grab the value after the add sign for tenant id save your tenant id the fourth step is to get our authorization code we need this authorization code to generate the refresh token bear in mind this authorization code will expire after 10 minutes in the shown format you must fill your site url client id and redirect uri i've done line breaks for ease of viewing but be sure not to have any spaces when you paste the string into your address bar here i've copied my string into my notepad and removed the spaces paste the string into your address bar you'll be brought to a page to again trust application which you've just authorized and you'll be navigated to your redirect uri your authorization code will be after the code parameter copy the authorization code and save it next we'll go into postman we'll be reusing many of these values and it's worthwhile to save them as variables in our postman collection enter your tenant name and site name and redirect uri copy out our client id and paste it in postman copy out our client secret and paste it in postman copy out our tenant id and paste it in postman as for application id microsoft has a list of application ids on their website in our case this is the value for sharepoint online you can use the same value i've placed the link to the documentation in the description box below we'll use a post method in postman to generate our refresh token we need the refresh token to generate the access token which authorizes us to run the api the default lifespan of a refresh token is 90 days the api to call this account.accesscontrol.windows.net forward slash tenant id slash tokens oauth 2. be sure to set your header content type and for the body the grant type is authorization underscore code for the client underscore id value we'll call our variables client id at tenant id for the client underscore secret value we'll call our variable client secret for the code value we'll call variable authcode for redirect underscore uri value we'll call redirect uri variable for resource value we'll call variables application id for slash tenantname.sharepoint.com at tenant id hit send and we can grab our refresh token once we've saved our refresh token in our collection variables we'll use a post method in postman to generate our access token the access token will be what we use to authenticate our api calls the default life span of the access token is 60 to 19 minutes which is around 75 minutes on average the api to call is exactly the same as for the refresh token the only difference here is that in our api body our grant underscore type is now refreshed on a score token instead of authorization underscore code and we don't need the code parameter anymore hit send and we can grab the access token from the results let's save this value in our collection variables too the list name which we are using is the work progress tracker which i've created via microsoft's template in sharepoint we will use a get method enforcement to get the internal list name we will need this value for our card operations on the list later be sure to set authorization to be bearer token the api to call is the site url slash api slash web slash lists slash get by title open bracket single quote your list name single quote close bracket question mark select equals list item entity type full name for the headers a step and content type will use the application slash json or data equals verbose to get the full result in json for the authorization header we'll put bearer space or variable access token hit send and grab the internal list name from the results here's the part you've been waiting for the current apis we'll start with c creating a list item we'll use a post method again using the authorization bearer token the api call is similar to before except that we are using slash items after all this name the headers are the same except for the accept header where i choose to have no metadata in my output in our body use the below format curly bracket double quotes underscore underscore metadata colon double quotes colon curly bracket double quotes type double quotes colon double quotes and place the internal list name from the previous api call here finish this line with double quotes and curly brackets and a comma next enter the field names and values of the fields in json format before ending with another curly bracket in my example i'll just be creating an item with value in the title field we'll hit send you can see i have item id 1 with title myitem created and navigate to sharepoint to confirm it has been created so hit refresh and here you can see the item being created next we'll do our reading list item we will use a get method and authorization bearer token again if you want to read all these items the api is same as before but if you want to read a single item add a slash get by id bracket item id we'll use the same headers here and hit send in the output you can see the item that we've created previously here i can also just add a bracket item id after slash items to get a specific item next we'll do you updating on this item we'll use a post method and authorization barrier token here we have to reference the item to update be sure to have slash items bracket item id after your list name we'll need two more parameters in our header if match with value star on the etag value and the xhtb method with the value merge for the body it's the same format as when you create a list item for those fields which you omit they will not be updated hit send via 204 no content and let's check out our sharepoint list it has been updated to value updated item next we'll do d deleting a list item we'll use a post method and authorization bearer token the api call and the headers are exactly the same as update item except for the xhttp method which should have the value delete instead of merge let's hit send we get 200 okay we see that in sharepoint it has been deleted in this step we will get our form digest value the form digest value is essential for working with files we'll use a post method with authorization barrier token the api call is the site url api slash contacts info we'll use the accept content type and authorization headers which we've seen before hit send copy out the form digest value that's just before the date and the comma for the last api we'll do an upload file this is a post method with authorization barrier token will use the following api call site url slash api slash web slash get folder by server relative url open bracket slash sites slash your site name your folder path in my case i have a folder called sharepoint api in my shared documents folder continue with slash files slash add bracket url equals your file name dot file extension here you can choose whether you want to override put true or false and close a bracket for headers we'll use the authorization barrier token for a set we use applications json all data equals no metadata for the x-request digest header we use the variable form digest value which we saved earlier in our body add the binary file which we wish to upload hit send and you'll get a 200 okay in the response you can see our face.png file got uploaded to the sharepoint api folder here we'll navigate to sharepoint and we can see that the sharepoint app has uploaded the file hope you've enjoyed this video do give me a thumbs up if it did and subscribe if you haven't if you have any questions do leave them in the comment section and i'll help address them see you and take care
Info
Channel: Voon Technology
Views: 33,502
Rating: undefined out of 5
Keywords: microsoft, free, singapore, developer, easy, guide, tutorial, legit, office, sharepoint, m365, o365, sandbox, azure, ms, hack, hacker, singaporean, sg, love, life, bored, account, key, dev, development, beginner, plan, api, rest api, postman, crud, crud operations, create, read, update, delete, file upload, sharepoint list, sharepoint document library, api call, access token, bearer token, refresh token, authorization code, x-requestdigest, requestdigestform, sharepoint online, expiry, authorization, resource, client_secret
Id: aD_WBiyKjd0
Channel Id: undefined
Length: 12min 47sec (767 seconds)
Published: Fri Apr 22 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.