0

I have a lookup column that I want to update using the Sharepoint REST API. the column is called "Titular" and shows the title of a list of companies. I have this code:

const body: string = JSON.stringify({Titular: {Title: "company1", Id: 1}});

 this.props.spHttpClient.post(`${this.props.siteUrl}/_api/web/lists/getbytitle('mylist')/items(${this.state.idQ})`,
          SPHttpClient.configurations.v1,
          {
            headers: {
              'Accept': 'application/json;odata=nometadata',
              'Content-type': 'application/json;odata=nometadata',
              'odata-version': '',
              'IF-MATCH': '*',
              'X-HTTP-Method': 'MERGE'
            },
            body: body
          })

I do not know if the sintaxys is wrong but I have tried several options:

const body: string = JSON.stringify({"results":[{"Id":1,"Value":"company1"}]});
  const body: string = JSON.stringify( [ "1;#company1"]);
  const body: string = JSON.stringify( {_ObjectType_:"SP.FieldLookupValue",LookupId:1,LookupValue:"company1"});
  const body: string = JSON.stringify({ "__metadata": { "type": 'Collection(Edm.Int32)' },  "Results": [1]});

In all of them I get an error "400 (Bad Request)"

Thank you! And regards

0

Well I have found the solution. Just put the lookup field id in this way

  const body: string = JSON.stringify({TitularId: 1});

change the name "Titular" by "TitularId" and add the id

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.