SharePoint rest api | SharePoint rest api example step by step | rest api SharePoint 2013

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we will check about sharepoint sdp how we can use it in sharepoint online uh as well as we will see some examples some other factors on this and then i'll show you how we can get a pdf which will have some examples and the details about the rest api that we are going to discuss now hello and welcome to the channel my name is pichai and i am a microsoft mbps specialized in sharepoint so now let's get started so in this video we are going to see how it is rest api and then how rest api works and what are the http commands that we can use and then i will show you some examples on the rest api endpoints and what is the advantages that you can get if you will use sharepoint rest api and then also we will see how we can get or send those digest value and that is required in when you are doing some update and then we will see some examples and we will do a demo on this video this this one also on this video and there will be some other examples you will get in that pdf as well so um so what i've done here is i have created a pdf for the same as i was talking about it so uh this pdf will contain everything it there is also a blog post for the same you can go through i'll put the link in the video description and then you can get it so you will get the pdf as well and uh so first of all what is rest api uh now the rest api um like we have different different object models which you can use to interact with our sharepoint objects we have see some we have json we have server-side object model as well now microsoft introduced sharepoint rest api in 2013 where we can interact with sharepoint remotely so uh your your sharepoint is somewhere and then you you can write yourself your code here and then you can connect with your sharepoint remotely now though the the advantages over here is uh you will you will use the open data protocol standard so sharepoint uh rest api uh when you are connecting to your sharepoint sites in this case whatever the technology that support rest that support rest web request then that you can use to to to connect to your sharepoint sites now basically in this case uh what will happen is uh you will construct a a restful uh request and using your open data protocol and then you you it will uh it will you will you will connect with your sharepoint site or you can get or you can even do the insert update all these things now if i'll give you a small example on this so uh let's say purely if you are working on sharepoint client object model then let's say we use list dot get by title and then the list name this will give you the particular list uh but in case of your sharepoint list api then you can use uh your sharepoint site url uh then slash underscore api slash list and then slash your get by title is the method and then you can provide the list name in in in encode in in single quote or double quote and it will give uh it will give you the least particular list so this is how you can actually uh you can actually uh work with sharepoint rest api this is a small example the same way let's say you want to retrieve all the list items so for example i have an employee list and you can see here get items i will use dot gate items there is a method which will give you all the items from that particular list the same thing we can do here like you know underscore api slash list slash get by title your list name slash items so here till underscore apa your site name slash underscore api for example in this case if you'll see here this is uh uh this is my rest api till your site and url and then underscore api slash list then get by title and then this is your list name and then slash item so it will give you all the items now our next thing is if you'll see here now what internally happens is your let's say look at this example this is a diagram that i have taken from mstn uh now there is a absolute solution and then on this if you will see here you are your rest code is there and then you will uh you will do a http request and then it will internally call the client.spc web service which will internally call to server object model and your server model when you interact with your container database or your sharepoint and then it will give you the required data in json or atom format so internally it will again it will call all these things so your server object model will get called but as we will not feel that so we will just pass a http up request now meanwhile if you are interested for sharepoint you can click on this url you will check the sharepoint training courses i have so you will also get a uh get a url where you can access the entire course as well now um so now let's next next one is the http commands that we we required for example normally if you will work with your sharepoint then you will do some in short update or create to delete like this operations so there are various http requests that we can do for example if you want to retrieve something if you want to read the data then you can use a http get request similarly if you want to add or update then you can use http post request you want to update uh the existing resources then you can use http put request and if you want to delete then uh then you can use http delete so uh these are quite uh quite understandable for how it is so for example if you want to create a list then since it's a create request or you are adding something then in that case it will be a post request now here are few of the things that i have added here when you will use the post command what will happen and then how we can use the put and merge things so what will happen on that is so uh when he will actually the merge request then uh all the settings of this properties will be optional so any properties that you do not explicitly uh um provide then it will set the current property so this way you can you can check out some of the additional things on this now um next thing is uh how we can construct that url that is what is known as the rest endpoint as well so for example um let's say uh there is a client object model we want to retrieve the list so i'll say clientcontext.web.list and in this case actually as i said your url site url slash underscore api slash waves list so it will give you the list so there are certain um these parameters are available this reference guide is available in msdnr as well you can check out this i have also added some reference urls which contains various examples that you can also go through and uh this code will work for uh for sharepoint online as well as on-premises also so you will not have any any differences only thing is your site url else other things will be same so your if you have written a rest code which is working on your sharepoint on-premises then the same code will work on the sharepoint online as well only thing is you need to update your url now similarly there is a rest endpoints for user profile search publishing all these things are there now let's let's just see some of the uh particular examples which you usually work every day for example you want to retrieve the wave title or something then if you'll see here then slash wave and then title so it will give you the current whatever the wherever you are using this code that wave title only so if i'll give only till slash wave then i can access all the properties but if i will put slash title then i'll only it will give me the property which is title now similarly the next one if we'll see here it will give me all the list and libraries which are presented in the sharepoint site and the second one if you'll see here it will provide the items from a particular list so that's the reason we are using get by title and then providing the list title so remember this is the title of the list and similarly if you want to retrieve only the title of the particular list then you can see here you can put a question mark select equal to title so it will only select the title property of that sharepoint list now what the advantages you will get it is uh when you don't need to really do any reference uh of to your sharepoint libraries so if you are using a javascript object model then your sp.js should be there in the page then only you will be able to interact with your sharepoint site but in this case um it will not you don't need any references for that so you uh all you need is the http rest endpoint and uh um yeah as i was telling you know this the speed.js file which is required but in this case it is not required uh and rest api another advantages will get is that if you actually put the rest url in the browser then you will be able to see all these properties on the browser itself you don't really require any other you can immediately see the output in that browser itself i'll show you that and then this is one thing that we required when we are doing a post or update operation we need to pass the form digest value that you can just write this line of code so that it will uh it it will understand that this is the request is coming from a safe page now there are certain examples that i have provided here before that you can use your sharepoint http code in normally you can use the popular you know code injection approach you can use a script editor webpart or a content editor webpack you can write your code over there that's one thing you can do the other thing is you can use sharepoint apps or the add-ins and you can use the code over there in this particular example what i will do is i will show you how we can do this thing in in in a in a script editor part in a classic sharepoint site so now if we'll see here i i want to retrieve the user display name from of the particular sharepoint site so this will be the logged in user display name now in this case i have taken a button so these are html code remember you should have some html knowledge for that so this is a html button you can see here i have a button click event which is attached to that particular button and then that's the reason i'm using the jquery library here you can see here because this is this code is a jquery code and then we will retrieve the user id by using underscore sp page context info this javascript variable will give you lot of properties on that and these two properties we are using here one thing is the user id and the other one is the web absolute url so it will give you the sharepoint url because i don't want to hard code that this is my url so it will take your url because this code let's say if you will hard code it then once you take this code from one server to another server you have to actually change the url if you have hard coded in this case you don't need to hard code it so it will take the current url it will take the current url and then slash on underscore api wave slash then get user buy id this is the method and it will take the id which will retry retrieve here and then then there is a request header that we need to pass your accept application slash json over data verbose and then this is how we can call our rest api url now dollar adjust and then you can see here the url so this is our url and then content type headers this is the request header and two things we are we have to pass here two methods one is the success and the failure so in the success what will happen and the failure what will happen so you will see here on the success method i have taken data d so it will give you the response and then now we have the user info contents whatever the values are there in this and then you can see here um user info.title so title will give you the display name and then if in the in case of some error occurred then it will show that we are just showing an alert in the error message now let me put in the uh script editor part so i'll open uh one of my sharepoint site so you can see here i was talking about the training so you can go through here you will check all the trainings here now this is the sharepoint classic site and you can see here this is the url and i will go and create a page so i'll go to view all pages and then you can see here i have some pages here so i'll just click on text page test page this is a test page this is a web part page not a modern page and i will click on edit page so i'll click on add a webpart and then if you'll go down here media and content you will see the script editor web part and just click on add so once you add the script or your script editor webpart then we can paste our code entirely here so in this case uh what i'll do is i will just copy the code here you can see here this is the this is the code and what we will what we will do here is i will just copy paste the code here and i will just pass it here i will just click on insert now i will stop editing the page so you can see here i have a button here as i was telling we have taken html button if i'll click on that then it is showing me the display name of this logged in user so whatever the id we are getting that information we are getting here now as i was telling you we can actually get the url here or we can uh we can in fact we will be able to construct that url which you can use to uh to get the particular things or the particular result you can see in the browser itself so what i'll do is i'll quickly i i want to see the user id so what i'll do here is i will just put an alert here so i'll put alert and then we will pass this user id so i want to see the user id here so whatever the user id is there so i just want to see so that we can use actually this we can construct this url here so i'll click on insert i will just submit it now you can see here nine is the username so in this case it is the username is nine and uh now you can see here this is the display name in fact we can actually uh get the particular url here so i will go here this is the request uri so this is what we required so i will go here and i'll put an alert here so basically we want to retrieve the url so our rest endpoint url so that will put in the browser and we'll see how it is appearing so i'll click on ok and this is the url so you can see here now this is our rest endpoint so i will simply go here i'll put it on this now you can see here you will be able to see the properties whatever are there on this for example you can see here the login name so if i'll put the login name then i'll get this result here so similarly this is the title you can see here it is returning the same thing and there are other things also you can you will be able to see here this is the id you can see here principal type which is this one and then email if you want to retrieve just you can have email here so that means in my code if i will say user info dot email then it will give me this email over here so this is how you can work with on the rest api we saw one example there are some more examples on this uh you can once you download this pdf you will have all this code available also and also i have some more urls which you can uh check it and you can see there are a lot of examples which are available on this you can see here sharepoint 2016 cloud operation using rest api and jquery uh there are some other things are also there list item cloud operation you can see here so you will get a lot of examples here so i'll put all these relevant examples on on this video description so if you like the video kindly subscribe to the channel just click on subscribe button and you will get a lot of free videos on this uh you will you will get on office 365 sharepoint azure teams uh spfx all these tutorials you will get it free so thank you and have a nice day
Info
Channel: EnjoySharePoint
Views: 18,413
Rating: 4.3414636 out of 5
Keywords: SharePoint 2013, SharePoint 2016, SharePoint Online, Office 365, SharePoint 2019, SharePointTutorial, sharepoint rest api tutorial, sharepoint rest api, sharepoint rest api example step by step, sharepoint online rest api tutorial, sharepoint 2013 rest api javascript example, sharepoint 2013 rest api tutorial, sharepoint 2013 rest api example, rest api sharepoint 2013, rest api in sharepoint 2013 examples, rest api sharepoint online, rest api sharepoint online example
Id: X_aMAFyIPSM
Channel Id: undefined
Length: 17min 45sec (1065 seconds)
Published: Thu Jul 23 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.