Response Format
Tradier supports a couple of different response formats. The way you should request a specific format is by using the standard HTTP header Accept.
JSON
JSON is the recommended and default format for the Tradier API. JSON format is lightweight and readable. You should use the following Accept header to get JSON:
'Accept: application/json'
JSON format is supported through XML to JSON translation. Due to this conversion, there is a known issue where responses can change shape depending on the data, specifically for arrays: a field that normally returns a list of items may instead be returned as a single, bare object (rather than a one-element array) when there is only one item to return.
For example, with two items the field looks like this:
{
"orders": {
"order": [
{ "id": 123, "symbol": "AAPL" },
{ "id": 456, "symbol": "MSFT" }
]
}
}
But with only one item, the same field can be returned as a bare object instead of a one-element array:
{
"orders": {
"order": { "id": 123, "symbol": "AAPL" }
}
}
Recommendation: always normalize the value to an array (e.g., wrap a bare object in a single-element array) before iterating over it, rather than assuming the field is always an array.
XML
XML is also supported due to its historical use in the financial space. You can use the following Accept header to get XML:
'Accept: application/xml'
Note: XML format is deprecated in favor of JSON. New integrations should use JSON.
Compression
All APIs support GZip compression if sending the appropriate headers. For example:
Accept-Encoding: gzip
On this page
- Response Format