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:
$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;
}
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.
After some more digging and help I changed the url used in the function file to this: if ( $args['url'] == 'https://api.sendinblue.com/v3/contacts' )
The only difference is the last slash ("/") is removed. This changes the error log to be directed to the API key not being correct - if I understand it. However I created a new API V3 key and did as last time: copied it directly to a text file -> then over to the code. Sendinblue support dont seem to know why this happens. Anybody has a guess? Anything more I can test that I perhaps is doing wrong?
The new error log says this:
Response
{
"headers":
{
},
"body": "
{
"message": "Key not found", "code": "unauthorized"}n", "response":
{
"code":401,"message": "Unauthorized"
},
"cookies":[],"filename":null,"http_response":
{
"data":null,"headers":null,"status":null}}
frm_entry
32
frm_action
14459
frm_code
401
frm_message
Key not found unauthorized
frm_url
https://api.sendinblue.com/v3/contacts/
frm_request
{
"updateEnabled": true, "email": "oskar.hanborg@gmail.com", "emailBlacklisted": false, "smsBlacklisted": false,
"attributes": {
"FIRSTNAME": "Per", "LASTNAME": "Treborn",
},
"listIds": [4,5] }
frm_headers
Content-type: application/json; charset=UTF-8