Download the PHP package daktela/daktela-v6-php-connector without Composer

On this page you can find all versions of the php package daktela/daktela-v6-php-connector. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package daktela-v6-php-connector

Daktela V6 PHP Connector

Daktela V6 PHP Connector is a library that enables your PHP application to connect to your Daktela V6 REST API. This connector requires you to have the Daktela Contact Centre application already purchased, installed, and ready for use. The Daktela Contact Centre is an application enabling all-in-one handling of all customer communication coming through various channels, for example calls, e-mails, web chats, SMS, or social media.

Installation

The connector requires PHP 8.1 or newer, the mbstring extension, and Guzzle 7 (7.15.2 or newer, with PSR-7 2.13 or newer) or Guzzle 8 (8.0.1 or newer, with PSR-7 3). Composer installs the Guzzle version that fits the other dependencies of your project. The recommended way to install it is through Composer:

When upgrading an existing installation, Composer may need permission to update transitive dependencies:

See CHANGELOG.md for release notes and upgrade requirements.

Setup

The connector requires the following:

Configuration

HTTP Request Timeout

The default HTTP request timeout is 2 seconds. For operations that may take longer (e.g., reading large datasets), you can increase the timeout:

Usage

Create a client with the URL of the instance and an access token, and execute requests with it:

Every client has an ApiCommunicator of its own, which holds its transport settings: authentication method, timeout, SSL verification, User-Agent suffix, logger, custom HTTP client, retry, and rate-limit settings. To share one transport between clients, or to configure it before the client is created, pass it to the constructor:

Client::getInstance() and ApiCommunicator::getInstance() are deprecated. They return one shared object per instance URL and access token, so a setting changed by one caller applies to all of them, and the object stays in memory with its token until the process ends. Create the client once and pass it to the code that needs it.

Operations

The allowed operations serve for CRUD manipulation with objects. Each operation uses the builder pattern and corresponds to specific REST action.

Reading entities

In order to list all objects for specific entities use the execute() method:

To get one specific object, use RequestFactory::buildReadSingleRequest() or set its unique name and the ReadRequest::TYPE_SINGLE request type explicitly:

To read relation data, use RequestFactory::buildReadRelationRequest() or set the object name, relation name, and ReadRequest::TYPE_MULTIPLE request type explicitly:

Standard loading reads always entities of one page. For pagination use the setTake() and setSkip() methods.

To limit which fields are returned in the response, use the setFields() method:

If you don't want to handle pagination, use the following request type to read all records:

When reading all records, the connector starts at the request's setSkip() offset and stops as soon as the API-reported total is reached, even when the last page is full. If the API does not report a total, it stops on a short or empty page. A safety limit caps this operation at 999 page requests; when the limit is reached before all records are read, the response contains the records read so far and an error saying the result is truncated. By default, an error page ends the operation and that response is returned. To continue past error pages, use setSkipErrorRequests(true); error responses with non-array data are skipped. Only pages the API answers with HTTP 2xx and an error member can be skipped: an HTTP 4xx or 5xx response throws a RequestException, and the records read so far are lost. The errors of skipped pages are not kept, so the result can be incomplete without saying so; compare the number of records with getTotal(). The take of the request must be at least 1:

You can use different methods for defining filters:

Every addFilter() and addFilterFromArray() call is combined with the filters added before it using AND logic. To use OR logic, specify it in the filter array. The OR group is kept intact as a nested group when it is combined with other filters:

Creating entities

addAttributes() skips null values so that a partially filled array (for example a database row) does not clear fields by accident. Pass true as the second argument to send null values, for example to clear a field:

Updating entities

Deleting entities

Object names and relation names are URL-encoded as single path segments. Values that could address a different endpoint (empty values, . and .., also percent-encoded, and values containing /, \, or NUL) are rejected with a RequestException, as are model names containing dot segments, a literal ? or #, or NUL. A relation set without an object name is rejected as well, because the request would read the records of the model instead.

Processing response

The response entity contains the parsed data returned by the REST API. A successful HTTP status can still contain application-level errors, so inspect hasErrors() when the operation requires it.

Handling exceptions

Transport failures and, with Guzzle's default http_errors setting, non-retryable HTTP 4xx/5xx responses are wrapped in Daktela\DaktelaV6\Exception\RequestException. Other exceptions of the HTTP client, for example from a custom client, are wrapped in RequestException as well: a Guzzle request or network exception is chained as a copy without the access token, and any other exception is not chained, because its own previous exceptions may carry the token. HTTP 429 responses use the more specific RateLimitException, which extends RequestException and returns 429 from getHttpStatus().

