none
REST Request To Update/Modify Quick Launch Nav Node RRS feed

  • Question

  • My HTTP Request sends the following parameters to update the Current Navigation (left-side) link I want modified.

    url: https://<my-server>/_api/web/Navigation/GetNodeById(<node id>) method: POST headers: "X-RequestDigest":<digest-value>, "X-HTTP-Method":"MERGE", "IF-MATCH":"*",

    "accept": "application/json;odata=verbose", "Content-Type": "application/json;odata=verbose" body/data: { '__metadata': { 'type': 'SP.NavigationNode' }, 'Title':'<display name of nav node/link>', 'Url':'<URL of the nav node/link' }



    The HTTP responses have been 204/"nocontent". But I refresh the page where the links are seen, and the link URL has not been changed.  I can change the display name ('Title') property and it does change, but not the URL!

    I have tried variations on the header "X-HTTP-Method". "MERGE" and "PUT" are on MS official SharePoint pages, but others have mentioned "PATCH" (not sure why). In some cases, I found 400 returned status code about 'IsVisible' not being specified in the body.

    MERGE works at least to change the title.

    If I am forced to do a DELETE and CREATE process because an existing URL is immutable using a REST request, how does one position the Quick Launch nav links relative to each other (top to bottom)? I want this in a certain location under the Header node (property URL="/")


    • Edited by Mavi Gozler Sunday, June 28, 2020 4:30 PM fix code block
    Sunday, June 28, 2020 4:27 PM

Answers

  • Hi Mavi,

    I tested the code snippet in my reply above, also updated the Url property for the link, please see the changes below:

    Original Link is Default Documents Library Link, redirect to the AllItems.aspx:

    After updating with Rest API code above, href set to "/" and redirect to the root site:

    In additional, please make sure the Id is valid, you can check the Id by doing GET Request to the following endpoint:

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by Mavi Gozler Tuesday, June 30, 2020 2:10 AM
    Tuesday, June 30, 2020 1:17 AM

All replies

  • Hi Mavi,

    Try to use PATCH in Rquest Header like this to update Navigation Node:

    <script type="text/javascript">
    UpdateNavigationLinkById(2001);
    function UpdateNavigationLinkById(LinkId) {
        $.ajax
            ({
                // _spPageContextInfo.webAbsoluteUrl - will give absolute URL of the site where you are running the code.
                // You can replace this with other site URL where you want to apply the function
     
                // Enter the Id of the search node that you want to delete
                url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/Navigation/GetNodeById(" + LinkId + ")",
                type: "POST",
                data: JSON.stringify({
                    '__metadata': {
                        // Type that you are modifying.
                        'type': 'SP.NavigationNode'
                    },
     
                    'Title': 'Updated Documents',
                    'Url': '/'
                }),
                headers:
            {
                // Accept header: Specifies the format for response data from the server.
                "Accept": "application/json;odata=verbose",
                //Content-Type header: Specifies the format of the data that the client is sending to the server
                "Content-Type": "application/json;odata=verbose",
                // IF-MATCH header: Provides a way to verify that the object being changed has not been changed since it was last retrieved.
                // "IF-MATCH":"*", will overwrite any modification in the object, since it was last retrieved.
                "IF-MATCH": "*",
                //X-HTTP-Method:  The MERGE method updates only the properties of the entity , while the PUT method replaces the existing entity with a new one that you supply in the body of the POST
                "X-HTTP-Method": "PATCH",
                // X-RequestDigest header: When you send a POST request, it must include the form digest value in X-RequestDigest header
                "X-RequestDigest": $("#__REQUESTDIGEST").val()
            },
                success: function (data, status, xhr) {
                    console.log("Success");
                },
                error: function (xhr, status, error) {
                    console.log("Failed");
                }
            });
    }
    </script>
    

    The Link Id in the code snippet above needs to be replaced with yours.

    Here is the result after updating:

    Reference:

    Update Quick Launch Link in SharePoint using REST API

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, June 29, 2020 2:39 AM
  • Hi Jerry,

    That cited web page you indicated in your post using "X-HTTP-Method: PATCH" is one of the things I found on the web and tried. I mentioned in my original post trying "PATCH". It does the same thing as "X-HTTP-Method: MERGE" and "X-HTTP-Method: PUT", and MERGE and PUT are officially mentioned on using the SharePoint REST API. Without the use of an "X-HTTP-Method" header, the following error message is given: "The parameter __metadata does not exist in method GetNodeById."

    But the REST request is not doing what is expected. After doing the POST request, I immediately do a GET request on the node and only the 'Title' property is changed, not the 'Url' property. This is also proven in going to the site's home page (refreshed) and checking the left nav (Quick Launch) panel: the displayed name of the link is changed, but the URL is not changed (!).

    Is the REST request in your use of it changing the 'Url' property of the Quick Launch link, Jerry? I am not seeing it on my side.

    When I go to Site Settings => Navigation, the Local Navigation is the same: the displayed name is changed, but not the URL. I checked whether the Navigation page is working: after editing the link in the interface, then only after clicking "OK" on the Navigation, the URL of the left nav panel is updated. There is an interesting thing in using Site Settings => Navigation: after clicking "OK", SharePoint is deleting all the Top Bar and Quick Launch links, and recreates its structure using new node IDs, enumerating from the last node ID used (as with unique system-generated IDs in list/lib items).  Figuring that would be the case, my single page web application is designed first to get all nodes (Request URL: https://<site-path>/_api/Navigation/QuickLaunch, expanding Children) then search for the node I want using the 'Title' and 'Url' properties in order to get the ID value for modifying the node.

    Now I will have to look for a workaround. If I cannot use the REST API to change the 'Url' property (and only the 'Title' property), I will not be able to use new file names. I was adding a Month-Year part of the file name to know the version of the file.  Since I cannot change the file name as it will break the QL link, and since I want to keep track of the Month-Year version of the uploaded file, I  will have to store this metadata somewhere, probably as a JSON string in the unused 'Title' field [column] of the dob lib, with its single-line-of-text data type; I may store other metadata compactly in JSON form.

    I would still like to learn from SharePoint developers why the 'Title' property and not the 'Url' property of a nav node can be modified using the REST API.

    ------------------------

    Why is being able to change the URL and not just the displayed name of a Quick Launch link important?

    In our government enterprise, we have office techs who provide updates to org charts and phone lists as PDF files on a SharePoint doc lib. They are given written instructions to change the file name and upload to a certain location in order not to break the QL links. But they constantly make mistakes and users are constantly getting "Page Not Found".

    I thought it would be easier instead to create a web application with form and drag-and-drop file upload. They only have to set radio inputs for the organization and the type of document (phone list, org chart), and the form processing does the rest: file rename, copying older versions to archives, and updating QL links on the home page. If the updating-QL-links-on-the-home-page part does not work, something else must be tried/done.
    Monday, June 29, 2020 5:23 PM
  • Hi Mavi,

    I tested the code snippet in my reply above, also updated the Url property for the link, please see the changes below:

    Original Link is Default Documents Library Link, redirect to the AllItems.aspx:

    After updating with Rest API code above, href set to "/" and redirect to the root site:

    In additional, please make sure the Id is valid, you can check the Id by doing GET Request to the following endpoint:

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by Mavi Gozler Tuesday, June 30, 2020 2:10 AM
    Tuesday, June 30, 2020 1:17 AM
  • I have a Postman-like Request/Response tool I use and believed I had been setting it up correctly, but apparently I was not. Given your own test, I re-tried it and it was working. Thanks.
    Tuesday, June 30, 2020 2:13 AM