17

I have a SharePoint 2013 page that I want to make updates to a hyperlink field in a list. I'm calling the REST API using JavaScript + jQuery.

My code (my hyperlink field is Timesheet_x0020_Page):

self.UpdateTimesheet = function(id, state) {
    var data = {
        '__metadata': { 'type': 'SP.Data.TimesheetListItem' },
        'Timesheet_x0020_Page': 'http://google.com, Google',
        'State': state
    };
    var url = "/_api/Web/Lists(guid'e95f5b86-64dd-41d9-9973-493d906ce75e')/Items(" + id + ")";
    var promise = $.ajax({
        'url': url,
        type: "POST",
        contentType: "application/json;odata=verbose",
        data: JSON.stringify(data),
        headers: {
            "Accept": "application/json;odata=verbose",
            "X-HTTP-Method": "MERGE",
            "IF-MATCH": "*",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        }
    });
    return promise;
};

But I get the following error:

{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"An unexpected 'PrimitiveValue' node was found when reading from the JSON reader. A 'StartObject' node was expected."}}}

1 Answer 1

29

You should try to using this. It may help you:

 var data = {
        '__metadata': { 'type': 'SP.Data.TimesheetListItem' },
        'Timesheet_x0020_Page': 
                {
                    '__metadata': { 'type': 'SP.FieldUrlValue' },
                    'Description': 'Google',
                    'Url': 'http://google.com'
                },
        'State': state
    };
3
  • Interested to see if that fixes it. I had the same issue earlier this week (calling from workflow). Rest API documentation really needs to be beefed up. Commented Jan 23, 2014 at 2:58
  • 3
    Yep that was it, thanks. Pretty interesting that values can have __metadata object. Commented Jan 23, 2014 at 3:05
  • Is there a web site we can go to learn or see more metadata combinations for various columns, not just hyperlinks? but for example, images...? Commented Mar 24, 2021 at 14:36

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.