How To Test SharePoint Online REST API Using Postman

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello friends welcome back to our youtube channel ds tech meter topic for today video is how to access sharepoint online rest api using postman i will begin with the introduction of the postman what is postman postman is an interactive and automatic tool for verifying the apis of your project in today's video we will consider sharepoint rest apis it is a google chrome app for interacting with http api it is most commonly used for api testing so it is a very useful tool let's say you are working on a project and you are working with rest api so what you can do you can easily test your rest api with postman you can check the response you can check the header easily and once your api is working in postman then you can directly use into your project it will help you to test your api very easily its response its end result so it's a very useful tool for sharepoint development projects and other projects as well let's let's start with the postman this is my postman tool you can download it you can find the link in the description box below how you can download the post postman so before working with the postman what i can do postman allow me to create a collection now there are certain advantages of creating a collection in postman if you create a collection in postman then you can keep all the related apis related to a project or maybe similar apis together in one collection then it is easy to you know you can easily find your rest api another important thing is if you have created a collection let's say related to a project you have created all the rest api and you want to share with your teammate it is very easy to share it you have to just export your collection and you can share it with over email or through any other tool so these two are very important advantages of creating a collection so we will start how we can create a collection in postman and then how we can keep all the rest apis together so over here in the left you can see i have a link new collection i will create on it and i will name it as test postman with sharepoint online i'll say sp online and i will create so now my collection is ready now i will test the rest api i will go with a very simple api of how to get a list item from a sharepoint list so i'll say create a request so now what i will do i will rest api with me get list item i will simply copy it now you might be thinking that i have this uh interface for testing the rest api i should be able to do it so let's see i'm trying to test an api and let's see what all issues i will face while working with the postman initially so this is my rest api over here you can see my sharepoint site is open with me it is ds tech mirror tutorial and over here i have create a simple list with just simple one column that is the title column there are no other columns in this list and i'm in one entry called entry one so i will copy the name of the list display name which is postman list name is also postman over here you you can see the rest api this is my site name till here after that you can see underscore api slashware slash list i am getting all the list after that get by title so my list title is postman and i am saying i want all the items present in that list after that there are few headers which i want to supply over here first is accept a value will be application slash json and odata is equal to verbose then i have content type the same content type application slash json or data equal to verbose and now what i will do i will save my recipe i will press ctrl s and over here it is asking me for the collection i can save this rest api inside the collection so what i will do i will search for my collection at the bottom it is test and i can say test postman with sp online and now save to test postman with sp online i will click on this button and i can see my rest page got saved inside this collection so this is one thing now what i will do i will click on send button and i am getting bad response that is 400 bed request over here i can see this is something related with the content type now before proceeding with the postman let me show you what result i will get if i hit this url in the browser so this is my browser i will open a new tab and i'm getting the result so you can see over here i'm getting all the list item so for me my rest api is working now i will copy the same rest api in my postman over here control a control b and now i will hit so over here i am getting the statuses 403 forbidden that is access denied you do not have permission to perform this action so what is the issue i am facing is my postman is my third party api it is trying to interact with the sharepoint online and sharepoint online is not allowing postman to access its item which is you know fair enough because of the security issues because of the security concern postman is not authenticated provost man is not authorized to get data from the sharepoint online so to get data to establish the connection between postman and sharepoint online we have to you know set up the authentication between these two different parties once the authentication is established between them then they will be able to interact with each other to establish the authentication what we have to do we have to you know register this postman for the authentication purpose to get data from the sharepoint online postman must have the access token with the help of access token only postman will be able to interact with sharepoint online you know that in sharepoint online for the authentication we have oo2 with the help of over two sharepoint online or authentication works so let's see how we will be able to establish the authentication between sharepoint online and postman so for the postman authentication for that what i have to do first of all i have to register an app to register an app what i have to do in my earlier videos i have you know shown you many times in my earlier videos i have already demoed how you can register an app in share my online so for that what i have to do this is my site collection with which i want to interact i will say underscore layout slash 15 slash app register new is the url okay i do not have access to it so let me first get the access to this particular url so now i've got the access to that particular page app register new so i will try to navigate to that page again rng new dot aspx so over here i can register an app so what i will do i will generate a client id this is my client id this is my client secret i will name the title as postman app domain will be again i will keep it as postman and redirect url i will keep this particular site only i can keep as the local host also so in in this case i will keep the stack mirror tutorial only so ds tech mirror hyphen tutorial so these are the entries which i have to make first client id i have to generate it client secret again i have to generate it and title app domain and redirect i have to fill in these values so now i will click on create it will register an app with postman title inside my sharepoint online now i have to keep this client idea inclined secret with me very carefully i will be needing these both in my future setup so what i will do in this slide only let me simply create a new slide and i will keep all the useful things over here so this is my client id and client secret okay done next moving forward what i will do i have to navigate to a principal page now that is app imv app inv dot aspx so please remember this particular url this is app inv page over here i will give and permission to my app so before this i have registered my app with sharepoint online now i will give permission to that particular app so in my case i will give full control permission to my app postman app which i just now register you can give other permissions as well so i have to enter the client id over here so this is my client id i will enter the client id i'll say look up so it will fetch all the related information to my app which is registered inside sharepoint online so you can say title app domain and redirect url in this box i have to give a permission request so i will give full control permission for that we have a small xml code so i will enter this inside this box this is a multiple line text so over here you can see what i am doing app permission request allow app only policy true app permission request scope is sharepoint content site collection web and full control and then i will close the app permission request app permission request so now i have granted the permission full control permission over the site collection content to my app so now let me just format my code a little bit it's a very small piece of code and let me click on create so now in this in this step i have given full control permission to my app i'm getting a pop-up uh do you trust it so i said yes i trust it and this is done so now i have registered an app in my sharepoint online ds tech mirror tutorial site collection with full control permission over the contact and i can check it for that what you can do under site collection administration just check for site collection app permission link click on it site collection app permission and over here you can see you can see this app so you can see this app identifier and it's very important so this is my client id till before add the date this is my client id you can even verify it we have copied it uh you can see d82d so this is my client data and after that i have this tenant id this is my tenant id and i will be requiring it in my further in my next step so i will be using it so let me copy it i will let me copy this entire identifier from this i will get the tenant id so let me just paste it i will paste it on a separate step okay so this is my pendant id so let me just let's see if i can set the font color just to make it more readable yes and let me just increase this bit so this is my tenant id guys please remember after the add the rate i have the done entire day and before app identifier i have the client id okay so we are done with this now we have to get the access token we will see how we can get the access token so let me go to my third slide this is postman authentication this is the first step register an app with sharepoint online using client editing client secret so this is done this is the code now get access token for postman authentication with sharepoint online using below rest api so this is the rest api url i will use this to get the access token and this access token we will use for other rest api urls so how to get the access token let me enter this uh create a new request so so this uh you can you can see now rest api to get the item from sharepoint online will still not work so still still forbidden so let me get the access token for this rest api to work so i'll go to the launchpad tab create a request it's a get request and this is my url https accounts.accesscontrol.windows.net over here i have to enter the tenant id slash token slash o2 so let me enter the tenant id now guys i told you i have already copied the tenant id so this is my tenant id so let me just copy it and please take care of the trailing spaces and make sure there is no space in your tenant id so this is my tenant id so i've entered the tenant id after the tenant id i will save this rest api in the same collection my collection is test postman with sharepoint online and request name will be get access to so you can see how useful is the uh how useful is to create collection in postman we can easily you know we can easily organize our rest api this is to get access token and i will format the another one also let me quickly do it so for this i want to name it as i have to see from i think over here i can name it yes and i think its name will be get list item see get access token get list item so we are working with the uh access token now i will simply add the headers headers will be same content i will accept so i will copy it from here only so over here to copy the header it is very easy just go to header tab and on the right side you can see bulk edit click on this bulk edit and you will get this tab i will copy it i will go to the get access token again bulk edit but with the header tab i want to edit the headers bulk edit and simply paste it now again you can click on key value edit and you can see my headers are ready my token is ready my headset ready let's see in the ppt if there is anything else yes so i have to enter a few values in the body tab so i will come to the body tab and this time it will be form data i will select the form data and i will enter few types first will be grant type let me see if i'll get some intelligence okay no so i'll say grant type after grant type i have client id i have client underscore id after that i have client underscore secret so guys this is very important step and then i have resource so guys i will explain you all these entries see grant type will be client underscore credentials this is simply hardcore you just type client underscore credentials okay next will be cr client id client id we have to enter in the format client id add tenant id which is this entry so we have already copied so let me copy it and now i will paste it over here i will make sure of the spaces at the end and in the beginning there is no space so client id is done client secret as i've already copied this is my client secret and last one will be the resource resource also i have to enter in a particular format so format for the resources resource slash site domain add tenant id so this is my resource okay and value of resource will always be the same this is the value of the resource so i will copy the resource over here so this is my resource then slash this is my resource and it will always remain the same guys you can note it from here if you want the resource value if you are trying it at your end then site domain site domain will be i will enter my site domain that is my tenant domain and then will be and if you are confused with the site domain it will be after https and before sites so this part will be your site domain okay then after site domain it is the format resource let's slash site domain at tenant id so i'll go site domain let me go to the bulk edit because it is easy to work over here at and then i want to the tenant that it is the same i i will copy it from my client id because after i did it i told you is the tenant id so my this entries are complete and i'll go to key value added so you can see grant type client retention client id is this client secret is this and resource i will save it and let me try if we'll get some error we will fix it otherwise and return we should get the access token and it's a bad request so we are getting some error the request body must contain the following parameter grant underscore type okay so i have typed over here grant and hyphen it should be grant underscore type okay now save i'll send it again again a bad request i'm getting i think it is related to my tenant okay so i will remove this parenthesis from here the scores control save and send and you can see status 200 okay before going forward i will come to my ppt and i will explain you for the postman authentication register an app over here using app register name app new dot aspx okay after that for permission you should go to app inv dot aspx after that in the postman in the postman this is my url and over here there will be no codes just enter your tenant id from where you will get the tenant id just go to site site collection app permission in your site settings and over here for the particular app let's say if you have register your app with the name test then search your app with name test and over here there will be a complete identifier after added will be your tenant id these are the headers content type then body grant type these four values are very important one is the grant type client id client secret and resource grant underscore type value will be client address retention client underscore id will be client id at tenant id same you have to i'll type okay over here i will type same as it is under site collection app permission okay so over here you can see client secret you can get it and resource will be in the format resource slide slide domain add and entity so these value once you will enter you will get this access token and guys this is the most important value now your postman is authenticated to interact with gs tech mirror site collection using this access token we were looking for this particular access token now we have got the access token now what i will do i will use this access token so this is the access token and just for your information again this was the rest api which we used accounts dot access control dot windows dot net tenant id token slash over two so you can note it down it is available in my api you can not all the information from here just using this you will be easily able to establish connection between your postman and your sharepoint online tenant so now we will go forward and we will test other rest api that is we will see if we are able to get the list item now so i will copy this access token i will go to the header section key value edit and over here i have to enter another header that is authorization for the authorization value will be this is very important guys bearer b-e-a-r-e-r now please make sure to enter in space after br and then copy paste the access token please do remember to make a space between bearer and your access token i'll go to bulk edit and you can see this is how it should look content type accept and authorization and now let me click on it again send and you can see status 200 the moment i enter this access token i am able to get all the list items you can see i'm getting all the list items there's only single list item over here in my uh list it was like entry one so we i will show you where i'm getting that let me expand it so i'm getting content type all all this thing in json format i'm getting so over here you can see id1 and if you want i can search from here and you can see title entry one over here in this id one content type id title modified all these metadata properties everything will come in this let me show you what i will do i will i will make one more entry over here this time let me go to my app my app name is postman i will make one more entry and this time it will be entry two i will show you whether i will get it save and now let me simply go to postman and send the request again this time i should get two entries inside the results content type after this at the bottom i am getting this id1 entry one and after that again at the bottom i can say id 2 and redo so my get request is working absolutely fine now moving on to next i will see how i can create a list item with the help of postman so again go to the launchpad create a request i'll say i will um you know enter the url to create a request in the same list so to create the item i have to change the header i have to change this method of my restrict earlier it was a get request now it should be a post request because we are posting something in my sharepoint online so i will take this rest api url because i have to this time i have to uh create an item url will remain the same it's just the type is got change now type is the post this time it's a post request so you can see you underscore api list get by title slash items now headers headers also will remain the same i will copy the header as it is and i told you to copy the header simply go to the header tab bulk edit and simply copy everything and i can close this get access token because it creates some confusion over here i will come to this bulk edit and i will simply paste it i will click and simply paste it ctrl save and request name i will say create list item create list item in the same collection this is also done now i will let me check my headers again let me just scroll up and key evaluated so i've got everything now again now i want to create a list item so i have to supply the values i have to supply the column values this one single column over here it's it is title i have to supply the title value and that i will do under body tab for that i will select this row sorry raw data not row table row it's the raw data radio button i will select and over here i will supply the values for that this particular format in which i have to supply i will just paste it over here and then i will explain you so this is the format which we have to supply for under the body tab this is under this parenthesis underscore underscore metadata remember this is double underscore type we have to provide sp.data dot list title list item list title i have to change with my list title so my list title is postman so i'll say post my list item and over here i will say title this is it title column will give the value entry through postman entry using postman so i will save it i will save the value and i will run the i will send the request let's see and it's a bad request again we will see what is the error our type name sp.data dot postman list item could not be resolved by the model okay so there is some error over here we will see what is the error so over here we are getting this value at type name sp dot data dot postman list item could not be resolved by the model so there is some some problem with this over here you can see i told you over here we have to enter a list name so let me go back my list name is i will go let me go back i will go to the browser my list name is postman but if you notice carefully my internal name there was a typo because of which there's a wrong internal name and i have to use it there's a difference between the internal name and the display name so postman this is post amen so this is a mistake which i did so because of which over here just remember we have to enter the internal name of the list and not the display name that is the title so let me change this over here so this was the mistake okay so this is also done now and it should create an entry with name entry using postman let me send it and you can see status 201 created let me refresh it and you can see enter using postman if i enter again enter again and i can see multiple i should see multiple entries over here see enter using postman enter using postman so our create request is working perfectly fine so we are done with the get create and i will do one more request although i think now you know how you can authenticate now you can test your apis with sharepoint online using postman it just i want to give a sample for each create update that is create read update and delete so create and read this fine now before using the update one i will uh let me create for the delete request so i'll use the same it just i will i have to modify this api rest url so in this what i have to do slash item slash get by id so i have to you know supply the id which particular item i want to delete for that i should know the id of these entries for that i will modify my view and i will include the id also so edit current view and i will say i want the id i will get the id and now i want to delete the last item so i will supply the id 6 so id is fine after that again type of the request will be delete this is important header will be more or less will remain the same so ideally these three headers are requested i required in almost all the request that is authorization content type and then another one that is my uh let me paste it comment key value so these three address i require uh required in almost all the request content type accept and authorization i will name it as delete list item and save this so delete is also fine and now let me try let's see if we get any error for that i think i have to rename it let me first rename it delete list item request name i don't know where i have you know update the delete list item so let me just send it and i am getting access denied so this is strange i should not get access to night let me see because uh okay because of this headers i have pasted at the wrong place i'm getting the error okay bulk edit paste header is fine okay okay my bad i am pasting it under the parameter tab i will go to the header tab bulk edit and then i will paste it yes now it should be fine now evaluate it now let's see whether this will work or not so we are trying to delete an item with id6 and we are getting request e-tag value does not match so we have to supply the e tag we have to supply one more [Music] header that is if match i'll say star and now let me send it again and i got 200 so item this item must be deleted in my list so please remember to use if match and just supply the star and got deleted so guys we are also done with this delete list item and the last one which i will create over here is to update a list item so let me close this delete one get and let me first save this i will name it as update list item same collection test postman with sp online save i will enter the url i will have to modify it a bit till items you are getting it will again be a post request and i'll say i have to uh supply the id i will update this one with id4 entry using postman so get by id and id will be four now it is also done i have to supply few more headers headers i told you more or less these three address i need so at least these three address let me copy and this time i will carefully paste it under i will carefully paste it under headers tab so this is done i will come to key value edit and now again i have to you know supply the updated value i will be updating the title column so again i will go to this body tab and in this under i will select this raw option and over here again uh let me copy this body let me copy this metadata and i will paste it as it is entry using postman updated successfully this will be my updated value and again because you know we are updating a particular id i have to supply the if match also so if match is star now let's see i will click on send [Music] and i got this 400 bad request because this metadata does not exist in method get by id okay this value i will enter one more header it will be x http method i should get the intelligence i just want to use this x okay i'm not getting x http method value will be merge let me save and try again if this will fix the issue and i got 200 for no content because it updates the list item but in return it will not get anything so let's go to the browser and you can see enter using postman updated successfully let's try to do the same with this item id5 i'll change five save send and i will come here so you can see i'm not refreshing my machine i'm not refreshing my browser but i think it will update on its own you can see entry using postman updated successfully so this is how uh we perform all the rest apis quickly i will you know make a quick revision so this was the simple api uh get request i'll say underscore api web list get by title and items header these three edits are common content type accept and authorization for creating the list item we have to supply the body and the body we have to supply the values this is important type dot data dot url is internal name list item and the title rest headers remain the same for the delete uh for the uh sorry create item yeah for the delete one again we have to make uh supply one more header if match for the update two more header if match and x http method along with this body so guys this is how you can use postman to test your rest api to test the response using postman in this video this all we have covered how you will authenticate your postman using app registration so guys that's it for today's video if you like this video please like and share the video and subscribe to the channel to get the notification for our upcoming videos you can reach out to us using our official email id contact dstechmeter.gmail.com i have created a group over facebook you can join that group with the name modern sharepoint and we can collaborate over there to get all the updates from the office 365 world you can follow me on tutor this is my twitter handle much love keep learning thank you
Info
Channel: DS TechMirror
Views: 60,994
Rating: undefined out of 5
Keywords: SharePoint online, rest api, postman, sharepoint rest api, test restapi
Id: YMliU4vB_YM
Channel Id: undefined
Length: 34min 57sec (2097 seconds)
Published: Sun Jan 17 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.