API resource access to POST body


I have a POST query where Im sending a json body. Im attaching an on failure handler to the query for when it times out (which by the way is not being captured) I can do some logging.
On the failure handler Im trying to access the body of the request ({request}.body[0].value) but noticing its not well parsed, the value is stored as literal string "[object Object]".
Here is a screenshot of the resource and its body.

{{ formatDataAsArray(generate_print.body[0].value) }}

Hi @ScottR, thanks for your reply.
That wont do the job since the body is coming back as a string, applying formatDataAsArray would just split the words of the string on to an array.

        "0": "[",
        "1": "o",
        "2": "b",
        "3": "j",
        "4": "e",
        "5": "c",
        "6": "t",
        "7": " ",
        "8": "O",
        "9": "b",
        "10": "j",
        "11": "e",
        "12": "c",
        "13": "t",
        "14": "]"

Is there a config I need to provide to the query being sent or somewhere else so that the body comes back the way it was sent? (as json object)

What is the actual value of generate_print.body[0].value no [ or ] surrounding it?

The value of generate_print.body[0].value is literal string "[object Object]" as you can see on first screenshot on state pane

:thinking: would you mind checking the value of generate_print.rawData.data?

@Kabirdas thanks that did work, without the last .data (generate_print.rawData).
Wondering if you could also guide me in this follow up question as well.
API queries on advance settings have a timeout prop. However if a request last longer than specified timeout prop, exception is raised and does not trigger failure handler. How can I recover from a timeout exception?

That's odd! Would you mind posting a screenshot of your failure handler as well as the exception you're seeing? It might also help to get screenshots of the rest of your query settings if you don't mind!

Hi @Kabirdas, seems to be capturing correctly the failure handler now :thinking:.
However now the generate_print.rawData on the failure handler comes as null, as opposed to the success handler. Any other prop I can use to recover sent body on the API request?
Attached is a screenshot of a dummy on failure callback where Im trying to log body sent on a POST request (same as top example)

:thinking: I'm not seeing another property when you'd be able to access the body of your query, you can browse all of its properties in the state tab of your debug console:

How are you triggering the generate_print query? I'm curious if you can reference table1.data[i] in a different way when the query fails but how to know what i is would depend on how the query is triggered.

I browsed the state props but have not found any that would have the data I need, just body that have string value and rawData which is null.
generate_print is being triggered inside a foreach, one per row in the table, sending with it the i variable representing the actual row.

I think this should be open as a bug ticket? the body value should come json parsed, or if it need to be a string, the json stringified. But right now its a string out of a bad parsed value ("[object Object]")

Yep! We have an open bug ticket for more accurately displaying objects in the query body property and I've added your case to it. We can report back here when there's a fix :slightly_smiling_face:

In the meantime, can you try adding your JS queries as success handlers in the same scope where you're triggering the query itself?

table1.data.forEach((row, i) => {
    additionalScope: { ... },
    onSuccess: (result) =>
        additionalScope: { result, i, contractId, tokenId },
    onFailure: (result) =>
        additionalScope: { result, i, contractId, tokenId },

I know it's not ideal but given you can pass anything from the scope there you may be able to get the error handling you're looking for.

Hey @Kabirdas awesome.
Thanks for the alternative, thats great since as you said, I can provide all data with the additionalScope. It is working fine for the onFailure handler.. But
onSuccess handler never gets called. I did a new dummy repo to test this out

Screen Shot 2022-12-21 at 19.36.50

dummy_button_handler gets called on a button click, it then trigger dummy_button_trigger which just does a console.log and then dummy_button_sucess should get called, but its not (it just a console.log)

@nico.io oh I spelled success wrong :flushed: does renaming the property onSuccess work? I've edited the above post as well!

Oh sorry, completely missed that typo. Yea, thats working now.
I just assumed right since there was no prop validation.
@Kabirdas thanks for the support.