2

In SharePoint Online I need to Update item in Workflow Task List using REST API on same server.

I am receiving 403 forbidden error, but I am on the same error and unable to identify why should I am receiving this error.

 $.ajax({
      url: "https://mysite.sharepoint.com/it/_api/web/lists/GetByTitle('Workflow%20Tasks')/items?$filter=(Title%20eq%20%27Employee%20Application%20Request%20No:%20621%27)",
         type: "POST",
         data: JSON.stringify({ '__metadata': { 'type': 'SP.Data.WorkflowTasksItem' } }),
         headers: { 
             "X-HTTP-Method":"MERGE",
             "accept": "application/json;odata=verbose",
             "content-type": "application/x-www-url-encoded",
             //"content-length": 1000,
             "X-RequestDigest": $("#__REQUESTDIGEST").val(),
             "IF-MATCH": "*"
         },
         success: function (data) {
             // Returning the results
             console.log(data);
         },
         error: function (data) {
             console.log(data);
         }
  });

And its giving below error: jquery-1.4.4.min.js:141 POST https://mysite.sharepoint.com/../ 403 (Forbidden)

6
  • Your url is not valid. for updating an item you need to use /_api/web/lists/GetByTitle('Workflow%20Tasks')/items('{Item Id}') Oct 17, 2016 at 9:41
  • Sorry, totally overlooked that URL. In general with 403 responses, check if you can READ first. Oct 17, 2016 at 9:47
  • OP is trying to find and update item at a time. But it's not possible Oct 17, 2016 at 9:51
  • I am unable to get WF TASK ID at Emp Application List. so i create filter which match Title, Status = Not started and Assgined to login user. always return single record, not found any issue in query. Oct 17, 2016 at 12:31
  • Any help from my answer?? @TahaZubair Oct 19, 2016 at 10:39

3 Answers 3

2

It's not possible to find and update items in REST API. You can update a single item at a time. So your End-Point should look like.

/_api/web/lists/getbytitle('{list name here}')/items({item id here})

OR

/_api/web/lists/getbytitle('{list name here}')/items/getbyid({item id here})

Find some useful information here.

Example

function updateItem(url, oldItem, newItem) {
    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + url,
        type: "PATCH",
        headers: {
            "accept": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val(),
            "content-Type": "application/json;odata=verbose",
            "X-Http-Method": "PATCH",
            "If-Match": "*"
        },
        data: JSON.stringify(newItem),
        success: function (data) {
            console.log(data);
        },
        error: function (error) {
            alert(JSON.stringify(error));
        }
    });
}
2
  • will you please share any format of olditem and newitem string. Oct 17, 2016 at 12:33
  • Information is already in my article. Use "*" for force update Oct 17, 2016 at 14:56
0

You are not sending data in the URL

What happens with:

"contentType": "application/json;odata=verbose",
1
  • nothing change on changing content Type. still getting "POST 403 URL (Forbidden)" Oct 17, 2016 at 9:33
0

In my case I found if we provide wrong details in meta data it will provide us 403 forbidden error.

So I change List name return by get Items query

data: JSON.stringify({ '__metadata': { 'type': 'SP.Data.Workflow_x0020_Tasks1ListItem' }, 'Status':'Completed', 'PercentComplete':'100','Nintex_x0020_Task_x0020_Outcomes':'Approved' }),

Also found that we need to get the result using GetById instead of GetByTitle

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.