4

i have a workflow on "Site 1" which uses a rest call to update a list item on 'Site 2'. i have followed many sites, solutions etc. but nothing seems to work. I keep getting this error:

{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"The parameter __metadata does not exist in method GetById."}}}

This is my Request header:

  1. Accept= application/json;odata=verbose
  2. Content-Type= application/json;odata=verbose
  3. X-RequestDigest= Variable:RequestDigest
  4. X-HTTP-Method= MERGE
  5. IF-MATCH= *

__Metadata header:

  1. type= SP.Data.LISTNAMEListItem

Request content:

  1. __metadata= Variable:__metadata header
  2. Title= Modified by workflow

In the actual call:

Address: https://SITE/SITE 2/_api/web/lists/GetByTitle('LIST ON SITE 2')/items(3)

Request type: POST

I need some assistance in resolving this as I have been at it for some time and haven't come got any positive results as yet. Has anyone experienced this issue before? if so, how did you resolve it?

3 Answers 3

4

I think your problem is in the metadata header, just for an example I use somthing like this

var itemMetadata = {
    '__metadata': {
        'type': getListItemType('your_list_nale')
    },
    'parameter_1': wherever_you_data_comes;
};

And the calls should be

$.ajax({
    url: http://your_site_url/items(id),
    data: JSON.stringify(itemMetadata),
    type: 'POST',
    contentType: 'application/json;odata=verbose',
    headers: {
        'X-HTTP-Method': 'MERGE',
        'X-RequestDigest': $("#__REQUESTDIGEST").val(),
        'Accept': 'application/json;odata=verbose',
        'IF-MATCH': '*'
    },
    success: function (item) {
    //your_code
    },
    error: function (err) {
        console.log(err);
    }
});

Just to be sure of the type I use another REST call

function getListItemType(name) {
    var vRetorno = "";
    var oUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + name + "')?$select=ListItemEntityTypeFullName"
    $.ajax({
        url: oUrl,
        method: "GET",
        async: false,
        headers: {
            "Accept": "application/json; odata=verbose"
        },
        success: function (data) {
            vRetorno = data.d.ListItemEntityTypeFullName
        },
        error: function (data) {

        }
    });

    return vRetorno;
}
1

I would start by making sure your URL and list name are correct. You can check this by using a REST Console utility (I use REST Console in Chrome browser) and sending a GET request for the list properties.

Example URL:

[your site url]/_api/web/lists/GetByTitle('MyTable')

Look for this to verify the list name "ListItemEntityTypeFullName": "SP.Data.MyTableListItem"

Hope that helps.

0

Since you stated "workflow", I assume you are using SharePoint Designer 2013 HTTP Web Services action.

I did receive this error in the past. I don't recall the exact issue, but here are some things I recall modifying. Hope they help.

  1. Make sure that the __metadata is set as Dictionary enter image description here
  2. Make sure the properties are set correctly on the call. Right click on the "Call" line. I had forgotten to set the RequestContent to the parameters dictionary. enter image description here
  3. As maleman has said above, also verify the URL is valid. You can just place the URL in the browser and see if you get a valid response back.
  4. Make sure when setting the metadata dictionary, the Name is "type" not "Type". It requires a small "t".
  5. If the workflow needs to run across sites, elevated workflow privileges needs to be used. See "www.advaiya.com/blog/sharepoint-list-workflow-create-or-update-list-item-on-another-sharepoint-site-list/" and "dev.office.com/sharepoint/docs/general-development/create-a-workflow-with-elevated-permissions-by-using-the-sharepoint-workflo" on how to do this.

If any of the responses have helped or you have found the answer, please update this to help others.

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.