Posted by: R Manimaran | November 12, 2014

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:

//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));
}

Quick Launch Navigation

Creation in Top Navigation:


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));
}
Top Navigation

Top Navigation

Advertisements

Responses

  1. […] the Previous blog post we have seen how to create a Navigation using REST API in SharePoint 2013. Using that the […]

  2. […] https://rmanimaran.wordpress.com/2014/11/12/sharepoint-2013-working-on-navigation-using-rest-api/ […]

  3. Thanks, this really helped me!


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: