REST query is turning additionalScope property object into "[object Object]"

I have a rest query in query the query library. I am calling it from JS like this:

const scope = {
  jobName: txtSTName.value,
  writer: writer, // try passing with object
  parsingFormat, // try passing ES6 style
  additionalWriters, 
  dateTime: tblJobs.selectedRow.data.job_date + ' ' + tblJobs.selectedRow.data.start_time,
  timeZone: "{ name: tz,  value: " + tblJobs.selectedRow.data.time_zone + "}" // try passing as string
}
let event = await restSTAddEvent.trigger({additionalScope: scope})

But this is what is what I am seeing in the console:

You can see the additionalScope looks correct. But the body propertyies that are themselves objects are getting converted to "[object Object]".

My query is pretty straighforward:

I tried parsing the string in my query:

image

But then the writer property just become a string "null":

image

Now I'm stumped, how do I pass an object as a JSON body property?

Hey Bradley! Is there a reason you're not parsing writer.data? What is writer - a component or something else?

Jonathan

writer is simply a name/value pair {name: 'Karla', value: "email'} (see additionalScope in my screenshot of the console)

I did try parsing it (see last two screenshots), but it returns a null string. Maybe I am doing that wrong or in the wrong place?

Can you try and hover {{writer}} and show what you see there?

@jonathanbredo, thanks for being additional eyes on this!

I can't hover {{writer}} in the query since it is not defined until the query runs.

But I'll do you one better.

Here is my code (stripped of unneeded filler):

let additionalWriters = []
let writer = {name: qryContractorsForST.data[i].name,  value:qryContractorsForST.data[i].st_username}
let parsingFormat = {name: st_parsingFormats().find(el=>el.value===qryContractorsForST.data[i].st_parse_format_value).name,  value:qryContractorsForST.data[i].st_parse_format_value}

const scope = {
  jobName: txtSTName.value,
  writer: writer,
  parsingFormat,
  additionalWriters, 
  dateTime: tblJobs.selectedRow.data.job_date + ' ' + tblJobs.selectedRow.data.start_time,
  timeZone: "{ name: tz,  value: " + tblJobs.selectedRow.data.time_zone + "}"
}

console.log(scope)

let event = await restSTAddEvent.trigger({additionalScope: scope})
if (event?.status != 'Scheduled') {
  utils.showNotification({title: 'Error',description: JSON.stringify(restSTAddEvent.data), notificationType:"error"})
  return
}

Here is the json I am passing in additonalScope from that console.log():

{
    "jobName": "1589630b",
    "writer": {
        "name": "Karla Ray",
        "value": "karlaray@****.com"
    },
    "parsingFormat": {
        "name": "Use writer's default/None",
        "value": ""
    },
    "additionalWriters": [],
    "dateTime": "2023-01-12 10:30:00",
    "timeZone": "{ name: tz,  value: America/New_York}"
}

Yeah, I'm lost here... Best recommendation from me is to go over it with a Retool engineer over one of the office hours :sweat_smile:

1 Like

Update! Brad did indeed make it to office hours this morning :slight_smile:

Seems like using a Raw body should support different data types (not just strings). Waiting to see exactly what body format the API endpoint is expecting!

1 Like

I was unable to get it working at all. Retool doesn't like JSON objects when using a JSON body type and the API end point won't accept any Raw input configurations I can think to try.

So I fired up an Azure Function to act as an intermediary and that is working.

1 Like

Thanks for the update both!

Hello, I meet the same error. I post it here. [BUG] transport Object/Array from trigger additionalScope to query, the object/array will resolve to [object Object]