Repeaters and API woes

By: Andrew Christensen | Asked: 10/23/2023
ForumsCategory: Code HelpRepeaters and API woes
Andrew Christensen asked 9 months ago
We are trying post some data to the API. It was working fine until we added some repeaters.
This is the error:
Error sending event to GCMD Site:
Client error: `POST https://my.wordpress.site/wp-json/frm/v2/entries/119` resulted in a `409 Conflict` response:
{"code":"frmapi_validate_entry","message":{"form":"There was a problem with your submission. Please try again."},"data": (truncated...)

Here's the content it's attempting to send:
{"form_id":2,"6":"DEMO ","22":"No","23":"Yes","21":"2022-01-18","26":"#sign-up","25":"conference-demo","9":"
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu.
","13":"Monday, January 17th, 2022","65":"
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu.rn
rn
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu.rn
","38":"This is the tagline.","16":"2022-01-17","17":"2022-01-17","14":"9:00AM - 4:00PM America/Los_Angeles","15":"Free","39":"https://my.domain/app/default/assets/images/laravel_streams_black_line_logomark.png?v=1698110827","40":"#instagram","41":"#twitter","speakers": { [foreach 42] "[id]":{ "45": "Ryan","46": "Ronin","66": "Sir","48": "
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu.
","49": "https://my.domain/app/default/assets/innovators/me2.jpeg?v=1698110827" },"[id]":{ "45": "Ryan","46": "Thompson","66": "Bruh","48": "
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu.
","49": "https://my.domain/app/default/assets/innovators/me2.jpeg?v=1698110828" } [/foreach 42] },"image_gallery": { [foreach 54] "[id]":{ "56": "https://my.domain/app/default/assets/images/doctor-preparing-covid-19-vaccine.jpg?v=1698110828" },"[id]":{ "56": "https://my.domain/app/default/assets/images/harlie-raethel-ouyjDk-KdfY-unsplash.jpg?v=1698110828" },"[id]":{ "56": "https://my.domain/app/default/assets/images/hero-group.jpg?v=1698110828" },"[id]":{ "56": "https://my.domain/app/default/assets/images/brain-study-background-mental-health-care-medical-technology.jpg?v=1698110828" },"[id]":{ "56": "https://my.domain/app/default/assets/images/pexels-anna-shvets-4226256.jpg?v=1698110828" } [/foreach 54] },"sponsors": { [foreach 50] "[id]":{ "52": "#1","53": "https://my.domain/app/default/assets/resources/Untitled-1.jpg?v=1698110828" },"[id]":{ "52": "#2","53": "https://my.domain/app/default/assets/resources/Untitled-2.jpg?v=1698110828" },"[id]":{ "52": "#3","53": "https://my.domain/app/default/assets/resources/Untitled-3.jpg?v=1698110828" },"[id]":{ "52": "#4","53": "https://my.domain/app/default/assets/resources/Untitled-4.jpg?v=1698110828" } [/foreach 50] },"downloads": { [foreach 57] "[id]":{ "59": "dummy.pdf","60": "https://my.domain/file/download/dummy.pdf" },"[id]":{ "59": "dummy.pdf","60": "https://my.domain/file/download/dummy.pdf" } [/foreach 57] },"links": { [foreach 61] "[id]":{ "63": "Google","64": "https://google.com" } [/foreach 61] }}

Can you tell me what's wrong with the content we are posting? I followed the API docs to add in the repeater data. I assume something is wrong there, but I don't know what. We are on the latest version of Formidable.
Question Tags:
Andrew Christensen replied 9 months ago

The problem I think is the completely invalid json format that formidable says to use with the [foreach xx] ... [/foreach xx] code in the json data.

I added Content-Type: application/json and Accept: application/json to my headers and now entries post properly but only when they DO NOT have any of the repeater field data. If there's repeater field data I get:

Bad Request` response:
{"code":"rest_invalid_json","message":"Invalid JSON body passed.","data":{"status":400,"json_error_code":4,"json_error_m (truncated...)

The formidable api docs say to send data as RAW but that's what I was trying to do and every single call failed with the 409 error even without any repeater data.

2 Answers
Andrew Christensen answered 9 months ago
Well I got the errors to go away but it's still not filling in the repeaters.

I found in the docs to change things a bit so the json now looks more like this:
{"form_id":2,
"6":"Town Hall ",
"22":"Yes",
"23":"Yes",
"21":"1969-12-31",
"26":null,
"25":"cchmc-town-hall",
"9":"<p>Town Hall #9<\/p>",
"13":"Friday, January 14th, 2022",
"65":null,
"38":"Join the conversation ",
"16":"2022-01-14",
"17":"2022-01-14",
"14":"8:00AM - 9:00AM America\/Los_Angeles",
"15":null,
"39":"",
"40":null,
"41":null,
"ctlgo": {
"form": 5,
"0":{
"45": "Jeffery",
"46": "Anderson",
"66": "MD, MPH, MBA",
"48": "<p>-</p>",
"49": "https://my.domain/app/default/assets/images/Screen Shot 2022-01-11 at 12.59.57 PM.png?v=1698118224"
},
"0":{
"45": "Shelly",
"46": "Voet",
"66": "MD",
"48": "<p>&nbsp; -</p>",
"49": "https://my.domain/app/default/assets/images/Shelly Voet MD.jpg?v=1698118224"
}
},
"keo9d": {
"form": 7,
"0":{
"56": "https://my.domain/app/default/assets/images/screen_shot_2022-01-11_at_12.22.33_pm.jpg?v=1698118224"
}
}
}
I get a successful post, but the repeaters have no data in them in Formidable.
Victor Font answered 9 months ago
This is extremely difficult to follow without understanding the design of your system. Formidable's instructions for populating repeaters is correct and I don't see where you're following this mandate: "Note:The [id] in the data is meant to stay as [id]. It is a shortcode that autofills with the ID of the entry that is being submitted. Don't remove this or change its value."
Andrew Christensen replied 9 months ago

Thanks Victor. If you look at the first post the example code I'm attempting to send DOES have "[id]". it also has the [foreach xx] ... [/foreach xx] code in it. But if I attempt to send this as raw with no json headers I get the 409 error. If I have the json headers with this raw data I get the 400 error that the json is invalid.

Bear in mind I am NOT sending FROM formidable to another formidable form. I am attempting to send data from a Laravel site using Guzzle (curl) to populate this form with repeaters in it. So if the shortcodes are intended to be dynamically replaced when the data is SENT to formidable and not being read in and applied on receipt then I need to know the format for the data that Formidable will receive it. Should it be receiving valid json?

Victor Font replied 9 months ago

If you're not sending from Formidable, the shortcodes are never going to work, but you already know that. You wouldn't even be able to test this in Postman, which is usually the first step in formatting RAW JSON.

I would set up a development instance of Formidable with a duplicate of the intake form and same data to output the RAW JSON in the format it expects, then use it as a model for constructing the RAW JSON from Laravel/Guzzle. You can review the Formidable generated REQUEST either in your browser's development tools or by using the Logging add-on.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right