1

I want to create 3 columns in a SP list from my SPFX webpart using REST call. Could you please let me know how to achieve this? I am using below code to create 1 column but instead I want create 3 different columns using single REST call.

url: https://test.sharepoint.com/sites/dev/_api/web/lists/getByTitle('MyList')/fields
    const response = await fetch(url, {
       method: 'POST',
       credentilas: 'include',
       headers: {
           Accept: 'application/json;odata=verbose',
           'Content-Type': 'application/json;odata=nometadadat',
           'x-RequestDigest': xRequestDigestValue
       },
       body: JSON.stringyfy({
          Required: true,
          FiledTypeKind: 6,
          Title: 'MyChoice'
       })
    }
13
  • Are you asking how to create 3 columns with a single call? Oct 9, 2020 at 13:34
  • Yes, 3 columns in a single call. You are correct.
    – sarbashis
    Oct 9, 2020 at 13:37
  • I guess you can make batch requests with the REST APIs for such requirements. Check for it. Oct 9, 2020 at 15:10
  • 1
    In a very general sense, yes, fewer calls are better, however there are times when you just can't do what you want with a single request. :) Also, though, 1 vs. 3 is less important to try and optimize than 1 vs. 20. In this case (creating fields), I do not know for sure that you can't do what you want with a batch request, I would research that as Ganesh has suggested if you really want to try to get it done in a single call. But personally - 1 vs. 3 is not enough of an optimization for me to spend my time trying to figure out a batch call when I can just get it done. But that's me. :) Oct 9, 2020 at 17:27
  • 1
    Thanks @GaneshSanap. It means a lot. :)
    – sarbashis
    Oct 10, 2020 at 14:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.