1

Below is the code, which is not working, shows below error

An unexpected 'PrimitiveValue' node was found when reading from the JSON reader. A 'StartObject' node was expected.

 const body: string = {
                    '__metadata': { 'type': 'SP.Data.InputsListItem' }, 'IsMapped': true
                };
    this.props.spHttpClient.post(`${this.props.siteUrl}/_api/web/lists/getbytitle('${this.props.listName}')/items(${item.Id})`,
      SPHttpClient.configurations.v1,
      {
        headers: {
          'Accept': 'application/json;odata=nometadata',
          'Content-type': 'application/json;odata=verbose',
          'odata-version': '',
          'IF-MATCH': '*',
          'X-HTTP-Method': 'MERGE'
        },
        body: JSON.stringify(body)
      });
  })
  .then((response: SPHttpClientResponse): void => {
    this.setState({
      status: `Item with ID: ${latestItemId} successfully updated`,
      items: []
    });
  }, (error: any): void => {
    this.setState({
      status: `Error updating item: ${error}`,
      items: []
    });
  • Be more specific. What does not work exactly? What is the error? What value is under listItemEntityTypeName? – Lukas Nespor Mar 4 at 6:47
  • The listitem metadata might be the problem, var item = { "__metadata": { "type": "SP.Data.listnameListItem" // change the listname }, "columnname": "value" }; – Vinod kumar G Mar 4 at 7:12
  • Check if you are using the correct internal column name – Gautam Sheth Mar 4 at 8:21
  • Even when I tried to update any other column, its same error, moreover generic error says "Bad Request" – Arun Mar 4 at 9:26
0

My test code for your reference.

let body: string = JSON.stringify({
      '__metadata': { 'type': 'SP.Data.InputsListItem' }, 'IsMapped': true
  });
  body = body.substring(1, body .length-1);
  body = '{' + body +'}';
  this.context.spHttpClient.post(`${this.context.pageContext.web.absoluteUrl}/_api/web/lists/getbytitle('Inputs')/items(1)`,
      SPHttpClient.configurations.v1,
      {
      headers: {
      'Accept': 'application/json;odata=nometadata',
      'Content-type': 'application/json;odata=verbose',
      'odata-version': '',
      'IF-MATCH': '*',
      'X-HTTP-Method': 'MERGE'
      },
      body: body
      })
      .then((response: SPHttpClientResponse): void => {
        console.log(response);
      }, (error: any): void => {
        console.log(error);
      });

enter image description here

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.