Getting data from API

I am using an api URL Shortener. How can I access the data from the API. What should I edit on my code?
My code:


var axios = require("axios").default;

var options = {
  method: 'POST',
  url: 'https://url-shortener-service.p.rapidapi.com/shorten',
  headers: {
    'content-type': 'application/x-www-form-urlencoded',
    'x-rapidapi-host': 'url-shortener-service.p.rapidapi.com',
    'x-rapidapi-key': 'b48883481fmsh5673bb460c7c864p19181cjsnc8adea593e65'
  },
  data: {url: 'https://google.com/'}
};

axios.request(options).then(function (response) {
    console.log(response.data);
}).catch(function (error) {
    console.error(error);
});  

URL Shortener
https://rapidapi.com/BigLobster/api/url-shortener-service/

Without taking a look at the api manual, for me it looks like you have a dismiss between content type and data. Content type ist form-url-encoded, while your data looks like JSON.

You should check out which type the api is asking for and change the content type to application/json or change the data to be form data.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.