Unexpected Token when trying to load additionalScope variable in OpenAPI Body

  • Goal: Make an OpenAPI resource call with array request body retrieved from additionalScope. Unexpected token error no matter what I try.

  • Steps:

  1. Create a button in my table that makes a post request with an Order ID and a list of urls

Here is the button script:

const content_ids = currentSourceRow.content_items.map(item => item.content_id);

console.log('content_ids:', content_ids);

var resp = await AcceptImages.trigger({
  additionalScope: {
    content_ids_to_approve: content_ids,
    approve_images_order_id: currentSourceRow.order_id
  }
});

return resp;
  1. Create a query AcceptOrder that calls OpenAPI (fastapi) route.

Here, I get Unexpected token error: AcceptImages failed (0.322s):Unexpected token { in JSON at position 1.

I've also tried just putting content_ids_to_approve as well as {{content_ids_to_approve}}. I've also tried using Object.Values and Array.from in the Button script, but still same error.

I've tested by just inputting a raw list in the request and it worked fine:

[
 "url1",
 "url2",
]

I've confirmed the API is just expecting an array of strings:

Any ideas here? Am I correctly using the additionalScope? Am I messing up the formatting somehow? Something different I'm completely missing?

Hi @kodak,

If content_ids_to_approve contains IDs as a string separated by commas, you can simply use {{content_ids_to_approve.str.split(',')}}. If content_ids_to_approve is already an array, just pass {{content_ids_to_approve}}—there's no need to use JSON.stringify.

1 Like

I also recommend checking the debug console for clues as to why it may be failing. You can use the debug console to see the underlying value of {{content_ids_to_approve}}