I have been developing against a REST API for a private vendor, and haven't had issues with it prior. I'm attempting to streamline a workflow prototype in BudiBase, and in BudiBase the API is behaving unlike anything I've seen before, but I am not clear whether it's the API developers or BudiBase that is giving me such a hard time.
When I make a GET request from BudiBase to the endpoints, the JSON response comes back as an empty object:
{}
while the Raw response is something like
{"data1":"60","data2":"STATE","data3":"STATE","data4":"OPTION","data5":"THING","data6":"REPEAT","dataTimer":"0,0","dataSetting":"OFF","dataSetting2":"OFF","dataLow":"-200","dataHigh":"500"}
The schema remains empty, even though there is a Raw response. The Raw response looks identical to the response I get back from Postman for the same request.
Alternately, when I make a request to a different endpoint (same API), I get BudiBase's JSON response formatted with a pre-scribed "value" key, then the resulting value for that key is the expected response, but with all quote marks escaped, like this:
{
"value": "{\"accountInfo\":\"[email protected]\",\"items\":[\"itemid1\",\"itemid2\",\"itemid3\",\"itemid4\"]}"
}
However, BudiBase's Raw response appears as I would expect (same as Postman again), like:
{"accountInfo":"user655321","items":["itemid1", "itemid2", "itemid3", "itemid4"]}
I've gone so far as to copy over the Postman headers to the Budibase request to attempt to align the two requests as closely as possible.
Is this BudiBase's issue or the private API's? Or both? I've never seen anything like this before. I suspect the private API, as free development APIs I've tried to replicate this experience on are identical in content between JSON and Raw responses in the BudiBase view portals.
I would love to be able to divulge more information about the API I am requesting from, but it is private and confidential, so I'm afraid that's not an option.
Does anybody know how I could get to the bottom of the "blame" for this weird behavior? If it's the vendor, I could reach out to them. If their JSON is malformed, it's not something I have reproduced in either Python, Postman, or JavaScript. If it's BudiBase, I could attempt to open a ticket (although the private nature of the API endpoints makes it very difficult to test).
After some deliberation with folks on my team, we realized Postman's response included telling details. The Content-Type
returned was text/plain; charset=utf-8
which isn't the application/json
type BudiBase (and most users, I bet) expect. Postman does a good job of managing the response into something useable, while BudiBase attempts to wrap the response in valid JSON, putting the entire response body into the "value"
parameter's value.
So, to accommodate the API's poor documentation and improper response type, I wrote a BudiBase Transformer for each of those API's requests, like so:
// gotta do this because <vendor> returns a string instead of valid JSON
const response = data;
const cleanedResponseText = data.trim();
const jsonData = JSON.parse(cleanedResponseText);
return jsonData;