{
"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": "[email protected]", "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 wont give support on code as they told me when I sent in a ticket. Since I have never done coding I tried googleing to understand this but I just learned basic css so this step to troubleshoot code is miles over 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 googleing 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;
}
You are not creating headers. You are adding the API key to the array element that is used to create the request header further along in the process. If your code is using curly quotes as you are in the example you provided above, it will break the request header. This is your example: $arg_array[‘headers’][‘api-key’], the correct code is: $arg_array['headers']['api-key']. See the difference with the straight quotes? It's corrct in the function block but not when you explain.
You are sending raw JSON as the request. JSON needs to be precise. If you have one misplaced bracket or comma, your code won't work. While the log is helpful, it doesn't show the actual API request or response.
The error message is saying the error is in the form URL. Are you using the correct URL as defined by SendInBlue? APIs often continue to evolve after example code has been written. The example code provided by the Formidable Developers is usually a good starting point, but you have to verify everything with the SendInBlue API documents.
When testing an API, it's a good idea to use Postman until you get a correct response returned from the API. Once the API is working with Postman, then you transfer the raw JSON to Formidable's API add-on and add the field shortcodes. Have you done that?
You have to make sure the data you send matches the the format expected by the sendinblue API. Are you including the country code with the phone number? See this: https://developers.sendinblue.com/reference/createcontact
I would also remove the comments from the raw JSON. Comments aren't always processed by an API and will cause errors. Remove all lines that start with //. Once you have clean JSON with all data elements formatted as the receiving API expects, you should get some kind of response returned from the API.
If you need help from a developer, I suggest you search the Formidable Masterminds Developers Directory. Expect to pay for 4-6 hours of a developers time.
<p>Victor I am almost crying of thankfulness. Your answer made me relook and I found the url from sendinblue documents. It was a / extra in the end in the code I wrote. However now I have a new type of error in the log (so its moving forward). You understood the problem with the first error log (wrong url in the code, was an / extra), can you point me in the right direction on this one also? 🙏 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 23 frm_action 14459 frm_code 401 frm_message Key not found unauthorized frm_url <a href="https://api.sendinblue.com/v3/contacts/" rel="nofollow">https://api.sendinblue.com/v3/contacts/</a> frm_request { "updateEnabled": true, "email": "[email protected]", "emailBlacklisted": false, "smsBlacklisted": false, "attributes": { "FIRSTNAME": "Oskar", "LASTNAME": "Hanborg", }, "listIds": } frm_headers Content-type: application/json; charset=UTF-8</p>
This is the error: "Key not found". You're not sending a correct API key. Did you create one in sendinblue? Make sure it's correct.
As I suspected. Yes I made one in sendinblue - copied it to a textfile to save it - then in to the code. I have a ticket at sendinblue regarding this and I included the help you gave here. I dont know whats wrong with the API key provided. I even made a new one today to test a second one - still the same problem 🤷♂️
But then hopefully they can arrange a correct API-key and this should be sorted. I will update this thread with what the response from sendinblue 🙂👍
Many thanks for your time and help. It made all the difference 🙏
I read here they changed import of contacts. https://developers.sendinblue.com/changelog/contact-import-endpoint-now-supports-json-body
Could this somehow be linked to what I am trying to do (creating new contacts)?
The problem I had was that the domain was not verified in sendinblue. Also I had not removed the "," in the raw code after removing on attribute I do not use (the sms number). Now it works 🙂👍
To clarify, the code that says ""FIRSTNAME": "Oskar", "LASTNAME": "Hanborg"," should be ""FIRSTNAME": "Oskar", "LASTNAME": "Hanborg"". Its just the end thats different without a ",".
That's JSON! JSON format is strict about commas and where they are used. Always run JSON code through JSONLint. It saves heartache.
A funny detail when I look at their website: "Common Errors
Expecting 'STRING' - You probably have an extra comma at the end of your collection. Something like { "a": "b", }" 😅👍
Many thanks Victor 🙏
Please login or Register to submit your answer