REST API - Change Body Field Name

Hi Everyone, I'm building POST requests for a trading API and it works perfectly with the GET requests but I'm having an issue with the POST body field. The brokerage API is expecting the body data in a field named "form" but the REST API doesn't seem to let me change the default "body" name or add an additional field. Would love to hear how you guys would go about that issue. Thanks guys!

code example:

// Version 10.15.2    
const request = require('request');

request({
    method: 'post',
    url: 'https://api.tradier.com/v1/accounts/{account_id}/orders',
    form: {
       'class': 'equity',
       'symbol': 'SPY',
       'side': 'buy',
       'quantity': '10',
       'type': 'market',
       'duration': 'day',
       'price': '1.00',
       'stop': '1.00',
       'tag': 'my-tag-example-1'
    },
    headers: {
      'Authorization': 'Bearer <TOKEN>',
      'Accept': 'application/json'
    }
  }, (error, response, body) => {
      console.log(response.statusCode);
      console.log(body);
  });

Hello @DisionDVSN,
Please could you share a screenshot of how you implemented the POST request in retool

Hi @ugo.ago, sure thing, here is the logic:

(I removed the body data in the screengrab to keep it clean)

However I tried, with forms, raw or JSON or with additionalScope the API is not reading the form field data from the request probably as it remains inside the body field.

This is the response:

Feels like if the body field was labeled form it would work in this case, bu I don't seem to find a way around it.

Thanks!!
Ben

This is a version where I tried to include the form field but stays contained in the body:

@DisionDVSN
Have you tried adding the information for the form in the key/value fields under Form Data like the following except where I have textInput1.value, you would put the name of whatever array/object value there instead and whether it is Text or a File type...


And so on....

Hi @ScottR, thanks for your reply. I did try the form and I'm getting strange results with it and dind't get the data in the field, I didn't really dig since the data was still in the bod instead of form but I couldn't get it to work either. Here is a grab:

Thanks for your help guys, much appreciated! I feel like it's a simple thing I'm missing

I don't see an error... so what's missing...if you could post sample data/code, etc.; it may help the forum get to a solution faster for you....

The data entered is not in the body field in this case, not sure why I'm getting random data, but I would need the filed to be a form field like in this sample code for the request to work:

Thanks for the help!

Request Sample:

// Version 10.15.2    
const request = require('request');

request({
    method: 'post',
    url: 'https://api.tradier.com/v1/accounts/{account_id}/orders',
    form: {
       'class': 'equity',
       'symbol': 'SPY',
       'side': 'buy',
       'quantity': '10',
       'type': 'market',
       'duration': 'day',
       'price': '1.00',
       'stop': '1.00',
       'tag': 'my-tag-example-1'
    },
    headers: {
      'Authorization': 'Bearer <TOKEN>',
      'Accept': 'application/json'
    }
  }, (error, response, body) => {
      console.log(response.statusCode);
      console.log(body);
  });

Here is the request sent from REST API: (Not sure what those values are tho but it's not the data I entered for some reasons)

{
  "request": {
    "url": "https://sandbox.tradier.com/v1/accounts/#######/orders",
    "method": "POST",
    "body": {
      "_overheadLength": 938,
      "_valueLength": 35,
      "_valuesToMeasure": [],
      "writable": false,
      "readable": true,
      "dataSize": 0,
      "maxDataSize": 2097152,
      "pauseStreams": true,
      "_released": true,
      "_streams": [],
      "_currentStream": null,
      "_insideLoop": false,
      "_pendingNext": false,
      "_boundary": "--------------------------014396872357082173810777",
      "_events": {},
      "_eventsCount": 1
    }

I am sorry @DisionDVSN but without me having direct access to the app or the API, I am stumped - the API may require


instead... but I don't know....
Perhaps someone on the Retool side can step into your app and see/dig further

1 Like

Hey @ScottR , I'm going to keep trying different options and see if I can identify the issue but I really appreciate you taking some time to try to figure it out! Hopefully someone from Retool can jump in!

Thanks again

Hey @ScottR url enclosure seemed to have done the trick thanks a lot!

You're welcome - glad it's solved

1 Like