Jump to content

API CreateListing Statuscode : 400


Flame

Recommended Posts

I've been stuck on this for a good bit now and I'm curious as of what I'm doing wrong. I've asked around and a lot of people suggest me to use 'axios' or 'request' to do the request but I'm currently using fetch() (node-fetch) and I feel like it should still work with that.

 

Now I'm attempting to auto create buy & sell listings on BP.TF but I get statuscode of 400 and if I check the JSON message it says: missing 'listings' which I don't get as I'm sending the listings.

 

(Yes I checked that the assetid & key object have the value that they supposed to have)

 

I also checked the Docs on how to POST JSON (https://www.npmjs.com/package/node-fetch#post-with-json)

 

My code:

 

async function doUpdateListing(assetid, key) {
  if (assetid !== undefined && assetid !== null) {
    let listingArray = 
     [
        {
          intent: 1,
          id: assetid,
          offers: 1,
          buyout: 1,
          promoted: 0,
          details: `I'm selling ${key.name} for ${key.sell_metal} ref. Instant accept 24/7`,
          currencies: { metal: key.sell_metal }
        }
        {
          intent: 0,
          item: {
            quality: 2,
            item_name: key.defindex,
            craftable: 1
            // priceindex: ,
          },
          offers: 1,
          buyout: 1,
          promoted: 0,
          details: `I'm buying ${key.name} for ${key.buy_metal} ref. Instant accept 24/7`,
          currencies: { metal: key.buy_metal }
        }
      ]
    ;

    url = `https://backpack.tf/api/classifieds/list/v1?token=${config.bptfToken}`;
    const options = {
      method: 'POST',
      header: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        listings: listingArray
      }),
      redirect: 'follow',
      follow: 20,
      timeout: 0,
      compress: true,
      size: 0
    };

    await fetch(url, options)
      .then(function(response) {
        return response.json();
      })
      .then(function(data) {
        console.log('Update listings on BP.TF');
        console.log(data);
      });
  }
}

 

Link to comment
Share on other sites

Why insist on using fetch instead of other suggested libraries that do work and are, in my opinion, much more easy to understand?

Link to comment
Share on other sites

I don't know. I just started with fetch() and it must be possible to do with fetch. Though I'll probably start another version using axios but I still want to figure this out

 

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...