Posted by: R Manimaran | November 28, 2014

Creating Navigation under Parent in SharePoint 2013 using REST API

In the Previous blog post we have seen how to create a Navigation using REST API in SharePoint 2013. Using that the Navigation will be created at the end. Suppose consider I have a parent Navigation node and I need to create my new Navigation under that. To do we need to use the below end point.

REST End Point URL: /_api/Web/Navigation/GetNodeById(1031)/children

Here the value 1031 is the ID of the parent Node. You can get that using the GET verb of the below endpoint.

/_api/web/Navigation/QuickLaunch?$expand=children&$select=Title,Children/Title,Children/Id

The REST Output will be like below

RESTOutputNavigation

function createNavigationonHome() {
 var endPointUrl = "http://pwsp2013/_api/Web/Navigation/GetNodeById(1031)/children";
 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));
}

Navigation OnParent

Advertisements

Responses

  1. Hello Manimaran, This is a great blog post. This is exactly ehat I need. Is there a way to delete the item that we just added by any chance ?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: