Skip to content

Latest commit

 

History

History

svgator-php

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

SVGator's PHP SDK for SVGator API

Requirements

  • PHP ^5.4
  • cURL

Usage

Autoload

Include autoload.php inside your project.

i.e.

require_once('autoload.php');

Before You Start

In order to use SVGator's API & SDKs, one first must obtain an SVGator Application. To do so, please email [email protected], providing your SVGator account ID and the desired usage of your SVGator application.

The API keys one should receive from [email protected] are shown below:

Name Description Notes Sample Value
app_id Application ID prefixed with "ai_", followed by 32 alphanumeric chars ai_b1357de7kj1j3ljd80aadz1eje782f2k
secret_key Secret Key prefixed with "sk_", followed by 32 alphanumeric chars sk_58ijx87f45596ylv5jeb1a5vicdd92i4
❗ Attention
◾ Your Secret Key must not be included in any requests, neither be present on Front-End.

Creating an application on the fly is also possible using appId=dynamic, yet this feature comes with restrictions. For a multi-user implementation follow the steps above instead.

How to obtain access_token and customer_id

In order to obtain these, you will first need to obtain an auth_code (and an app_id, if you don't already have one) from the Frontend API.

You can generate the login URL from the SVGatorSDK\Main class by passing an app_id and a redirect_url. If you don't have an app_id, you can just pass dynamicsee limitations and one will be provided for you in the response.

$app_id = 'dynamic'; //or the actual app_id you have
$redirect_url = 'https://example.com/';
$loginUrl = \SVGatorSDK\Main::getLoginUrl($app_id, $redirect_url);

Once you got those, you need to pass the app_id to the SVGatorSDK\Main class and call the getAccessToken with the auth_code.

If the request is successful, the method will return an array with the following keys, which you should save:

  • access_token
  • customer_id
  • app_id
  • secret_key - only if it wasn't already provided to the class' constructor
$auth_code = 'ac...';
$svgator_keys = array(
	'app_id' => 'ai...'
);
$svgator_app = new \SVGatorSDK\Main($svgator_keys);
$data = $svgator_app->>getAccessToken($auth_code);

How to work with the SVGatorSDK\Main class

You will need to create a SVGatorSDK\Main object by passing an array - having the 4 keys mentioned earlier.

$svgator_keys = array(
    'app_id'      => 'ai...',
    'secret_key' => 'sk...',
    'access_token' => 'at...',
    'customer_id' => 'ci...',
);

$svgator_app = new \SVGatorSDK\Main($svgator_keys);

How to get the project list

Call the getAll method (no params necessary).

It will return an indexed array of SVGatorSDK\Model\Project objects. Each of these objects contain the following properties:

  • id - ID of the project
  • title - the title of the project
  • preview - a URL where one can preview the SVG
  • created - UNIX timestamp when the project was created
  • updated - UNIX timestamp when the project was last updated
$svgator_app->projects()->getAll();

How to get a single project details

Call the get method, passing the project's ID as a parameter.

It will return a SVGatorSDK\Model\Project object, described in the previous section.

$svgator_app->projects()->get($project_id);

How to get the SVG for a project

Call the export method, passing the project's ID as a parameter. It will return the SVG of the requested project.

$svgator_app->projects()->export($project_id);

You can also export the project for different platforms: web, react-native or flutter

$svgator_app->projects()->export($project_id, 'react-native');

If you omit the platform parameter, the settings saved to the project will be used.