8

I'm using the Codeigniter framework and trying to integrate with SendInBlue's PHP API. Their PHP documentation is not super helpful and the setup instructions on Github not clear either.

The doc says to "Download the files and include autoload.php":

require_once('/path/to/APIv3-php-library/vendor/autoload.php');

But I cannot find autoload anywhere and I'm not really sure how to include that in my CI structure.

Update:

I contacted Sendinblue support and they do not have any installation tutorial for CI users. I tried using Compiler, and got the folder structure created but I'm still having issues integrating it with CI. I placed all the folders in my Libraries but it is not loaded correctly and complains about Autoload class not existing.

Composer result

remyremy
  • 3,548
  • 3
  • 39
  • 56

2 Answers2

3

To get the autoload.php, you need to use Composer. This will resolve all dependencies and install/update them for you.

If you already have the entire SendInBlue API folder structure in the library location, you can only add in your controller, before class My_Class ... line require_once (APPPATH . 'vendor/autoload.php');

eg.

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

// include manually module library - SendInBlue API
require_once (APPPATH . 'vendor/autoload.php');

class My_Class extends CI_Controller {
....

After that, you can follow the guide from Github: APIv3-php-library - Getting Started

If you get errors, means that your SendInBlue's structure is bad. I recommand you to use Composer

  1. Install Composer if is not installed - Installation - Linux / Unix / OSX or Installation - Windows
  2. Install SendinBlue's API with Composer - Github: APIv3-php-library - Installation & Usage
  3. Add autoload.php in your controller - see the previous example

Please add here the list of errors if you still have issues.

vasilenicusor
  • 2,023
  • 1
  • 21
  • 37
  • It worked! Just made a few adjustments. In my controller the correct path is `require_once (APPPATH . 'libraries\vendor\autoload.php');` and I had to change autoload.php to `require_once (APPPATH . 'libraries\vendor\composer\autoload_real.php');` instead of the default `_DIR_ ...` – remyremy Jul 31 '18 at 06:40
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