0

I have a list with name Product Catalog and there are two lookup fields with name Country Preference and Location Preference one date field and multiselect field.

I tested with list name without any space ex:- employee and simple field types and able to insert the data in the list without error. But with the above list name and the field types I am not able to insert the data. Error no. 400 Bad Request is displaying in the browser debugging console.

Might be there is problem in preparation of item as given below.

Can any one help me in correct preparation of item which i have to use it as payload in request.

I wanted to know following things specified inline in the below item variable.

var item = {
           "__metadata": { "type": itemType },
           datefield : correct value format,
           multiselect field : correct value format,
          correct Country Preferences lookup field name: correct value format,
           correct Location Preferences lookup field name: correct value format
       };

Also what should be the name format for the 'ListName' in the below url?

url: "http://<site url>/_api/web/lists/GetByTitle('ListName')",

jQuery.ajax({
        url: "http://<site url>/_api/web/lists/GetByTitle('ListName')",
        type: "POST",
        data: JSON.stringify(item),
        headers: { 
            "X-HTTP-Method":"MERGE",
            "accept": "application/json;odata=verbose",
            "content-type": "application/json;odata=verbose",
            "content-length": <length of post body>,
            "X-RequestDigest": $("#__REQUESTDIGEST").val(),
            "IF-MATCH": "*"
        },
        success: doSuccess,
        error: doError
});

Thanks & Regards,

Gopi

I am again describing the error below.

0

While adding/updating list item, REST endpoint should be like given below:

http://site url/_api/web/lists/getbytitle('ListName')/Items

Where ListName is Display name of the SharePoint List.

In your code, itemType is ListItemEntityTypeFullName property of List.

The ListItemEntityTypeFullName property is especially important if you want to create and update list items. This value must be passed as the type property in the metadata that you pass in the body of the HTTP request whenever you create and update list items.

Reference: Working with lists and list items with REST.

Correct Data format for different field types:

  1. Lookup Column:

For lookup type column, the value will be Integer and must be the ID of Lookup item. In the request body, you have to specified it as

InternalNameOfTheColumn + Id

Meaning that, If your column's internal name is Subsystem, in the request, it will be SubsystemId. Value of SubsystemId will be an Integer (Id of the lookup item).

JSON.stringify({ '__metadata': { 'type': 'SP.Data.FeaturesListItem' }, 
  'SubsystemId':"It will be integer"})

If your lookup column is Multiple selection field then you can set its value like:

'SubsystemId': { 'results': ["itemId1" , "itemId2",...]} 
  1. Date Column:

For date type of column, you can pass the string but it must be in ISOString format.

References:

  1. CRUD Operation to List Using SharePoint 2013 Rest API.
  2. Lists and list items REST API reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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