SharePoint 2013: Working on Navigation using REST API
SharePoint 2013: Working on Navigation using REST API:
I have not find many articles on Navigation using REST API in the internet. Hope this post will be useful for someone or may be to me in future J
Navigation in SharePoint has two types.
- Creating Navigation in the Quick Launch( i..e Left Navigation)
- Creating Navigation in Top Navigation bar (i..e Top links on the page)
To create the above navigations we have separate endpoints respectively
QuickLaunch EndPoint :/_api/web/Navigation/QuickLaunch
TopNavigation EndPoint: /_api/web/Navigation/TopNavigationbar
In the below example I have added a link to my blog at the end of the existing links. I have used Jquery to call the REST API
Creation in Quick Launch bar:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
| //Create a Quicklaunch Navigation function createNavigation() { var endPointUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/navigation/QuickLaunch" ; var headers = { "accept" : "application/json;odata=verbose" , "content-Type" : "application/json;odata=verbose" , "X-RequestDigest" : jQuery( "#__REQUESTDIGEST" ).val() } var call = jQuery.ajax({ url: endPointUrl, type: "POST" , data: JSON.stringify({ "__metadata" : { type: "SP.NavigationNode" }, 'IsExternal' : true, 'Title' : "Blog" , 'Url' : "http://www.rmanimaran.wordpress.com" }), headers: headers }); call.done(successHandler); call.fail(failureHandler); } function successHandler(data, textStatus, jqXHR) { SP.UI.Notify.addNotification( "Navigation created Successully" , false); } function failureHandler(errorMessage) { alert( "Request Failed: unable to Navigation: " + JSON.stringify(errorMessage)); } |
Creation in Top Navigation:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
| function createNavigation() { var endPointUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/navigation/TopNavigationbar" ; var headers = { "accept" : "application/json;odata=verbose" , "content-Type" : "application/json;odata=verbose" , "X-RequestDigest" : jQuery( "#__REQUESTDIGEST" ).val() } var call = jQuery.ajax({ url: endPointUrl, type: "POST" , data: JSON.stringify({ "__metadata" : { type: "SP.NavigationNode" }, 'IsExternal' : true, 'Title' : "Blog" , 'Url' : "http://www.rmanimaran.wordpress.com" }), headers: headers }); call.done(successHandler); call.fail(failureHandler); } function successHandler(data, textStatus, jqXHR) { SP.UI.Notify.addNotification( "Navigation created Successully" , false); } function failureHandler(errorMessage) { alert( "Request Failed: unable to Navigation: " + JSON.stringify(errorMessage)); } |
Reference from https://rmanimaran.wordpress.com/2014/11/12/sharepoint-2013-working-on-navigation-using-rest-api/
Comments
Post a Comment