0

I have issue with my query to post item on test list, it returns 400 error. My list columns:

Title | user

Here is my body of json:

       const body: string = JSON.stringify({
      "__metadata": {
        "type": "SP.Data.TestInsertPersonListItem"
      },
      "Title": "test",
      "user": {
        "__metadata": {
          "type": "SP.Data.UserInfoItem"
        },
        "Id": 8,
      }
      });
    return this.props.spHttpClient.post(`tenant.com/sites/randomsite/_api/web/lists/getbytitle('TestInsertPerson')/items`,
      SPHttpClient.configurations.v1,
      {
        headers: {
          'Accept': 'application/json;odata=nometadata',
          'Content-type': 'application/json;odata=verbose',
          'odata-version': ''
        },
        body: body
      });
  })

and it returns 400 error with error:

A type named 'SP.Data.UserInfoItem' could not be resolved by the model. When a model is available, each type name must resolve to a valid type.

When I leave only Title it works as expected. Does anybody face similiar problem and deal with it ?

0

For the name of the user column use <ColumnInternalName><Id> i.e append Id at the end of the column internal name. The value should be user id (integer). In your case it should be userId: 8

0

I solve this, just have to check how it looks like in network debugger, jesus sharepoint. Here is solution:

const body: string = JSON.stringify({
  "__metadata": {
    "type": "SP.Data.TestInsertPersonListItem"
  },
  "Title": "this is bull..",
  "userStringId": "8"
});

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.