So what I am trying to do is to make a form using formidable forms to set up a newsletter. The contacts should be sent to sendinblue (the newsletter plugin) that will handle the newsletter. I have followed their official guide found here: https://formidableforms.com/knowledgebase/formidable-api/how-to-add-contacts-in-sendinblue/
The issue I get the form is submitted as it seems on the website when testing as a user. However, nothing happens other than getting an error log. So no contacts are added in sendinblue, and no confirmation email is sent to the user.
The error log in formidable forms states this:
{
"headers":
{
},
"body": "
{
"message": "Unexpected token } in JSON at position 226"}", "response":
{
"code":400,"message": "Bad Request"
},
"cookies":[],"filename":null,"http_response":
{
"data":null,"headers":null,"status":null}}
frm_entry
16
frm_action
14459
frm_code
400
frm_message
Unexpected token } in JSON at position 226
frm_url
https://api.sendinblue.com/v3/contacts/
frm_request
{
"updateEnabled": true, "email": "oskar.hanborg@gmail.com", "emailBlacklisted": false, "smsBlacklisted": false,
"attributes": {
"FIRSTNAME": "Oskar", "LASTNAME": "Hanborg",
},
"listIds": [4,5]
}
frm_headers
Content-type: application/json; charset=UTF-8 api-key: API-key from sendinblue
I looked in my function file on my WordPress server and found that on line 226 (as stated in the log) there is indeed a "}". The problem is I am not a coder, just followed the guide. So to me, it seems the code they provide is not working. However, they won't give support on code as they told me when I sent in a ticket. Since I have never done coding I tried googling to understand this but I just learned basic CSS so this step to troubleshoot code is miles over my head. As a total novice/noob I just guessing out load after trying to understand it, and here are my guesses:
- Maybe it's something with this. But I have no clue how to fix it. I read here: https://bobbyhadz.com/blog/javascript-unexpected-token-u-in-json-at-position-0 It says there that it is an undefined value. If we look at the code in the guide it says
$arg_array[‘headers’][‘api-key’]” But we are only defining the api-key and not the headers – if I understand this (I am a non-coder, just learning by googling this). Can that be fixed by any chance?
Code that I put in my function file for reference (I change where I need to change):
add_filter( 'frm_api_request_args', 'my_custom_frm_api_request_header', 10, 2 );
function my_custom_frm_api_request_header( $arg_array, $args ) {
if ( $args['url'] == 'https://api.sendinblue.com/v3/contacts/' ) { // the full url where the request is being sent
$arg_array['headers']['api-key'] = 'Your-API-Key-Here'; //Replace Your-API-Key-Here with your Sendinblue API key
}
return $arg_array;
}
- In the log it states “Unexpected token } in JSON at position 226”. If I look in my function file at line 226 then its at that bracket in the code above = the one after/under “your-api-key-here”. Any idea if this could have anything to do with this also?
I have been writing to support, but they dont give support on code they say. I have been googleing and trying to understand the concept of unexpected token in WordPress, but it goes over my head. I have followed the official guide that should work - so I have no clue what I am doing wrong.