A request that is not valid, such as a model or object name that would address another endpoint, a relation without its object, a page size below 1, or an instance URL that cannot be parsed, throws InvalidRequestException before anything is sent. It extends RequestException.

HTTP 404 responses throw NotFoundException, which also extends RequestException. For HTTP errors, the exception exposes the response details:

The access token is replaced with *** in exception messages, the stored response body and API errors, and log entries produced by the connector. With the header methods, $ex->getPrevious() is a copy of the Guzzle exception without the token: its request has no credential headers, and the token is replaced in its URL, message, response headers, and body. For a transfer error, a response body larger than 1 MiB is left out of the copy. A response body that cannot be parsed as JSON is not chained at all, because the trace of the parser error holds the raw body. With query parameter authentication, nothing is chained. Prefer getHttpStatus(), getResponseBody(), and getApiErrors(). For a transfer that failed after the response headers, such as a truncated body or, with Guzzle 8, a timeout while the body is read, getHttpStatus() is null, while getCode() is the status of the partial response, as Guzzle sets it. The response body may contain personal data, so log it with care.

Access Tokens

Use a static API token for integrations. An administrator creates it in Manage → Users → [user detail] → Persistent API tokens, or through the apiToken API endpoint.

Integrations that use a static token need no changes when Daktela is updated to a version that uses JWT sessions for the web interface.

Logging In with a Username and Password

Instead of using a static token, the connector can log in with a username and password. It refreshes the short-lived access token before it expires, and logs in again when the session has ended:

Each login starts a new session on the Daktela server. To reuse one session across processes, pass a TokenStore that keeps the tokens in your cache or database:

Authentication Methods

The connector supports three ways of passing the access token to the Daktela V6 API. It sends the token in exactly one of them.

1. Authorization: Bearer Header (Default)

By default, the access token is sent in the standard Authorization: Bearer <token> header, which the Daktela API documentation recommends. It requires Daktela 31.37.0, 32.36.0, 33.14.0, or later. Older versions do not read this header: API endpoints answer HTTP 401, and the health check reports the token as not accepted. Use the X-AUTH-TOKEN header for them.

2. X-AUTH-TOKEN Header (Legacy)

The access token can be sent in the proprietary X-AUTH-TOKEN header, which every Daktela V6 version accepts. The Daktela API documentation lists it as legacy, but it is still supported. Use it for Daktela versions older than 31.37.0, 32.36.0, or 33.14.0.

3. Query Parameter Authentication (Deprecated)

This method is deprecated: the token becomes part of the request URL, which web servers and proxies write to their logs. Alternatively, you can send the access token as a query parameter (accessToken). This method may be useful for compatibility with certain proxy configurations or firewall rules.

To switch back to the default header:

Security Note: Use one of the header methods in production. They keep the access token out of server logs, browser history, and other places where URLs are typically recorded. The default HTTP client does not send the token to a redirect target outside the instance (another host, another port, or plain HTTP from an HTTPS instance). After a redirect from http:// to https:// on the same host, the X-AUTH-TOKEN header is still sent, but the Authorization: Bearer header is not, because Guzzle removes it whenever the scheme changes: use an https:// instance URL, and keeps it off for the rest of the redirect chain once a redirect has left the instance. If you set a custom HTTP client, configure its redirect handling yourself.

Advanced Configuration

SSL Verification

By default, SSL certificates are verified. For development environments with self-signed certificates, you can disable verification:

Warning: Never disable SSL verification in production.

Custom User-Agent

You can append a custom suffix to the User-Agent header for tracking purposes:

Logging

The connector supports PSR-3 compatible loggers for debugging:

Custom HTTP Client

You can inject a custom Guzzle HTTP client for advanced configurations (proxies, middleware, etc.):

The connector sends requests with a path relative to the instance, so a custom client needs base_uri set to the instance URL. When a custom client is set, configure timeouts, TLS verification, http_errors, and other transport options on that client. The connector's setRequestTimeout() and setVerifySsl() settings are used only when it creates the default Guzzle client.

Retry Mechanism

The connector supports automatic retries with exponential backoff for configured HTTP status codes and, optionally, connection errors. maxRetries is the number of additional attempts after the initial request. With Guzzle's default http_errors setting, other HTTP errors continue to throw RequestException without retrying.

Connection errors are transfers that end without a complete response. Guzzle 7 reports connection failures and timeouts as ConnectException. Guzzle 8 reports connection failures, timeouts, and connection resets as NetworkException, and a response that broke off after its headers, for example on a timeout, as ResponseTransferException. Guzzle 7 reports a connection reset or a truncated body as a plain RequestException, so these are not retried with Guzzle 7, while Guzzle 8 retries them like other connection errors.

