PHP-SDK

Introduction

Our PHP-SDK provides a simple interface for PHP developers to integrate Quentn into their application. Features include:

  • Easy installation of all dependencies with Composer
  • Build in functions for each API-Endpoint
  • Helper functions to get started with Oauth 2.0 authentication

Please visit our Github Repository for more information:

Quentn PHP-SDK (Github)

Install the SDK

We highly recommend composer to install the Quentn-PHP-SDK. To learn more about composer please visit the Composer Getting Started Guide

To install the Quentn-PHP-SDK with composer, simple run:

composer require quentn/php-sdk

You can also manually add the dependency to your composer.json file:

{
  "require": {
    "quentn/php-sdk": "1.0.*"
  }
}

Examples

Autoload

Add autoload on top of each file:

require __DIR__ . './vendor/autoload.php';

Create a new contact

This example shows how to create a new contact.

require __DIR__ . './vendor/autoload.php'; 

$quentn = new Quentn\Quentn([
   'api_key' => 'API_KEY',
   'base_url' => 'BASE_URL',
]);

//check API key
if (!$quentn->test()) {
   echo "key doesn't seem to work";
   exit;
}

//create contact       
$data = [
   "first_name" => "Johnn",
   "family_name" => "Doe",
   "mail" => "johndoe@example.com",
];

try {
   $get_response = $quentn->contacts()->createContact($data);
   $contact_id = $get_response['data']['id'];
} catch (Exception $e) {
   echo $e->getMessage();
}

Oauth authentication

With Oauth authentification you are able to receive the API-Url and the API-Key from a target system. To start your OAuth process, you need to register your app with the Quentn. After registration your will get Client ID and Client Secret.


require __DIR__ . './vendor/autoload.php'; 
$quentn = new Quentn\Quentn();        
$quentn->oauth()->setApp([
   'client_id' => 'CLIENT_ID',
   'client_secret' => 'CLIENT_SECRET',
   'redirect_uri' => 'REDIRECT_URL',   
]);

if($quentn->oauth()->authorize()) {                        
   /*
      do you stuff here
      You can now access your App key and base url with:
      $quentn->getApiKey();
      $quentn->getBaseUrl();
   */
   try {
      $get_response = $quentn->contacts()->findContactById($contactId, 'first_name, mail');
   } catch (Exception $e) {
      echo $e->getMessage();
   }            
}
    
else {
   // to get the Authorization URL you can use getAuthorizationUrl() function
   echo '<a href="' . $quentn->oauth()->getAuthorizationUrl() . '">Click here to get authorize</a>';   
}