Search by

metadrop / gocontact-php

omarlopesino

PHP client for the GoContact CCaaS REST API: contacts, databases, extrafields and the report designer.

Package info

github.com/Metadrop/gocontact-php

pkg:composer/metadrop/gocontact-php

Statistics

Installs: 31

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-11-16 15:54 UTC

This package is auto-updated.

Last update: 2026-11-16 16:18:55 UTC


README

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.

Documentation

Installation

composer require metadrop/gocontact-php

The 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/cache

Usage

use 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.

API notes

  • Tokens last 24h; they are cached and renewed once on a 401.
  • The batch contact creation is all-or-nothing, needs at least one *_phone and 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.

Quality

composer qa

License

LGPL-3.0-or-later. See LICENSE.