Search code examples
phpcomposer-phplaravel-5.5sendinblue

SendInBlue create contact error


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 protected]';
$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)


Solution

  • Using the github docs

    <?php
    
    require_once(DIR . 'autoload.php');
    
    // Configure API key authorization: api-key
    SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOUR API');
    // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
    // SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer');
    
    $api_instance = new SendinBlue\Client\Api\ContactsApi();
    $createContact = new \SendinBlue\Client\Model\CreateContact(); // \SendinBlue\Client\Model\CreateContact | Values to create a contact
    
    $createContact['email'] = '[email protected]';
    
    
    try {
        $result = $api_instance->createContact($createContact);
        print_r($result);
    } catch (Exception $e) {
        echo 'Exception when calling ContactsApi->createContact: ', $e->getMessage(), PHP_EOL;
    }
    ?>