profile
viewpoint

Ask questionsNode.js Axios HTTP request with bearer token returning undefined

Hello,

I'm a little new to Node.js, so I hope this question isn't too basic. I'm working with Node.js/Axios, and trying to get basic communication going with the Tiltify API. Here's my code so far:

const axios = require('axios');

axios.get('URL_GOES_HERE', {
  headers: {
    'Authorization' : 'Bearer MY_TILTIFY_ACCESS_TOKEN'
  }
})
  .then(response => {
    console.log(response.data.url);
    console.log(response.data.explanation);
  })
  .catch(error => {
    console.log(error);
  });

I assume that MY_TILTIFY_ACCESS_TOKEN is the access token I generated from within my Tiltify account. I'm confused, however, about what value to put in URL_GOES_HERE. The API docs give two possible URLS: https://tiltify.com/oauth/authorize and https://tiltify.com/oauth/token. Or am I supposed to put my bearer credentials directly into the URL of a useful request, like https://tiltify.com/api/v3/user? I've tried all three, and I just get undefined undefined in the console.

Thanks for taking a look!

Tiltify/api

Answer questions benstepp

url / explanation aren't part of the axios response schema

const axios = require('axios');

axios.get('https://tiltify.com/api/v3/campaigns/65218/donations', {
  headers: {
    'Authorization' : 'Bearer MY_ACCESS_TOKEN'
  }
})
  .then(response => { // this is an axios response object (https://github.com/axios/axios#response-schema)
    console.log(response.data); // this is the response body from tiltify (https://tiltify.github.io/api/endpoints/campaigns-id-donations.html)
    console.log(response.data.data); // this is the .data property of our responses

    response.data.data.map((donation) => {
      // the name/amount of the recent donations
      console.log(`${donation.name} - ${donation.amount}`)
    })
  })
  .catch(error => {
    console.log(error);
  });
useful!

Related questions

No questions were found.
source:https://uonfu.com/
Github User Rank List