I have created a proxy route to forward web.get and web.post requests to the Notehub API, so that we can control firmware updates from firmware (say, from provisioning/testing to production firmware.)
The route URL is set to https://api.notefile.net/v1/projects/[project], and the Authorization header set to Bearer <PAT>
I started with this request to fetch a list of firmware:
{"req":"web.get","route":"firmware-api","name":"/firmware"}
Which gives this error:
{
"result": 503,
"body": {
"err": "hub request error: response length (18849) is larger than max (8192) {too-big}"
}
}
I tried using pageNum and pageSize query parameters to cursor through the list, but these don’t seem to be supported for that firmware API.
Next, added "binary”:true :
{"req":"web.get","route":"firmware-api","name":"/firmware", "binary":true}
Which gives this error :
{
"result": 503,
"body": {
"err": "hub request error: json: cannot unmarshal array into Go value of type map[string]interface {}"
}
}
It seems the JSON deserialization doesn’t like the firmware API response format. But I didn’t want Notehub to deserialize the data, so I changed the content type:
{"req":"web.get","route":"firmware-api","name":"/firmware", "binary":true, "content":"application/octet-stream"}
Which surprisingly gives the same unmarshal error.
I tried various other content types, including application/x-binary, application/pdf, image/jpeg, application/x-gzip but all gave the same error.
The route doesn’t have any JSONata at present.
Looking at the event in _web.qo, there’s no mention of the content type.
{
"method": "GET",
"name": "/firmware",
"route": "firmware-api"
}
It’s as if Notehub is always trying to parse the response even when the MIME type override in the request is given. Even if Notehub has to parse the JSON (which I imagine it will when using JSONata), it would be helpful if unsupported formats in JSON were either directly supported, or transformed in some way to make them compatible, or simply not output by your own APIs
For example, the /firmware API returns a response that is an array of objects, with each object carrying firmware details:
[
{ … firmware 1 … },
{ … firmware 2 … },
… etc
]
Perhaps Notehub could transform top level array formats automatically to something like:
{ “array”: [
{ … firmware 1 … },
{ … firmware 2 … },
]}
before JSONata processing begins. Alternatively, perhaps add a parameter to the firmware list API that changes the output format to match that above, with pagination. Just my thoughts, no doubt there are other options too.
Thanks!