Create requests (POST) are not idempotent: a timeout or a 5xx response does not prove that the server did not create the record, so repeating them could create duplicates. They are therefore retried only on HTTP 429 and when the connection for the request itself could not be established (DNS, connect, or TLS handshake failure). A connection failure on a redirect target does not count: the server may have created the record before it redirected, for example with 303 See Other. With Guzzle 8, a connect timeout also counts as a failure to establish the connection; with Guzzle 7, a timeout is never retried for them, because Guzzle 7 does not report in which phase it happened. The connector tells the request from a redirect hop by its origin, method, path, and query, so a custom HTTP client must send the request to the instance and keep its method, path, and query for a failed POST to be retried. Only a Guzzle ConnectException shows that the connection failed before the request was sent, so another network exception of a custom client is retried for a POST only with retryNonIdempotentRequests. Set retryNonIdempotentRequests: true to retry them in all retryable cases. Read, update, and delete requests are retried in all retryable cases.

Rate Limit Handling

The connector can automatically handle rate limiting (HTTP 429 responses):

With automatic rate-limit handling enabled, the connector performs one retry even when no general RetryConfig is set. A positive maxRetries value in RetryConfig supplies the shared retry budget. The wait comes from either form of the HTTP Retry-After header, or from defaultWaitSeconds; a RateLimitException is thrown if the budget is exhausted or the requested wait exceeds maxWaitSeconds.

If rate limiting occurs and autoRetry is disabled, a RateLimitException is thrown:

Health Check

ping() and healthCheck() call the whoim endpoint and report the API as healthy only when the response identifies the user of the access token. The endpoint also answers requests whose token was not accepted (invalid, expired, or revoked token, or a deactivated user) with HTTP 200 and no user, and the health check reports those as unhealthy.

error contains the first error message reported by the API, in the language of the token's user. Without one, it describes the problem: the token was not accepted, an HTTP error status, an unexpected response (for example, from a wrong instance URL), or the transport error. status_code is missing when no HTTP response was received.

whoim also checks the state of the user account. For an account with an unfinished password change (its profile requires a one-time password and the new password was never set), it returns HTTP 400 New password should be set, although other endpoints still accept the token. Set the new password in the Daktela web interface to make the health check pass.

whoim is the request the Daktela web interface makes at startup, and it is heavier than a typical read. Use the health check at startup or for monitoring, not before every request.

Memory-Efficient Iteration

For large datasets, use the iterator to process records one at a time without loading everything into memory:

The iterator clones the request and does not mutate the caller's request. It stops at the API-reported total, avoiding an extra empty request when the total is an exact multiple of the page size. If no positive total is reported, it stops on a short or empty page. It starts at the request's setSkip() offset.

An error page ends the iteration by default. To tell this apart from the end of the data, check the iterator afterwards:

Set stopOnError: false to skip an error page and continue at the next offset. As with reading all records, only an HTTP 2xx response with an error member is an error page; an HTTP 4xx or 5xx response throws a RequestException out of the loop, and hasStoppedOnError() stays false. The page size must be at least 1; iterate() throws an InvalidRequestException otherwise. Error pages are skipped only while the API-reported total shows that more records follow; otherwise the iteration stops and the error response is available as above. For item iteration, a maxItems value of zero returns no items and sends no request; pages() is independent of that item limit.

Iterator helper methods start a new traversal each time. For example, calling first() and then toArray() performs separate API reads.

Response Helper Methods

The response object provides convenient helper methods:

Development and testing

Project commands are run in Docker. After installing dependencies in the mounted working directory, run the deterministic unit suite with:

The full suite also contains live API integration tests, which are skipped unless their environment variables are set:

composer check runs composer validate, the coding standard (PSR-12, phpcs.xml.dist), PHPStan, and the tests. CI runs the same on every supported PHP and Guzzle version, and also requires 90% line coverage. Run it in the same container:

CI tests supported PHP versions with Guzzle 7 and Guzzle 8 and enforces at least 90% line coverage for the deterministic unit suite.


All versions of daktela-v6-php-connector with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
guzzlehttp/guzzle Version ^7.15.2 || ^8.0.1
guzzlehttp/psr7 Version ^2.13 || ^3.0
ext-json Version *
ext-mbstring Version *
psr/http-client Version ^1.0
psr/http-message Version ^1.1 || ^2.0
psr/log Version ^1.0 || ^2.0 || ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package daktela/daktela-v6-php-connector contains the following files

Loading the files please wait ...