PHP code example of targito / targito-api

1. Go to this page and download the library: Download targito/targito-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

targito / targito-api example snippets




use Targito\Api\TargitoApi;

$api = new TargitoApi($credentials);

// do stuff with api



use Targito\Api\TargitoApi;
use Targito\Api\Credentials\Credentials;
use Targito\Api\Credentials\EnvironmentCredentials;

// provide the credentials in constructor
$credentials = new Credentials('my-account-id', 'my-api-password');
$api = new TargitoApi($credentials);

// get them automatically from environment variables using default TARGITO_ACCOUNT_ID and TARGITO_API_PASSWORD variables
$credentials = new EnvironmentCredentials();
$api = new TargitoApi($credentials);

// customize the environment variables
$credentials = new EnvironmentCredentials('MY_CUSTOM_ACCOUNT_ID_VARIABLE', 'MY_CUSTOM_API_PASSWORD_VARIABLE');
$api = new TargitoApi($credentials);



use Targito\Api\TargitoApi;
use Targito\Api\Credentials\EnvironmentCredentials;
use Targito\Api\DTO\Request\Contact\DeleteContactRequest;

// get credentials from env variables and use the default http request implementation
$api = new TargitoApi(new EnvironmentCredentials());

// get the contacts API module
$contactsApi = $api->contacts();

$result = $contactsApi->deleteContact(DeleteContactRequest::fromArray([
    'id' => 'contact_id',
    'origin' => 'contact_origin'
]));

echo $result->jobId;



use Targito\Api\TargitoApi;
use Targito\Api\Credentials\EnvironmentCredentials;
use Targito\Api\DTO\Request\Contact\DeleteContactRequest;

$api = new TargitoApi(new EnvironmentCredentials());

// provide data as array
$api->contacts()->deleteContact([
    'id' => 'contact_id',
    'origin' => 'contact_origin'
]);

// create the DeleteContactRequest from array
$api->contacts()->deleteContact(DeleteContactRequest::fromArray([
    'id' => 'contact_id',
    'origin' => 'contact_origin'
]));

// create the DeleteContactRequest manually
$deleteRequest = new DeleteContactRequest();
$deleteRequest->id = 'contact_id';
$deleteRequest->origin = 'contact_origin';

$api->contacts()->deleteContact($deleteRequest);