0

I am searching for a SendinBlue API for Codeigniter but not found yet.

In the case that the API does not exists yet, is that hard to code it by myself (I already know HTTP requests but I not have any idea about configs)

Or is that possible to use the PHP one ?

Thanks

Grokify
  • 15,092
  • 6
  • 60
  • 81

1 Answers1

0

I have a beautiful solution for this and it works fine for me and I hope it will work for you as well. I am using API-v3.

What I did is:

  1. Downloaded the API through composer on my local PC.
  2. Created a folder named "sendinblue" on the server (where we have assets folders) and upload the vendor folder from the downloaded API inside this folder.
  3. Created a library named "Sendinblue.php" and added all the necessary functions here. Now I can use this library like other libraries.

This is my library structure:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Sendinblue{
    public $config;
    public $apiInstance;
    public function __construct(){      
        require_once('sendinblue/vendor/autoload.php');
        $this->config = SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', '');
        $this->apiInstance = new SendinBlue\Client\Api\ContactsApi(
            new GuzzleHttp\Client(),
            $this->config
        );      
    }

    public function get_contact_info($data){
        $identifier = $data['email'];
        try {
          return $result = $this->apiInstance->getContactInfo($identifier);
        } catch (Exception $e) {
          return 'Exception when calling ContactsApi->getContactInfo: '.$e->getMessage();
        }
    }
    
    public function create_contact($data){
        $createContact = new \SendinBlue\Client\Model\CreateContact();
        $createContact['email'] = $data['email'];
        $createContact['listIds'] = [2];
        try {
          return $result = $this->apiInstance->createContact($createContact);
        } catch (Exception $e) {
          return $e->getCode();
        }
    }
Mohit Prajapati
  • 380
  • 3
  • 8