Good morning, I have a problem with the result returned through the API.
I created a simple form and followed the instructions to perform a query using the following syntax:
curl --user "xxxx-xxxx-xxxx-xxxx:x" https://dominio001www.app1955n05m001.com/wp-json/frm/v2/entries
Following the instructions found at the following link
https://strategy11.github.io/formidable-forms-rest-api-docs/?shell#get-all-entries
If I understood correctly, the obtained result in JSON format should have the following structure:
{ "id": 1, "name": "Fluffums", "breed": "calico", "fluffiness": 6, "cuteness": 7 }, { "id": 2, "name": "Max", "breed": "unknown", "fluffiness": 5, "cuteness": 10 }
Obviously, they provided a demonstration example, maybe copied from this link:
https://mermade.github.io/reslate/#get-a-specific-kitten
Also because I see it's about cats 😊
Anyway, I'm getting this result instead:
{ "nog2v": { "id": "15", "item_key": "nog2v", "name": "prova tecnica 01", "ip": "10.0.1.251", "meta": { "ybucj": "prova tecnica 01" }, "form_id": "4", "post_id": "0", "user_id": "0", "parent_item_id": "0", "is_draft": "0", "updated_by": "0", "created_at": "2023-05-26 20:38:17", "updated_at": "2023-05-26 20:38:17" }, "9jl2r": { "id": "16", "item_key": "9jl2r", "name": "prova tecnica 02", "ip": "10.0.1.251", "meta": { "ybucj": "prova tecnica 02" }, "form_id": "4", "post_id": "0", "user_id": "0", "parent_item_id": "0", "is_draft": "0", "updated_by": "0", "created_at": "2023-05-26 21:46:04", "updated_at": "2023-05-26 21:46:04" } }
The problem is that the structure is different because the first node consists of a random value.
The keys of the first two nodes, namely "nog2v" and "9jl2r," are randomly generated, and this prevents me from parsing the JSON file.
I created some "satanic" code to retrieve all the values of "item_key" through text search, and this allows me to replace the static values with predefined values, for example, 00001, so that I can have a static path like 00001 -> meta -> 00001 = prova tecnica 01.
I can use functions to perform parsing even if the keys are dynamic, but the problem is that I need to execute this automation within Power Automate, and the scripts inside it don't work.
For example, scripts like this:
const data = JSON.parse(jsonData); for (const key in data) { if (data.hasOwnProperty(key)) { const value = data[key]; const itemKey = value.item_key; const name = value.name; // Extract other desired information here console.log(Item Key: ${itemKey}, Name: ${name}
); } }
They don't work inside Power Automate.
Did I make any mistakes? Does anyone have a simpler solution? Thank you in advance.
Please login or Register to submit your answer
Until you mentioned Power Automate, I was wondering why you were using curl instead of a WordPress HTTP_REQUEST, but that's beside the point. We can't help you with Power Automate. This forum is Formidable only.
As far as the key. The first key is the entry key. Yes. these are generated randomly and there's nothing that can be done about it. The first key "nog2v" is the entry ID of the header record from the frm_items table. The content following "meta" are the actual form field values from the frm_item_metas table.
When you use Formidable's API to move data between WordPress sites, Formidable handles all the formatting and parsing. Because you are using a third party tool from Microsoft that isn't designed with WordPress or the Formidable API in mind, you may be better off creating your own REST endpoint so you can format the data the way you want it before sending the JSON response. It's a lot of work, but it's a one time activity.
@Victor Font , Formidable Form entries would be easier to work with in multiple ETL platforms if the /wp-json/frm/v2/forms/#/entries/ JSON was formatted as an array of JSON objects. Here's how I had to transform the current output before I could loop through each form entry in Power Automate:
[
{
"id": "2",
"item_key": "5ic0r",
"name": "Form Response 1",
"meta": {
"my_field_1": "Formidable JSON",
"my_field_2": "could be easier"
},
"form_id": "4",
"post_id": "0",
"user_id": "14",
"parent_item_id": "0",
"is_draft": "0",
"updated_by": "14",
"created_at": "2023-10-24 04:05:54",
"updated_at": "2023-11-14 02:48:40"
},
{
"id": "4",
"item_key": "kdq9c",
"name": "Form Response 2",
"meta": {
"my_field_1": "Formidable JSON",
"my_field_2": "is hard in Power Automate"
},
"form_id": "4",
"post_id": "0",
"user_id": "14",
"parent_item_id": "0",
"is_draft": "0",
"updated_by": "14",
"created_at": "2023-10-24 21:49:40",
"updated_at": "2023-10-24 21:49:40"
}
]