Home > Mobile >  Reading the API documentation
Reading the API documentation

Time:09-25

I am trying to recreate this create a new card API, but based on docs, I'm not sure how should I pass the data required, should it be inside the query parameters (req.params to collect the data), for example /1/cards?name=cardName&desc=cardDescription, or should it be inside the req.body?

CodePudding user response:

The doc shows plenty of examples for that API. One of the examples is even written for nodejs. It looks pretty clear that the options are query parameters and there is no body data in the request itself.

// This code sample uses the 'node-fetch' library:
// https://www.npmjs.com/package/node-fetch
const fetch = require('node-fetch');

fetch('https://api.trello.com/1/cards?idList=5abbe4b7ddc1b351ef961414', {
  method: 'POST',
  headers: {
    'Accept': 'application/json'
  }
})
  .then(response => {
    console.log(
      `Response: ${response.status} ${response.statusText}`
    );
    return response.text();
  })
  .then(text => console.log(text))
  .catch(err => console.error(err));

Similarly, the CURL example also makes this fairly clear:

curl --request POST \
  --url 'https://api.trello.com/1/cards?idList=5abbe4b7ddc1b351ef961414' \
  --header 'Accept: application/json'
  • Related