Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible incorrect metadata returns 400 Bad Request when create new list item #18

Open
heroneto opened this issue Nov 11, 2020 · 0 comments

Comments

@heroneto
Copy link

'__metadata': { 'type': `SP.Data.${listTitle}ListItem` },

Hi,
I'm using this module, and he is amazing, but in my tests i'm getting Response Code 400 when create a new item in list....

After some hours and thousands of Chrome tabs in Stackoverflow, i did not find any reference about possible incorrect _metadata type format.

Then, i test parsing _metadata like this:
body: { "__metadata": { "type": "SP.List" }, "Title": "New Item" },

And error 400 no more occours....

If you wan't to try or put this in your documentation can be very helpfull for income users.

Here's my full code for consultant:

const spClient = sprequest.create({
  username,
  password
})

spClient.requestDigest(url).then(digest => {
  return spClient.post(`${url}/_api/web/lists/getByTitle('nodejsapp')/items	`, {
    body: {
      "__metadata": {
        "type": "SP.List"
      },
      "Title": "New Item"
    },
    headers: {
      'X-RequestDigest': digest
    }  
  })
}).then(function () {
  console.log('item just created!!!');
}, function (err) {
    // if (err.message.indexOf('-2130575342') === -1) {
    //     console.log('Hmmmmm something went wrong');
    //     console.log(err);
    //     return;
    // }
    // console.log('list already exists!!!');
    
})
    .catch(function (err) {
    console.log('Hmmmmm something went wrong');
    console.log(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant