Goal: Do an API call and import json data into retool database.
Problem: When I try to update records it says data needs to be in an array.
I tried to use a javascript to transform the data but not getting anywhere. Importing gives me error 422.
Here's the json results format:
-
{ "messages_ttl": 31536000, "protocol_id": 81, "device_type_id": 300, "id": 1153709, "media_ttl": 31536000, "name": "", "configuration": { "ident": "360123456", "settings_polling": "daily" }, "cid": 596033, "media_rotate": 0, "messages_rotate": 0 }
-
{ "messages_ttl": 31536000, "protocol_id": 81, "device_type_id": 300, "id": 1453389, "media_ttl": 31536000, "name": "GNX Combine", "configuration": { "ident": "47000117", "settings_polling": "daily" }, "cid": 596033, "media_rotate": 0, "messages_rotate": 0 }
Here's the javascript I use to transform data into array:
function convertDataIntoArray() {
const data = Flespi_GetAPI_Data.data.result;
const dataArray = data.map(item => [
item.messages_ttl,
item.protocol_id,
item.device_type_id,
item.id,
item.media_ttl,
item.name,
item.configuration.ident,
item.configuration.settings_polling,
item.cid,
item.media_rotate,
item.messages_rotate
]);
return dataArray;
}
return convertDataIntoArray();
Here's the output:
{"data":[[31536000,81,300,1153709,31536000,"","360123456","daily",596033,0,0],[31536000,81,300,1453389,31536000,"GNX Combine","47000117","daily",596033,0,0],[31536000,250,748,1453513,31536000,"Bench 002B000BC9","002B000BC9",null,596033,0,0],[31536000,24,714,1461525,31536000,"352009110532921","352009110532921","daily",1611453,0,0],[31536000,24,714,1461533,31536000,"355154088036237","355154088036237","daily",1611453,0,0],[7884864,24,712,1579669,31536000,"Jill 358710311365995","358710311365995","daily",879617,0,0],[31536000,250,748,1583093,31536000,"002B000C74 Texas Bench","002B000C74",null,596033,0,0],[31536000,24,714,1595405,31536000,"355154089656488","355154089656488","daily",596033,0,0],
When I run function to bulk upsert primary key I get the following error:
statusCode | 422 |
---|---|
error | Unprocessable Entity |
message | Data must be an array. |
data | null |
isRetoolSystemError | false |
queryExecutionMetadata | {estimatedResponseSizeBytes:124,resourceTimeTakenMs:1,isPreview:false,resourceType:retoolDb,lastReceivedFromResourceAt:1714080381395} |
ANY HELP WITH BE APPRECIATED!