Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SendInBlue create contact error #9

Closed
pirmax opened this issue Sep 10, 2017 · 12 comments
Closed

SendInBlue create contact error #9

pirmax opened this issue Sep 10, 2017 · 12 comments

Comments

@pirmax
Copy link

pirmax commented Sep 10, 2017

I'm working in local to test SendInBlue create contact.

Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', env('SENDINBLUE_API_KEY'));

$api_instance = new Swagger\Client\Api\ContactsApi();
$createContact = new Swagger\Client\Model\CreateContact();

$createContact['email'] = 'email@gmail.com';
$createContact['listIds'] = 2;

$result = $api_instance->createContact($createContact);

dd($result);

I have this error...

[400] Error connecting to the API (https://api.sendinblue.com/v3/contacts)

@ekta-slit
Copy link
Collaborator

ekta-slit commented Sep 12, 2017

Hello @pirmax

FYI please update the library as we have done some minor fixes.
After that for create contact API I suggest you to use below sample code:

Sendinblue\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', env('SENDINBLUE_API_KEY'));

$api_instance = new Sendinblue\Client\Api\ContactsApi();
$create_contact = new \Sendinblue\Client\Model\CreateContact();

$create_contact['email'] = 'email@gmail.com';
$create_contact['listIds'] = array(2);

try {
    $result = $api_instance->createContact($create_contact);
    print_r($result);
} catch (Exception $e) {
    print_r($e);
    echo 'Exception when calling ContactsApi->createContact: ', $e->getMessage(), PHP_EOL;
}

Where print_r($e); will give you complete ApiException Object
Thanks

@bjornbos
Copy link

What about custom attributes? When I add

$create_contact['attributes'] = array('some_attribute' => 'some value')

I get the 400 error again.

@bjornbos
Copy link

I've also tried to wrap it as a json object:

$create_contact['attributes'] = json_encode(array('some_attribute' => 'some value'))

The contact is then saved, but not the attributes.

@stefanogit
Copy link

I'm trying to to add an attribute value but nothing... any solutions?

@vishalpawar-tudip
Copy link

Any update here, please?
I am also getting same 400 error code while creating contact.

@Faab
Copy link

Faab commented Sep 17, 2018

I got this error because contact already exists in another list. The error message is not clear.
Add parameter updateEnabled = true solved the problem.

https://developers.sendinblue.com/v3.0/reference#createcontact

@devNicolasNmk
Copy link

hello,

I have the same problem with attributes.

email is ok but attributes are not send

any idea please ?

I've also tried to wrap it as a json object:

$create_contact['attributes'] = json_encode(array('some_attribute' => 'some value'))

The contact is then saved, but not the attributes.

@bjornbos
Copy link

I just ditched the PHP SDK and use the REST api directly. Works so much better.

@devNicolasNmk
Copy link

@bjornbos
Thank you for your fast answer.

@karelbyte
Copy link

hello, has one managed to send the attributes?, only the email is saved

@karelbyte
Copy link

karelbyte commented Dec 21, 2018

I, sent in the data in this way and does not save the attributes:
{"email":"ssss@gmail.com","attributes":{"FNAME":"sdgsfdgsdsf"}}

@korynorthrop
Copy link

I have been able to get some attributes to save, but am struggling to set attributes with the "Category" type (e.g. the default DOUBLE_OPT-IN attribute and a custom attribute I created called IS_SUPPORTER, both of which are "Category" attribute types with two potential values "Yes" and "No").

I was originally struggling to set the first and last name attributes for a contact because I was following the documentation, which shows those attributes as FNAME and LNAME, but I saw in the attributes table that they are actually FIRSTNAME and LASTNAME. The following code successfully sets the the first name and the GDPR_CONSENT attribute (boolean type), but doesn't update my custom category attribute (IS_SUPPORTER) or the native DOUBLE_OPT-IN category attribute.

$apiInstance = new SendinBlue\Client\Api\ContactsApi(
  new GuzzleHttp\Client(),
  $config
);

$email = 'testcontact@email.com';

$updateContact = new \SendinBlue\Client\Model\UpdateContact();

$updateContact['attributes'] = array(
	'FIRSTNAME' => 'Joe',
	'IS_SUPPORTER' => 'YES',
	'DOUBLE_OPT-IN' => 'NO',
	'GDPR_CONSENT' => true
);

try {
  $result = $apiInstance->updateContact( $email, $updateContact );
  var_dump( 'sent' );
} catch ( Exception $e ) {
  echo 'Exception when calling ContactsApi->createContact: ', $e->getMessage(), PHP_EOL;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants