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

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone welcome to vuntec in today's video i'll be sharing how to use sharepoint api v2 better known as graph api via postman i'll be demonstrating how to perform card operations on sharepoint lists and how to upload files to a document library microsoft graph api allows you to manipulate almost every single application within the microsoft 365 suite this video can be your basis to learning other api calls such as on ad users mails calendars etc if you want a sharepoint and azure portal of your own to follow along this tutorial watch my first video to find out how you can get a microsoft subscription for free the first thing we must do is register our application in portal.azure.com to do that you must minimally have an application administrator persona in azure id in the azure portal look for app registrations click on new registration enter a name for the tutorial or use graph api by default single tenant will suffice but if you are planning to use refresh tokens you need to select multi-tenant i won't be covering it in this tutorial since i've touched on refresh tokens in my previous video for redirect uri we'll use https www.localhost.com select the web platform click register once your app is created remember to save your client id then save your tenant id for this video we'll be calling the api without the user so we'll need a client-secret so we'll go into certificates and secrets tab create a new client secret i'll use the graph api name and set my expiry to the microsoft recommended six months here remember to save the secret value because you will not be able to view it again if you navigate away you'll need to grant the app sufficient permissions for the api calls we are using it really depends on which api you are calling for this video we are performing crowd operations in sharepoint so we need the sites.readwrite.org permission let's go to api permission in azure portal click add a permission select microsoft graph here we choose application permissions since we are calling apis without the user look for permissions sites sites.readwrite.org and add the permission next we need to get the tenant admin or the global administrator persona in azure id to grant admin consent you will see a green check mark on the status column when it's done we are done with the azure setup next we are going to postman we will be reusing many of these values and is worthwhile to collect them as variables in our postman collection copy out our client id and paste it in postman copy out our tenant id and paste it in postman copy out our client secret and paste it in postman as for our app id microsoft has a list of application ids on your website in our case this is the value for sharepoint online you can use the same value i've placed a link to the documentation in the description box below remember to also add your tenant name and your site name now we are ready to generate our access token the access token will be what we use to authenticate our api calls the default lifespan of the access token is 60 to 90 minutes which is 75 minutes on average we'll use a post method in postman to generate our access token the api to call is login.microsoftonline.com tenon id slash oauth2 slash v 2.0 slash token you need one header content type with value application x www form url encoded for body you'll need 4 parameters grant type client underscore credentials client id we'll use our variable client id client secret we'll use our variable client secret for scope we'll use https graph.microsoft.com dot default send our api call in the response copy out our bearer token and save it as our collection variable we know our site name but now we need to get our site id in step 4 we'll use a get method with authorization barrier token use a microsoft graph api call with sites slash tenantname.sharepoint.com colon slash sites site name for headers we only need the authorization with value barrier space or access token variable you realize microsoft graph apis have minimal parameters and are intuitive to use which make them great send out api call and in the response we see the id value we see our sharepoint site followed by two strings separated by a comma we just need to grab the first string which is our site id and save it as a collection variable we'll need the list name that we are intending to use and we'll need the list id for api call in step 5 we'll use a get method with authorization barrier token use the microsoft graph api call with slash sites site id lists of course you can use the search parameters if you have many lists in your site using the question mark search equals your search string for headers we need authorization with value paraspace our access token variable send our api call and in the response we just need to locate the list that we are working with the list i'm using is the word progress tracker which is available as a template in sharepoint and grab the list id copy out the list id and save it as a collection variable we are ready to start with our card operations first c creating a list item we will use a post method with authorization barrier token use the microsoft graph api call with slash sites site id slash lists slash list id items for headers authorization will value bearer space rxs token variable and content type with value application json in our body here is the following format curly brackets with double quotes fields colon curly brackets followed by your field name and field value in my example i'll just be creating a list item with the field title and value new item hit send and you get a 201 created in the response we see our new item created with id 2. let's navigate to the sharepoint hit refresh and you can see new item has been created next are reading list items we'll use a get method with authorization barrier token use the microsoft graph api call with slash sites slash site id slash list slash list id slash items slash your item id for headers authorization with value barrier space or access token hit send you get a 200 ok you can see the new item that we previously created and all the data related to it in a response next you updating a list item we'll use a patch method with authorization barrier token use the microsoft graph api call with slash sites site id lists slash list id slash items slash item id be sure to reference your item id to accurately patched item for headers authorization with value bearer space our access token variable and content type with value application json for the body is the same format as when you create a list item for those fields which you omit they will not be updated in my example i'll just be updating the list item which i've created with the field title and value updated item hit send and you get the 200 okay in the response we see our item id tool with field title has the value updated item let's navigate to the sharepoint hit refresh and you can see that our item has been updated from new item to updated item next the deleting a list item we'll use a delete method with authorization barrier token use the microsoft graph api call with slash sites site id slash list slash list id slash items slash your item id for headers authorization with value barrier space our access token variable hit send and you get a 204 known content let's navigate to the sharepoint hit refresh and you can see that our updated item has been successfully deleted in step 6 we'll use a get method with authorization barrier token in order to get a drive id a drive id is basically the id of your folder path be in sharepoint or onedrive use the microsoft graph api call with slash sites site id slash drives for headers authorization with value bearer space or access token variable send our api call and in the response we just need to locate the drive that we are working with in this case i'm working with the shared documents document library that comes automatically with sharepoint sites i'll locate the drive id copy it out and save it as my collection variable in this tutorial i'll be showing you how to read and upload files to sharepoint we'll use a get method with authorization barrier token to read all drive items use a microsoft graph api call with slash drives slash drive id slash root colon slash your folder directory colon slash children for headers authorization and value barrier space or access token variable in my case i have a folder called graph api in the shared documents folder send our api call and in the response the list of items in the drive will be listed we see there is a file called graphpic.png file in the folder we can head over to our sharepoint document library to validate this we will use a put method with authorization barrier token to upload a file to our sharepoint document library use the microsoft graph api call with slash drives drive id root colon slash folder directory slash your file name dot file extension colon slash children do note that the file name that you have here is the file name that you wish to see in the drive that is it doesn't have to be the same as the actual file name however the file extension should be the same for headers authorization with value bearer space rxs token variable in my case i'm going to upload myface.png file in the body as a binary send our api call we'll head over to sharepoint we can see that our file has been successfully uploaded hope you've enjoyed this video do give me a thumbs up if you did please subscribe to my channel as it helps me a ton if you have any questions do leave them in the comment section and help answer them see you and take care
Info
Channel: Voon Technology
Views: 26,434
Rating: undefined out of 5
Keywords: microsoft, free, singapore, developer, easy, guide, tutorial, office, sharepoint, m365, o365, sandbox, azure, ms, hack, hacker, singaporean, sg, 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, graph api
Id: adoaDmiGn18
Channel Id: undefined
Length: 11min 49sec (709 seconds)
Published: Fri Apr 29 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.