PHP client for the GoContact CCaaS REST API. It covers contacts, databases, extrafields templates and the report designer, and works with any PSR-18 HTTP client, PSR-16 cache and PSR-3 logger.
- GoContact CCaaS API (Swagger): token, contacts, databases, extrafields and the report designer job endpoints.
- Report Designer (PHP):
the legacy
report_builder.phpendpoint that lists owners and report templates.
composer require metadrop/gocontact-phpThe client needs a PSR-18 HTTP client, PSR-17 factories and a PSR-16 cache. The example below uses Symfony HttpClient, nyholm/psr7 and Symfony Cache:
composer require symfony/http-client nyholm/psr7 symfony/cacheuse Metadrop\GoContact\Clock\SystemSleeper;
use Metadrop\GoContact\Credentials;
use Metadrop\GoContact\GoContact;
use Metadrop\GoContact\Http\HttpFactories;
use Metadrop\GoContact\Report\OwnerType;
use Metadrop\GoContact\Report\ReportDownloader;
use Metadrop\GoContact\Report\ReportRequest;
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Log\NullLogger;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Psr16Cache;
use Symfony\Component\HttpClient\Psr18Client;
$psr17Factory = new Psr17Factory();
$psr18Client = new Psr18Client(NULL, $psr17Factory, $psr17Factory);
$psr16Cache = new Psr16Cache(new FilesystemAdapter('gocontact'));
$logger = new NullLogger();
$goContact = new GoContact(
new Credentials('https://example.gocontact.es', 'example.gocontact.es', 'api_user', $password),
new HttpFactories($psr18Client, $psr17Factory, $psr17Factory),
$psr16Cache,
$logger,
);
// Contacts: the batch creation ignores extrafields, so they go afterwards.
$contact = $goContact->client()->createContact($databaseId, ['contact' => 'Jane', 'first_phone' => '600000000']);
$goContact->client()->updateExtrafields($databaseId, $contact->id, ['field1' => 'Jane']);
// Reports: every campaign, one day, saved to a CSV file.
$catalog = $goContact->reportCatalog()->catalog(OwnerType::Campaign);
$request = ReportRequest::forDay(OwnerType::Campaign, $catalog->ownerIds(), 5, $templateId, new DateTimeImmutable('yesterday'));
$bytes = (new ReportDownloader($goContact->reports(), new SystemSleeper(), $logger))
->download($request, '/tmp/report.csv', maxWait: 900);dataType selects which records enter the date range and depends on the owner
type. For campaigns and queues:
| dataType | Records |
|---|---|
| 0 | All calls |
| 1 | Calls with script |
| 2 | Answered calls |
| 3 | Not answered calls |
| 4 | Contact state by last call date |
| 5 | Contact state by last load date |
| 6 | Contact state by last update date |
The values of every other owner type are in the DataType Reference of
POST /api/reportdesigner/generateReport in the
Swagger documentation.
A report covers at most 3 months and 1 day.
- Tokens last 24h; they are cached and renewed once on a 401.
- The batch contact creation is all-or-nothing, needs at least one
*_phoneand ignores extrafields. - Extrafields are validated against the template of the campaign that owns the database, not the database's own template.
- Every request is logged before and after with its method and path. Query strings are never logged: the report builder takes the credentials there.
composer qaLGPL-3.0-or-later. See LICENSE.