Trade API Error

So, i was experimenting with the various roblox web apis, and came across this error with the endpoint
https://trades.roblox.com/docs#!/Trades/post_v1_trades_send

{
  errors: [
    {
      code: 8,
      message: 'The trade request should include offers.',
      userFacingMessage: 'Something went wrong'
    }
  ]
}

this is my code

-- u is the user object i put into a table, and d is the item itself. all of the uaids are valid
   fetch(`https://trades.roblox.com/v1/trades/send`,{method:"POST",headers: { 'Content-Type': 'application/json',"X-CSRF-TOKEN":token,"cookie": ".ROBLOSECURITY="+process.env.cookie+";",
           tradeRequest:
             {
  "offers": [
    {
      "userId": u.id,
      "userAssetIds": [
        parseInt(d.id)
      ],
      "robux": 0
    },
     {
      "userId": 895445660,
      "userAssetIds": [
       1167613401 
      ],
      "robux": 0
    }
  ]
}

The api’s example value

Docs are found here
How would I fix this?

2 Likes

The body of the POST request does not need a tradeRequest property, the offers property should be directly under the object.

ie.

let headers = { 
    'Content-Type': 'application/json',
    'X-CSRF-TOKEN': token,
    'cookie': `.ROBLOSECURITY=${ process.env.cookie };`
};

let body = {
    'offers': [
        {
            'userId': u.id,
            'userAssetIds': [
                parseInt(d.id)
            ],
            'robux': 0
        },
        {
            'userId': 895445660,
            'userAssetIds': [
                1167613401 
            ],
            'robux': 0
        }
    ]
};

fetch('https://trades.roblox.com/v1/trades/send', { method:"POST", headers, body });

You shouldn’t need to set tradeRequest as the key. This should work fine:

"offers": [
    {
      "userId": u.id,
      "userAssetIds": [
        parseInt(d.id)
      ],
      "robux": 0
    },
     {
      "userId": 895445660,
      "userAssetIds": [
       1167613401 
      ],
      "robux": 0
    }
  ]

Edit: @ReturnedTrue beat me to it

When I formatted that to match my package, it returned the same error

Did you find a solution to this yet?

For anyone curious as to how I fixed this, the body w/ the offers needs to be a stringified JSON. It should NOT be a header, it should be the request payload @Rainzyyy

  fetch(`https://trades.roblox.com/v1/trades/send`,{method:"POST",headers: { 'Content-Type': 'application/json',"X-CSRF-TOKEN":token,"cookie": ".ROBLOSECURITY="+process.env.cookie+";"},
           body:JSON.stringify(
             {
  "offers": [
         {
      "userId": 895445660,
      "userAssetIds": send,
      "robux": 0
    },
    {
      "userId": u.Id,
      "userAssetIds": [
        parseInt(d.id)
      ],
      "robux": 0
    }
  ]
}
           )   
           
           
           
            })
2 Likes

Here is a formatted version of the above:

fetch(`https://trades.roblox.com/v1/trades/send`, {
	method: 'POST',
	headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': token, cookie: '.ROBLOSECURITY=' + process.env.cookie + ';' },
	body: JSON.stringify({
		offers: [
			{
				userId: 895445660,
				userAssetIds: send,
				robux: 0,
			},
			{
				userId: u.Id,
				userAssetIds: [parseInt(d.id)],
				robux: 0,
			},
		],
	}),
});

2 Likes