Jump to content

token is invalid when attempting to heartbeat bp.tf api


Flame

Recommended Posts

So I'm using the backpack.tf api for the first time and I'm attempting to heartbeat backpack.tf with my bot account and I'm using the following code for it: 

 

JAVASCRIPT (NODE.JS)

 

function sendHeartbeat(callback) {
  if (
    config.bptfToken === '' ||
    config.bptfToken === undefined ||
    config.bptfToken === null
  ) {
    callback(new Error('No BP.TF token set.'));
    return;
  }

  const url = 'https://backpack.tf/api/aux/heartbeat/v1';
  const options = {
    method: 'POST',
    cache: 'no-cache',
    credentials: config.bptfToken,
    header: {
      'Content-Type': 'application/json'
    }
  };
  fetch(url, options)
    .then(function(response) {
      return response.json();
    })
    .then(function(data) {
      console.log(data);
    });
}

Now the problem is when using my backpack.tf userToken as credentials I get as reply 'access token is invalid'. I have also attempted to use my apiKey as token yet same result. Am I doing something wrong? Like is my fetch() the problem? Or is there another kind of key I need?

 

Thanks in advance

Link to comment
Share on other sites

Based on the documentation (https://backpack.tf/api/index.html#/user-token-auxiliary/App\Controllers\API\UserToken\Auxiliary::heartbeat) this looks to be deprecated.

 

I would recommend maybe just trying a GET on the /users/info/v1 endpoint with your own SteamId and seeing if you can get a response that way https://backpack.tf/api/index.html#/user-token-users/App\Controllers\API\UserToken\Users::info

 

I believe an example URL (for 2 ids) would be: https://backpack.tf/api/users/info/v1?steamids=76561198012598620%2C76561198070299574&key=YOURKEY

 

Link to comment
Share on other sites

Endpoint is not depricated, just not documented since oauth arrived. Which is getting removed on March 31st and will hopefully bring back some old docs.

 

I wasn't able to make it work with node-fetch. Not sure whats up with that.

I would instead recommend axios

const axios = require('axios');

function sendHeartbeat(callback) {
  if (!config.bptfToken) {
    callback(new Error('No BP.TF token set.'));
    return;
  }

  const options = {
    url: 'https://backpack.tf/api/aux/heartbeat/v1',
    method: 'POST',
    data: {
      token: config.bptfToken,
      automatic: 'all'
    },
    json: true
  }

  axios(options)
    .then((response) => {
      callback(null, response.data);
    })
    .catch((err) => {
      callback(err);
    });
}

sendHeartbeat(function(err, data) {
  if (err) {
    console.log(err);
    return;
  }

  console.log(data);
})

 

Link to comment
Share on other sites

4 hours ago, Zeus_Junior said:

Endpoint is not depricated, just not documented since oauth arrived. Which is getting removed on March 31st and will hopefully bring back some old docs.

 

I wasn't able to make it work with node-fetch. Not sure whats up with that.

I would instead recommend axios

 

Curious why it's marked as deprecated in the documentation? Maybe I'm missing something but I see a few marked as deprecated there and that's one of them.

Link to comment
Share on other sites

I made the heartbeat thing work with fetch() afterall for some reason passing it as querystring (so at end of url) it does work

Link to comment
Share on other sites

7 hours ago, Sniper Noob said:

 

Curious why it's marked as deprecated in the documentation? Maybe I'm missing something but I see a few marked as deprecated there and that's one of them.

No idea

Link to comment
Share on other sites

  • Flame locked this topic

Archived

This topic is now archived and is closed to further replies.

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...