### Complete PHP Crisp API Example Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/QUICK_START.md A comprehensive example demonstrating client initialization, authentication, fetching conversations, sending messages, updating metadata, and resolving conversations. Ensure you have the Crisp SDK installed and environment variables for authentication set. ```php setTier("plugin"); $client->authenticate( getenv('CRISP_TOKEN_ID'), getenv('CRISP_TOKEN_KEY') ); $websiteId = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc"; // Get conversations $conversations = $client->websiteConversations->getList($websiteId, 1); foreach ($conversations['conversations'] as $conv) { $sessionId = $conv['session_id']; // Get full conversation $full = $client->websiteConversations->getOne($websiteId, $sessionId); // Send message $client->websiteConversations->sendMessage( $websiteId, $sessionId, [ "type" => "text", "from" => "operator", "origin" => "chat", "content" => "Thanks for reaching out!" ] ); // Update metadata $client->websiteConversations->updateMeta( $websiteId, $sessionId, ["data" => ["processed" => true]] ); // Mark as resolved $client->websiteConversations->setState( $websiteId, $sessionId, "resolved" ); } echo "Processed " . count($conversations['conversations']) . " conversations"; } catch ( Crisp CrispException $e) { error_log("API Error: " . $e->getMessage()); } catch ( Exception $e) { error_log("Error: " . $e->getMessage()); } ``` -------------------------------- ### Minimal Crisp PHP API Client Setup Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/CONFIGURATION.md Instantiate the Crisp PHP API client, set the authentication tier, and authenticate with your token keypair. This is the basic setup required before using the client's functionalities. ```php require __DIR__ . '/vendor/autoload.php'; $client = new Crisp\CrispClient(); // Set authentication tier (user, website, or plugin) $client->setTier("plugin"); // Authenticate with your token keypair $client->authenticate("token_identifier", "token_key"); // Now use the client $conversations = $client->websiteConversations->getList("website_id", 1); ``` -------------------------------- ### Example Authentication Header Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/API_ENDPOINTS.md An example of a correctly formatted basic authentication header with a specific token and Crisp Tier. ```text Authorization: Basic N2MzZWYyMWMtMWUwNC00MWNlLThjMDYtNTYwNWMzNDZmNzNlOmNjMjllMWE1MDg2ZTQyOGZjYzZhNjk3ZDU4MzdhNjZkODI4MDhlNjVjNWNjZTAwNmZiZjIxOTFjZWVhODBhMGE= X-Crisp-Tier: plugin ``` -------------------------------- ### Install crispchat/php-crisp-api with Composer Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/README.md Use Composer to install the PHP Crisp API client library. This command fetches the package and its dependencies. ```bash composer require crispchat/php-crisp-api ``` -------------------------------- ### get() Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/CLIENT.md Sends a GET request to a specified relative path on the API. ```APIDOC ## get() ### Description Sends a GET request to the specified path. ### Method Signature `public function get(string $path): ResponseInterface` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters Table | Parameter | Type | Required | Description | |-----------|------|----------|-------------| | `$path` | `string` | Yes | Relative endpoint path (e.g., `website/123/conversation/456`). | ### Returns `ResponseInterface` (PSR-7) ### Throws `ClientExceptionInterface` ### Example ```php $response = $client->get("website/abc123/conversation/session123"); ``` ``` -------------------------------- ### Get Website Settings Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/QUICK_START.md Fetches the current settings for a specific website. ```APIDOC ## Website Settings - Get Website Settings ### Description Retrieves the settings for a specific website. ### Method ```php $settings = $client->websiteSettings->get("website_id"); ``` ``` -------------------------------- ### Example: Batch Resolve Conversations Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/OTHER_RESOURCES.md Demonstrates how to prepare data and call the batchResolveItems method to resolve multiple conversations. ```php $batch = [ "items" => [ "session_id_1", "session_id_2", "session_id_3" ] ]; $result = $client->websiteBatch->batchResolveItems("website_id", $batch); ``` -------------------------------- ### Basic Crisp PHP API Setup and Authentication Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/QUICK_START.md Includes setting the API tier and authenticating with your Crisp API tokens. Ensure you have autoloaded the Composer dependencies. ```php require __DIR__ . '/vendor/autoload.php'; $client = new Crisp\CrispClient(); // Set tier (plugin, website, or user) $client->setTier("plugin"); // Authenticate with token $client->authenticate( "7c3ef21c-1e04-41ce-8c06-5605c346f73e", "cc29e1a5086e428fcc6a697d5837a66d82808e65c5cce006fbf2191ceea80a0a" ); ``` -------------------------------- ### Initialize Crisp Client with Auto-Discovery Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/CONFIGURATION.md Use this method when you have compatible PSR-18 HTTP client packages installed. The client will automatically detect and use an available implementation. ```php $client = new \Crisp\CrispClient(); ``` -------------------------------- ### Get Verify Settings Source: https://github.com/crisp-im/php-crisp-api/blob/master/EXAMPLES.md Retrieves the verification settings for a specific website. ```APIDOC ## GET /websites/{website_id}/settings/verify ### Description Retrieves the verification settings for a specific website. ### Method GET ### Endpoint /websites/{website_id}/settings/verify ### Parameters #### Path Parameters - **website_id** (string) - Required - The ID of the website. ### Response #### Success Response (200) - **data** (object) - Contains the verification settings. ### Response Example { "data": { "enabled": true } } ``` -------------------------------- ### Initialize Crisp Client with Guzzle Adapter Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/CONFIGURATION.md Configure the Crisp client to use Guzzle 7 as the HTTP client. Ensure you have `guzzlehttp/guzzle` and `php-http/guzzle7-adapter` installed. ```php require __DIR__ . '/vendor/autoload.php'; use GuzzleHttp\Client as GuzzleClient; use Http\Adapter\Guzzle7\Client as GuzzleAdapter; $guzzle = new GuzzleClient(); $httpClient = new GuzzleAdapter($guzzle); $client = new \Crisp\CrispClient($httpClient); $client->setTier("plugin"); $client->authenticate($id, $key); ``` -------------------------------- ### Get Verify Key Source: https://github.com/crisp-im/php-crisp-api/blob/master/EXAMPLES.md Retrieves the verification key for a specific website. ```APIDOC ## GET /websites/{website_id}/settings/verify/key ### Description Retrieves the verification key for a specific website. ### Method GET ### Endpoint /websites/{website_id}/settings/verify/key ### Parameters #### Path Parameters - **website_id** (string) - Required - The ID of the website. ### Response #### Success Response (200) - **data** (object) - Contains the verification key. ### Response Example { "data": { "key": "your_verification_key" } } ``` -------------------------------- ### Get All Subscriptions For Website Source: https://github.com/crisp-im/php-crisp-api/blob/master/README.md Retrieves all plugin subscriptions associated with a specific website. ```APIDOC ## Get All Subscriptions For Website ### Description Retrieves all plugin subscriptions for a given website. ### Method GET ### Endpoint /websites/{website_id}/plugins/subscriptions ### Parameters #### Path Parameters - **website_id** (string) - Required - The ID of the website. ### Request Example ```php $websiteId = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc"; CrispClient->pluginSubscriptions->listSubscriptionsForWebsite(websiteId); ``` ### Response #### Success Response (200) - subscriptions (array) - A list of subscription objects for the website. #### Response Example ```json { "data": [ { "website_id": "8c842203-7ed8-4e29-a608-7cf78a7d2fcc", "plugin_id": "c64f3595-adee-425a-8d3a-89d47f7ed6bb", "created_at": "2023-01-01T12:00:00Z", "updated_at": "2023-01-01T12:00:00Z" } ] } ``` ``` -------------------------------- ### Get Website Verification Settings Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/API_ENDPOINTS.md Retrieves the verification settings for a specific website. ```APIDOC ## GET website/{websiteId}/verify/settings ### Description Gets the verification settings for a specific website. ### Method GET ### Endpoint `/website/{websiteId}/verify/settings` ### Parameters #### Path Parameters - **websiteId** (string) - Required - The ID of the website to retrieve verification settings for. ``` -------------------------------- ### Handle Crisp API and Network Errors in PHP Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/README.md This example shows how to catch specific exceptions for API errors (`CrispException`) and network issues (`ClientExceptionInterface`) when making requests. ```php try { $result = $client->websiteConversations->getOne($websiteId, $sessionId); } catch ( Crisp\ CrispException $e) { $error = $e->getError(); echo "Error: " . $error['data']['message']; } catch ( Psr\ Http\ Client\ ClientExceptionInterface $e) { echo "Network error: " . $e->getMessage(); } ``` -------------------------------- ### Create People Profile Request Body Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/API_ENDPOINTS.md Example of a request body for creating a new people profile. ```APIDOC ## POST /people ### Description Creates a new people profile. ### Method POST ### Endpoint /people ### Request Body - **email** (string) - Required - The email address of the person. - **person** (object) - Optional - Details about the person. - **nickname** (string) - Optional - The nickname of the person. - **avatar** (string) - Optional - The URL of the person's avatar. ### Request Example ```json { "email": "customer@example.com", "person": { "nickname": "Customer Name", "avatar": "https://example.com/avatar.jpg" } } ``` ``` -------------------------------- ### Get Verify Settings Source: https://github.com/crisp-im/php-crisp-api/blob/master/EXAMPLES.md Retrieves the verification settings for a specific website. Requires the website ID. ```php $websiteId = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc"; CrispClient->websiteVerify->getSettings(websiteId); ``` -------------------------------- ### Get Website Settings Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/OTHER_RESOURCES.md Retrieve the current settings for a specific website using its ID. Ensure you have a valid website ID. ```php $settings = $client->websiteSettings->get("website_id"); ``` -------------------------------- ### Initiate a Website Conversation Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/WEBSITE_CONVERSATIONS.md Initiates a conversation with an existing session. This is useful for re-engaging with a past conversation or starting a new interaction within an existing session context. Requires the website ID and session ID. ```php $initiated = $client->websiteConversations->initiateOne("website_id", "session_id"); ``` -------------------------------- ### PHP Crisp API Full Configuration Example Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/CONFIGURATION.md This snippet shows how to initialize the Crisp API client in PHP, load credentials from environment variables, and authenticate. It includes configuration for the HTTP client, SSL verification, and basic error handling. Ensure CRISP_TOKEN_ID and CRISP_TOKEN_KEY environment variables are set. ```php require __DIR__ . '/vendor/autoload.php'; use GuzzleHttp\Client as GuzzleClient; use Http\Adapter\Guzzle7\Client as GuzzleAdapter; try { // Configure HTTP client $guzzle = new GuzzleClient([ 'timeout' => 30.0, 'connect_timeout' => 10.0, 'verify' => true // Always verify SSL in production ]); $httpClient = new GuzzleAdapter($guzzle); // Initialize Crisp client $client = new \Crisp\CrispClient($httpClient); // Load credentials from environment $tier = getenv('CRISP_TIER') ?: 'plugin'; $tokenId = getenv('CRISP_TOKEN_ID'); $tokenKey = getenv('CRISP_TOKEN_KEY'); if (!$tokenId || !$tokenKey) { throw new \Exception('Crisp API credentials not configured'); } // Configure client $client->setTier($tier); $client->authenticate($tokenId, $tokenKey); // Use client $conversations = $client->websiteConversations->getList("website_id", 1); } catch (\Crisp\CrispException $e) { error_log("Crisp API Error: " . $e->getMessage()); } catch (\Exception $e) { error_log("Error: " . $e->getMessage()); } ``` -------------------------------- ### Initialize Crisp Client Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/ARCHITECTURE.md Instantiate the Crisp client, set the API tier, and authenticate with your API ID and key. ```php $client = new \Crisp\CrispClient(); $client->setTier("plugin"); $client->authenticate("id", "key"); ``` -------------------------------- ### Send GET Request Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/CLIENT.md Sends a GET request to a specified relative endpoint path. The response is returned as a PSR-7 ResponseInterface object. ```php $response = $client->get("website/abc123/conversation/session123"); ``` -------------------------------- ### Create New Website Conversation - PHP Crisp API Source: https://github.com/crisp-im/php-crisp-api/blob/master/EXAMPLES.md Initiates a new conversation for a specified website. This is useful for starting new support threads. ```php $websiteId = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc"; CrispClient->websiteConversations->create(websiteId); ``` -------------------------------- ### Handle API and Network Errors Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/QUICK_START.md Implement robust error handling for API requests. This example catches specific Crisp API exceptions (e.g., authentication, not found) and general network client exceptions. ```php try { $conversation = $client->websiteConversations->getOne( "website_id", "session_id" ); } catch (CrispCrispException $e) { // API error $error = $e->getError(); if ($error['code'] === 401) { echo "Authentication failed"; } elseif ($error['code'] === 404) { echo "Conversation not found"; } else { echo "API Error: " . $error['data']['message']; } } catch (PsrHttpClientClientExceptionInterface $e) { // Network error echo "Connection failed: " . $e->getMessage(); } ``` -------------------------------- ### Get Details for a Specific Plugin Subscription Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/OTHER_RESOURCES.md Fetch detailed information about a specific plugin subscription. Requires both the website ID and the plugin ID. ```php $details = $client->pluginSubscriptions->getSubscriptionDetails("website_id", "plugin_id"); ``` -------------------------------- ### Initialize and Authenticate CrispClient Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/README.md Instantiate the `CrispClient`, set the API tier, and authenticate using your Crisp API ID and key. This is the main entry point for using the library. ```php $client = new \Crisp\CrispClient(); $client->setTier("plugin"); $client->authenticate($id, $key); ``` -------------------------------- ### Get Subscription Details - PHP Crisp API Source: https://github.com/crisp-im/php-crisp-api/blob/master/README.md Fetch detailed information about a specific plugin subscription for a given website. Requires both website ID and plugin ID. ```php $websiteId = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc"; $pluginId = "c64f3595-adee-425a-8d3a-89d47f7ed6bb"; CrispClient->pluginSubscriptions->getSubscriptionDetails(websiteId, pluginId); ``` -------------------------------- ### Get metadata Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/API_ENDPOINTS.md Retrieves the metadata for a specific conversation. ```APIDOC ## GET /website/{websiteId}/conversation/{sessionId}/meta ### Description Get the metadata for a specific conversation. ### Method GET ### Endpoint `/website/{websiteId}/conversation/{sessionId}/meta` ### Parameters #### Path Parameters - **websiteId** (string) - Required - The ID of the website. - **sessionId** (string) - Required - The ID of the conversation session. ``` -------------------------------- ### Initialize and Authenticate Crisp Client Source: https://github.com/crisp-im/php-crisp-api/blob/master/README.md Basic setup for the Crisp API client. Ensure you have the 'vendor/autoload.php' file included and replace 'identifier', 'key', and 'websiteId' with your actual credentials and IDs. This snippet demonstrates setting the tier and authenticating the client. ```php require __DIR__ . '/vendor/autoload.php'; $CrispClient = new Crisp\CrispClient; $CrispClient->setTier("plugin"); $CrispClient->authenticate(identifier, key); $conversations = $CrispClient->websiteConversations->getList(websiteId, 1); echo $conversations; ``` -------------------------------- ### Get routing Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/API_ENDPOINTS.md Retrieves the routing information for a specific conversation. ```APIDOC ## GET /website/{websiteId}/conversation/{sessionId}/routing ### Description Get the routing information for a specific conversation. ### Method GET ### Endpoint `/website/{websiteId}/conversation/{sessionId}/routing` ### Parameters #### Path Parameters - **websiteId** (string) - Required - The ID of the website. - **sessionId** (string) - Required - The ID of the conversation session. ``` -------------------------------- ### Create Crisp Client Instance Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/ARCHITECTURE.md Instantiate the main client for interacting with the Crisp API. ```php $client = new CrispClient(); ``` -------------------------------- ### Get Plugin Subscription Settings Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/OTHER_RESOURCES.md Retrieve the current settings for a specific plugin subscription. This requires the website ID and the plugin ID. ```php $settings = $client->pluginSubscriptions->getSubscriptionSettings( "website_id", "plugin_id" ); ``` -------------------------------- ### Get Website Verification Settings Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/OTHER_RESOURCES.md Retrieve the verification settings for a given website ID. This is useful for checking the current security status. ```php $verifySettings = $client->websiteVerify->getSettings("website_id"); ``` -------------------------------- ### Get conversation Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/API_ENDPOINTS.md Retrieves details for a specific conversation on a website. ```APIDOC ## GET /website/{websiteId}/conversation/{sessionId} ### Description Get details for a specific conversation identified by its session ID. ### Method GET ### Endpoint `/website/{websiteId}/conversation/{sessionId}` ### Parameters #### Path Parameters - **websiteId** (string) - Required - The ID of the website. - **sessionId** (string) - Required - The ID of the conversation session. ``` -------------------------------- ### Initiate Conversation with Existing Session - PHP Crisp API Source: https://github.com/crisp-im/php-crisp-api/blob/master/EXAMPLES.md Starts a new conversation linked to an existing user session. This is helpful for resuming previous interactions. ```php $websiteId = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc"; $sessionId = "session_700c65e1-85e2-465a-b9ac-ecb5ec2c9881"; CrispClient->websiteConversations->initiateOne(websiteId, sessionId); ``` -------------------------------- ### Get Conversation Routing Source: https://github.com/crisp-im/php-crisp-api/blob/master/EXAMPLES.md Retrieves the routing information for a conversation. ```APIDOC ## Get Conversation Routing Assign ### Description Retrieves the routing information for a conversation. ### Method GET ### Endpoint /websites/{websiteId}/sessions/{sessionId}/routing ### Request Example ```php $websiteId = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc"; $sessionId = "session_700c65e1-85e2-465a-b9ac-ecb5ec2c9881"; CrispClient->websiteConversations->getRouting(websiteId, sessionId); ``` ``` -------------------------------- ### Get Messages Source: https://github.com/crisp-im/php-crisp-api/blob/master/EXAMPLES.md Retrieves messages from a conversation up to a specified timestamp. ```APIDOC ## Get Messages in Conversation ### Description Retrieves messages from a conversation up to a specified timestamp. ### Method GET ### Endpoint /websites/{websiteId}/sessions/{sessionId}/messages ### Parameters #### Query Parameters - **timestamp_before** (integer) - Optional - Timestamp (in milliseconds) before which to retrieve messages. ### Request Example ```php $websiteId = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc"; $sessionId = "session_700c65e1-85e2-465a-b9ac-ecb5ec2c9881"; $timestampBefore = 1641206011000; CrispClient->websiteConversations->getMessages(websiteId, sessionId, $timestampBefore); ``` ``` -------------------------------- ### authenticate() Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/CLIENT.md Sets up HTTP Basic authentication using an API token keypair. This is a prerequisite for most API operations. ```APIDOC ## authenticate() ### Description Sets up HTTP Basic authentication with the provided API token keypair. ### Method Signature `public function authenticate(string $identifier, string $key): void` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters Table | Parameter | Type | Required | Description | |-----------|------|----------|-------------| | `$identifier` | `string` | Yes | API token identifier (first part of keypair). | | `$key` | `string` | Yes | API token key (second part of keypair). | ### Returns `void` ### Throws None ### Example ```php $client = new \Crisp\CrispClient(); $client->authenticate("7c3ef21c-1e04-41ce-8c06-5605c346f73e", "cc29e1a5086e428fcc6a697d5837a66d82808e65c5cce006fbf2191ceea80a0a"); ``` ``` -------------------------------- ### Get Conversation Metas Source: https://github.com/crisp-im/php-crisp-api/blob/master/EXAMPLES.md Retrieves metadata for a specific conversation. ```APIDOC ## Get Conversation Metas ### Description Retrieves metadata for a specific conversation. ### Method GET ### Endpoint /websites/{websiteId}/sessions/{sessionId}/meta ### Request Example ```php $websiteId = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc"; $sessionId = "session_700c65e1-85e2-465a-b9ac-ecb5ec2c9881"; CrispClient->websiteConversations->getMeta(websiteId, sessionId); ``` ``` -------------------------------- ### Create Website Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/API_ENDPOINTS.md Creates a new website within the Crisp system. ```APIDOC ## POST /website ### Description Create website. ### Method POST ### Endpoint `/website` ``` -------------------------------- ### Get Conversation Source: https://github.com/crisp-im/php-crisp-api/blob/master/EXAMPLES.md Retrieves a specific conversation by its session ID. ```APIDOC ## Get a Conversation ### Description Retrieves a specific conversation by its session ID. ### Method GET ### Endpoint /websites/{websiteId}/sessions/{sessionId} ### Request Example ```php $websiteId = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc"; $sessionId = "session_700c65e1-85e2-465a-b9ac-ecb5ec2c9881"; CrispClient->websiteConversations->getOne(websiteId, sessionId); ``` ``` -------------------------------- ### Create Website with PHP Crisp API Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/OTHER_RESOURCES.md Use this method to create a new website. Provide website name and optionally a domain URL. ```php $website = $client->website->create([ "name" => "My Website", "domain" => "https://example.com" ]); echo $website['website_id']; ``` -------------------------------- ### Get Website Operator Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/API_ENDPOINTS.md Retrieves details for a specific operator of a website. ```APIDOC ## GET website/{websiteId}/operator/{operatorId} ### Description Gets the details of a specific operator for a given website. ### Method GET ### Endpoint `/website/{websiteId}/operator/{operatorId}` ### Parameters #### Path Parameters - **websiteId** (string) - Required - The ID of the website. - **operatorId** (string) - Required - The ID of the operator to retrieve. ``` -------------------------------- ### initiateOne() Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/WEBSITE_CONVERSATIONS.md Initiates a conversation with an existing session on a website. ```APIDOC ## initiateOne() ### Description Initiates a conversation with an existing session on a website. ### Method POST ### Endpoint /websites/{websiteId}/conversations/{sessionId}/initiate ### Parameters #### Path Parameters - **websiteId** (string) - Required - UUID of the website. - **sessionId** (string) - Required - Session ID to initiate. ### Request Example ```php $initiated = $client->websiteConversations->initiateOne("website_id", "session_id"); ``` ### Response #### Success Response (200) - **data** (object) - Initiated conversation data. #### Response Example ```json { "data": { "session_id": "session_id", "...other_conversation_details": "..." } } ``` ``` -------------------------------- ### Initialize CrispClient with Auto-Discovery Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/CLIENT.md Use this snippet to initialize the CrispClient when you want the library to automatically discover PSR-18 compatible HTTP clients and factories from your environment. This is the recommended approach for most use cases. ```php require __DIR__ . '/vendor/autoload.php'; // Using auto-discovery (recommended) $client = new Crisp\CrispClient(); ``` -------------------------------- ### Get Subscription Settings Source: https://github.com/crisp-im/php-crisp-api/blob/master/README.md Retrieves the settings for a specific plugin subscription on a website. ```APIDOC ## Get Subscription Settings ### Description Retrieves the settings for a specific plugin subscription on a website. ### Method GET ### Endpoint /websites/{website_id}/plugins/{plugin_id}/settings ### Parameters #### Path Parameters - **website_id** (string) - Required - The ID of the website. - **plugin_id** (string) - Required - The ID of the plugin. ### Request Example ```php $websiteId = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc"; $pluginId = "c64f3595-adee-425a-8d3a-89d47f7ed6bb"; CrispClient->pluginSubscriptions->getSubscriptionSettings(websiteId, pluginId); ``` ### Response #### Success Response (200) - settings (object) - The subscription settings. #### Response Example ```json { "data": { "chatbox": { "25": "#bbbbbb" } } } ``` ``` -------------------------------- ### Create Website Source: https://github.com/crisp-im/php-crisp-api/blob/master/EXAMPLES.md Creates a new website. Requires a parameters payload. ```php CrispClient->website->create(params); ``` -------------------------------- ### Get Subscription Details Source: https://github.com/crisp-im/php-crisp-api/blob/master/EXAMPLES.md Retrieves the details of a specific plugin subscription for a website. ```APIDOC ## GET /websites/{website_id}/plugin/subscriptions/{subscription_id} ### Description Retrieves the details of a specific plugin subscription for a website. ### Method GET ### Endpoint /websites/{website_id}/plugin/subscriptions/{subscription_id} ### Parameters #### Path Parameters - **website_id** (string) - Required - The ID of the website. - **subscription_id** (string) - Required - The ID of the subscription. ### Response #### Success Response (200) - **data** (object) - Contains the subscription details. ### Response Example { "data": { "id": "sub_id_1", "plugin_id": "plugin_abc", "status": "active", "created_at": "2023-01-01T10:00:00Z" } } ``` -------------------------------- ### Create A Website Source: https://github.com/crisp-im/php-crisp-api/blob/master/README.md Creates a new website within the Crisp account. Requires parameters to define the website's configuration. ```APIDOC ## Create A Website ### Description Creates a new website within the Crisp account. ### Method POST ### Endpoint `/websites` ### Parameters #### Request Body - **params** (object) - Required - An object containing the website configuration parameters. Specific fields depend on the API documentation. ### Request Example ```json { "params": { "name": "My New Website", "timezone": "Europe/Paris" } } ``` ### Response #### Success Response (201) - **data** (object) - Contains the details of the newly created website. - **website_id** (string) - The unique identifier for the new website. ``` -------------------------------- ### Initialize CrispClient with Custom HTTP Client Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/CLIENT.md This snippet shows how to initialize the CrispClient with a custom PSR-18 HTTP client. This is useful when you need specific configurations or a particular HTTP client implementation. ```php require __DIR__ . '/vendor/autoload.php'; // Using custom HTTP client $customHttpClient = new MyPSR18Client(); $client = new Crisp\CrispClient($customHttpClient); ``` -------------------------------- ### Get Website Availability Status Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/API_ENDPOINTS.md Retrieves the availability status for a specific website. ```APIDOC ## GET website/{websiteId}/availability/status ### Description Gets the availability status of a specific website. ### Method GET ### Endpoint `/website/{websiteId}/availability/status` ### Parameters #### Path Parameters - **websiteId** (string) - Required - The ID of the website to check availability status for. ``` -------------------------------- ### Get Website Verification Key Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/API_ENDPOINTS.md Retrieves the verification key for a specific website. ```APIDOC ## GET website/{websiteId}/verify/key ### Description Gets the verification key for a specific website. ### Method GET ### Endpoint `/website/{websiteId}/verify/key` ### Parameters #### Path Parameters - **websiteId** (string) - Required - The ID of the website to retrieve the verification key for. ``` -------------------------------- ### Authenticate with Crisp API using PHP Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/QUICK_START.md Initialize the Crisp client and authenticate using credentials from environment variables. Always set the tier before authenticating and authenticate only once during initialization. ```php $client = new \Crisp\CrispClient(); $client->setTier(getenv('CRISP_TIER')); $client->authenticate( getenv('CRISP_TOKEN_ID'), getenv('CRISP_TOKEN_KEY') ); ``` -------------------------------- ### Set Up Environment Variables for Crisp API Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/QUICK_START.md Configure your environment variables with your Crisp API credentials. Use the plugin tier for most integrations and ensure your token pairs are kept secure. ```bash # .env CRISP_TIER=plugin CRISP_TOKEN_ID=7c3ef21c-1e04-41ce-8c06-5605c346f73e CRISP_TOKEN_KEY=cc29e1a5086e428fcc6a697d5837a66d82808e65c5cce006fbf2191ceea80a0a ``` -------------------------------- ### Get Conversation Original Message Source: https://github.com/crisp-im/php-crisp-api/blob/master/README.md Retrieves a specific original message from a conversation. ```APIDOC ## Get Conversation Original Message ### Description Retrieves a specific original message from a conversation. ### Method GET ### Endpoint /websites/{websiteId}/conversations/{sessionId}/messages/{originalId} ### Parameters #### Path Parameters - **websiteId** (string) - Required - The ID of the website. - **sessionId** (string) - Required - The ID of the conversation session. - **originalId** (string) - Required - The ID of the original message. ### Response #### Success Response (200) - **data** (object) - The original message object. ``` -------------------------------- ### Create Website Source: https://github.com/crisp-im/php-crisp-api/blob/master/EXAMPLES.md Creates a new website within the Crisp account. ```APIDOC ## POST /websites ### Description Creates a new website within the Crisp account. ### Method POST ### Endpoint /websites ### Parameters #### Request Body - **params** (object) - Required - Parameters for creating the website. - **name** (string) - Required - The name of the website. - **timezone** (string) - Required - The timezone of the website (e.g., 'Europe/Paris'). - **locale** (string) - Required - The locale of the website (e.g., 'en'). ### Request Example { "params": { "name": "My New Website", "timezone": "Europe/Paris", "locale": "en" } } ### Response #### Success Response (201) - **data** (object) - Contains the details of the newly created website. ### Response Example { "data": { "website_id": "8c842203-7ed8-4e29-a608-7cf78a7d2fcc", "name": "My New Website", "timezone": "Europe/Paris", "locale": "en" } } ``` -------------------------------- ### Get User Profile Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/QUICK_START.md Retrieves the profile information for the currently authenticated user. ```APIDOC ## Getting User Profile ### Description Retrieves the profile of the current user. ### Method ```php $profile = $client->userProfile->get(); echo $profile['email']; echo $profile['first_name']; echo $profile['last_name']; ``` ``` -------------------------------- ### Subscribe a Website to a Plugin Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/OTHER_RESOURCES.md Initiate a subscription for a website to a specific plugin. This action requires the website ID and the plugin ID. ```php $subscription = $client->pluginSubscriptions->subscribeWebsiteToPlugin( "website_id", "plugin_id" ); ``` -------------------------------- ### Get messages Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/API_ENDPOINTS.md Retrieves messages from a specific conversation, with an option to filter by timestamp. ```APIDOC ## GET /website/{websiteId}/conversation/{sessionId}/messages?timestamp_before={ts} ### Description Get messages from a specific conversation, with an option to retrieve messages before a certain timestamp. ### Method GET ### Endpoint `/website/{websiteId}/conversation/{sessionId}/messages` ### Parameters #### Path Parameters - **websiteId** (string) - Required - The ID of the website. - **sessionId** (string) - Required - The ID of the conversation session. #### Query Parameters - **timestamp_before** (integer) - Optional - Unix timestamp to retrieve messages before. ``` -------------------------------- ### Resource Initialization (Factory Pattern) Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/ARCHITECTURE.md The CrispClient constructor utilizes the Factory pattern to create and assign resource instances, enabling lazy loading and convenient property access. ```php $this->websiteConversations = new WebsiteConversations($this); $this->websitePeople = new WebsitePeople($this); // ... ``` -------------------------------- ### Get Original Message Source: https://github.com/crisp-im/php-crisp-api/blob/master/EXAMPLES.md Retrieves a specific original message within a conversation. ```APIDOC ## Get an Original Message in Conversation ### Description Retrieves a specific original message within a conversation. ### Method GET ### Endpoint /websites/{websiteId}/sessions/{sessionId}/message/{originalId} ### Request Example ```php $websiteId = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc"; $sessionId = "session_700c65e1-85e2-465a-b9ac-ecb5ec2c9881"; $originalId = "2325a3c0-9b47-4fc6-b00e-111b752e44cd"; CrispClient->websiteConversations->getOriginalMessage(websiteId, sessionId, $originalId); ``` ``` -------------------------------- ### Schedule Reminder Request Body Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/API_ENDPOINTS.md Example of a request body for scheduling a reminder. ```APIDOC ## POST /reminders ### Description Schedules a reminder for a conversation. ### Method POST ### Endpoint /reminders ### Request Body - **date** (string) - Required - The date and time for the reminder in ISO 8601 format. - **note** (string) - Optional - A note for the reminder. ### Request Example ```json { "date": "2024-12-25T15:30:00Z", "note": "Follow up with customer" } ``` ``` -------------------------------- ### Initialize Crisp Client with Custom HTTP Client Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/CONFIGURATION.md Instantiate the Crisp client with your own implementations of HttpClient, RequestFactory, and StreamFactory. This provides full control over the HTTP communication layer. ```php use Http\Client\HttpClient; use Http\Message\RequestFactory; use Http\Message\StreamFactory; $httpClient = new MyCustomHttpClient(); $requestFactory = new MyRequestFactory(); $streamFactory = new MyStreamFactory(); $client = new \Crisp\CrispClient( $httpClient, $requestFactory, $streamFactory ); ``` -------------------------------- ### Get People Data Source: https://github.com/crisp-im/php-crisp-api/blob/master/README.md Retrieves all data associated with a specific person on a given website. ```APIDOC ## Get People Data ### Description Retrieves all data associated with a specific person on a given website. ### Method GET ### Endpoint /websites/{website_id}/people/{people_id} ### Parameters #### Path Parameters - **website_id** (string) - Required - The ID of the website. - **people_id** (string) - Required - The ID of the person. ### Request Example ```php $websiteId = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc"; $peopleId = "c5a2f70c-f605-4648-b47f-8c39d4b03a50"; CrispClient->websitePeople->getPeopleData(websiteId, peopleId); ``` ### Response #### Success Response (200) - **data** (object) - Contains all data associated with the people profile. ``` -------------------------------- ### Authentication Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/INDEX.md This snippet shows how to initialize the Crisp client and authenticate using a token. You can set the tier to 'plugin', 'user', or 'website' depending on your access level. ```APIDOC ## Authentication ### Description Initialize the Crisp client and authenticate your API requests using a token ID and token key. You can specify the access tier ('plugin', 'user', or 'website') to control the scope of your access. ### Method ```php $client = new \Crisp\CrispClient(); $client->setTier("plugin"); // or "user" or "website" $client->authenticate("token_id", "token_key"); ``` ### Tier Options - `plugin`: For third-party plugins (most common). - `website`: For single website access. - `user`: For full account access. ``` -------------------------------- ### Resource Constructor (Dependency Injection) Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/ARCHITECTURE.md Resources implement Dependency Injection by receiving the parent CrispClient instance in their constructor, granting access to HTTP transport methods. ```php class Resource { protected $crisp; public function __construct($parent) { $this->crisp = $parent; } } ``` -------------------------------- ### Get Plugin Subscription Settings Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/API_ENDPOINTS.md Retrieves the settings for a specific plugin subscription on a website. ```APIDOC ## GET /plugins/subscription/{websiteId}/{pluginId}/settings ### Description Get the settings for a specific plugin subscription. ### Method GET ### Endpoint `/plugins/subscription/{websiteId}/{pluginId}/settings` ### Parameters #### Path Parameters - **websiteId** (string) - Required - The ID of the website. - **pluginId** (string) - Required - The ID of the plugin. ``` -------------------------------- ### getList Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/WEBSITE_OPERATORS.md List all operators for a website. ```APIDOC ## getList Website Operators ### Description List all operators for a website. ### Method GET ### Endpoint /websites/{websiteId}/operators ### Parameters #### Path Parameters - **websiteId** (string) - Required - UUID of the website. ### Response #### Success Response (200) - **array** – List of operator objects. ### Request Example ```php $operators = $client->websiteOperators->getList("8c842203-7ed8-4e29-a608-7cf78a7d2fcc"); foreach ($operators as $operator) { echo $operator['user_id']; } ``` ``` -------------------------------- ### Get Messages in Conversation Source: https://github.com/crisp-im/php-crisp-api/blob/master/README.md Retrieves all messages within a specific conversation up to a given timestamp. ```APIDOC ## Get Messages in Conversation ### Description Retrieves all messages within a specific conversation up to a given timestamp. ### Method GET ### Endpoint /websites/{websiteId}/conversations/{sessionId}/messages ### Parameters #### Path Parameters - **websiteId** (string) - Required - The ID of the website. - **sessionId** (string) - Required - The ID of the conversation session. #### Query Parameters - **timestamp_before** (integer) - Optional - A Unix timestamp in milliseconds to fetch messages before. ### Response #### Success Response (200) - **data** (array) - A list of message objects. ``` -------------------------------- ### CrispClient Constructor Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/CLIENT.md Initializes the Crisp API client with optional PSR-18 HTTP client, request factory, and stream factory. Factories are auto-discovered if not provided. ```APIDOC ## Constructor ### Description Initializes the Crisp API client with optional PSR-18 HTTP client, request factory, and stream factory. If not provided, factories are auto-discovered from the environment. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```php require __DIR__ . '/vendor/autoload.php'; // Using auto-discovery (recommended) $client = new \Crisp\CrispClient(); // Using custom HTTP client $customHttpClient = new MyPSR18Client(); $client = new \Crisp\CrispClient($customHttpClient); ``` ### Response #### Success Response (200) Instance of `CrispClient` #### Response Example ```php // No specific response example for constructor, returns an instance of CrispClient ``` ``` -------------------------------- ### Get A Conversation Source: https://github.com/crisp-im/php-crisp-api/blob/master/README.md Retrieves a specific conversation using its website ID and session ID. ```APIDOC ## Get A Conversation ### Description Retrieves a specific conversation using its website ID and session ID. ### Method `CrispClient->websiteConversations->getOne(websiteId, sessionId)` ### Parameters #### Path Parameters - **websiteId** (string) - Required - The ID of the website. - **sessionId** (string) - Required - The ID of the session. ### Request Example ```php $websiteId = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc"; $sessionId = "session_700c65e1-85e2-465a-b9ac-ecb5ec2c9881"; CrispClient->websiteConversations->getOne(websiteId, sessionId); ``` ``` -------------------------------- ### Prepare URL Query Parameters Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/ARCHITECTURE.md This code iterates through a predefined mapping to construct URL query parameters from method arguments. It filters out empty values before appending them to the resource URL. ```php // In method: foreach ($this::FIND_WITH_SEARCH_QUERY_PARAMETERS as &$parameter) { $parameterValue = get_defined_vars()[$parameter[0]]; if ($parameterValue != "") { $query[$parameter[1]] = $parameterValue; } } $resourceUrl = "website/$websiteId/conversations/$pageNumber" . $this->prepareQuery($query); ``` -------------------------------- ### Get People Profile Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/API_ENDPOINTS.md Retrieves a specific people profile by its ID for a given website. ```APIDOC ## GET /website/{websiteId}/people/profile/{peopleId} ### Description Retrieves a specific people profile by its ID. ### Method GET ### Endpoint `/website/{websiteId}/people/profile/{peopleId}` ### Parameters #### Path Parameters - **websiteId** (string) - Required - The ID of the website. - **peopleId** (string) - Required - The ID of the people profile. ``` -------------------------------- ### Create New WebsitePeople Profile (PHP) Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/WEBSITE_PEOPLE.md Create a new person profile with email and optional person details like nickname and avatar. Returns the newly generated people ID. ```php $params = [ "email" => "valerian@crisp.chat", "person" => [ "nickname" => "Valerian Saliou", "avatar" => "https://example.com/avatar.jpg" ] ]; $profile = $client->websitePeople->createNewPeopleProfile("website_id", $params); echo $profile['people_id']; // Newly generated people ID ``` -------------------------------- ### Assign Routing Request Body Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/API_ENDPOINTS.md Example of a request body for assigning a conversation to a user. ```APIDOC ## POST /routing/assign ### Description Assigns a conversation to a specific user. ### Method POST ### Endpoint /routing/assign ### Request Body - **assigned** (object) - Required - Information about the user to assign. - **user_id** (string) - Required - The ID of the user. ### Request Example ```json { "assigned": { "user_id": "uuid" } } ``` ``` -------------------------------- ### Send Message Request Body Source: https://github.com/crisp-im/php-crisp-api/blob/master/_autodocs/API_ENDPOINTS.md Example of a request body for sending a text message. ```APIDOC ## POST /messages ### Description Sends a message to a conversation. ### Method POST ### Endpoint /messages ### Request Body - **type** (string) - Required - The type of message (e.g., "text"). - **from** (string) - Required - The sender of the message (e.g., "operator"). - **origin** (string) - Required - The origin of the message (e.g., "chat"). - **content** (string) - Required - The message content. ### Request Example ```json { "type": "text", "from": "operator", "origin": "chat", "content": "Hello!" } ``` ```