### Install SendPulse REST API PHP Client via Composer Source: https://github.com/sendpulse/sendpulse-rest-api-php/blob/master/README.md This snippet shows the Composer command to install the SendPulse REST API client library for PHP. It ensures the necessary package is added to your project for API integration. ```bash composer require sendpulse/rest-api ``` -------------------------------- ### POST /events/name/{event_name} Source: https://github.com/sendpulse/sendpulse-rest-api-php/blob/master/README.md Starts an event for Automation360, optionally including product information. ```APIDOC ## POST /events/name/{event_name} ### Description Starts an event for Automation360. ### Method POST ### Endpoint /events/name/{event_name} ### Parameters #### Path Parameters - **event_name** (string) - Required - The name of the event to start. #### Request Body - **email** (string) - Optional - The email address associated with the event. - **phone** (string) - Optional - The phone number associated with the event. - **products** (array) - Optional - An array of product objects. - **id** (string) - Optional - The product ID. - **name** (string) - Optional - The product name. ### Request Example ```php post('events/name/my_event_name', [ "email" => "test@test.com", "phone" => "+123456789", "products" => [ [ "id" => "id value", "name" => "name value" ] ] ]); var_dump($startEventResult); ?> ``` ### Response #### Success Response (200) - **Returns** the result of starting the event. ``` -------------------------------- ### Send GET Request: List Mailing Lists with SendPulse PHP API Source: https://github.com/sendpulse/sendpulse-rest-api-php/blob/master/README.md Demonstrates how to send a GET request to retrieve a list of mailing lists from SendPulse using the PHP SDK. It includes API client initialization and error handling for the request. ```php get('addressbooks', [ 'limit' => 100, 'offset' => 0 ]); var_dump($addressBooks); } catch (ApiClientException $e) { var_dump([ 'message' => $e->getMessage(), 'http_code' => $e->getCode(), 'response' => $e->getResponse(), 'curl_errors' => $e->getCurlErrors(), 'headers' => $e->getHeaders() ]); } ``` -------------------------------- ### Send POST Request: Create CRM Deal with SendPulse PHP API Source: https://github.com/sendpulse/sendpulse-rest-api-php/blob/master/README.md Provides an example of creating a new deal in SendPulse CRM via a POST request, specifying deal details like pipeline, step, responsible person, name, price, currency, contact, and attachments. Includes robust error handling. ```php post('crm/v1/deals', [ "pipelineId" => 0, "stepId" => 0, "responsibleId" => 0, "name" => "string", "price" => 0, "currency" => "string", "sourceId" => 0, "contact" => [ 0 ], "attributes" => [ [ "attributeId" => 0, "value" => "string" ] ], "attachments" => [ "https://link-to-file.com/file.jpg" ] ]); var_dump($crmCreateDeal); } catch (ApiClientException $e) { var_dump([ 'message' => $e->getMessage(), 'http_code' => $e->getCode(), 'response' => $e->getResponse(), 'curl_errors' => $e->getCurlErrors(), 'headers' => $e->getHeaders() ]); } ``` -------------------------------- ### GET /addressbooks Source: https://github.com/sendpulse/sendpulse-rest-api-php/blob/master/README.md Retrieves a list of mailing lists with optional limit and offset parameters. ```APIDOC ## GET /addressbooks ### Description Retrieves a list of mailing lists. ### Method GET ### Endpoint /addressbooks ### Parameters #### Query Parameters - **limit** (integer) - Optional - The maximum number of address books to return. - **offset** (integer) - Optional - The number of address books to skip. ### Request Example ```php get('addressbooks', [ 'limit' => 100, 'offset' => 0 ]); var_dump($addressBooks); ?> ``` ### Response #### Success Response (200) - **Returns** a list of mailing books. ``` -------------------------------- ### Send POST Request: Start Automation360 Event with SendPulse PHP API Source: https://github.com/sendpulse/sendpulse-rest-api-php/blob/master/README.md Shows how to trigger an Automation360 event by sending a POST request with event data, including email, phone, and associated products, using the SendPulse PHP SDK. Proper error handling is included. ```php post('events/name/my_event_name', [ "email" => "test@test.com", "phone" => "+123456789", "products" => [ [ "id" => "id value", "name" => "name value" ] ] ]); var_dump($startEventResult); } catch (ApiClientException $e) { var_dump([ 'message' => $e->getMessage(), 'http_code' => $e->getCode(), 'response' => $e->getResponse(), 'curl_errors' => $e->getCurlErrors(), 'headers' => $e->getHeaders() ]); } ``` -------------------------------- ### Send PATCH Request: Edit Scheduled Campaign with SendPulse PHP API Source: https://github.com/sendpulse/sendpulse-rest-api-php/blob/master/README.md Provides an example of sending a PATCH request to update details of a scheduled campaign, such as name, sender information, and send date, using the SendPulse PHP SDK. It includes comprehensive error logging. ```php patch('campaigns/333333', [ "name" => "My_API_campaign", "sender_name" => "sender", "sender_email" => "sender@test.com", "subject" => "Hello customer", "template_id" => 351594, "send_date" => "2023-10-21 11:45:00" ]); var_dump($editScheduledCampaignResult); } catch (\Sendpulse\RestApi\ApiClientException $e) { var_dump([ 'message' => $e->getMessage(), 'http_code' => $e->getCode(), 'response' => $e->getResponse(), 'curl_errors' => $e->getCurlErrors(), 'headers' => $e->getHeaders() ]); } ``` -------------------------------- ### Send DELETE Request: Remove Emails from Mailing List with SendPulse PHP API Source: https://github.com/sendpulse/sendpulse-rest-api-php/blob/master/README.md Demonstrates how to send a DELETE request to remove specific emails from a mailing list using the SendPulse PHP SDK. The example shows how to specify the emails to be removed and includes error handling. ```php delete('addressbooks/33333/emails', [ 'emails' => ['test@test.com'] ]); var_dump($removeEmailsResult); } catch (ApiClientException $e) { var_dump([ 'message' => $e->getMessage(), 'http_code' => $e->getCode(), 'response' => $e->getResponse(), 'curl_errors' => $e->getCurlErrors(), 'headers' => $e->getHeaders() ]); } ``` -------------------------------- ### POST /crm/v1/deals Source: https://github.com/sendpulse/sendpulse-rest-api-php/blob/master/README.md Creates a new deal in the CRM system. ```APIDOC ## POST /crm/v1/deals ### Description Creates a new deal in the CRM system. ### Method POST ### Endpoint /crm/v1/deals ### Parameters #### Request Body - **pipelineId** (integer) - Required - The ID of the pipeline. - **stepId** (integer) - Required - The ID of the step within the pipeline. - **responsibleId** (integer) - Required - The ID of the responsible user. - **name** (string) - Required - The name of the deal. - **price** (number) - Required - The price of the deal. - **currency** (string) - Required - The currency of the deal. - **sourceId** (integer) - Required - The ID of the deal source. - **contact** (array) - Required - An array of contact IDs associated with the deal. - **attributes** (array) - Optional - An array of deal attributes. - **attributeId** (integer) - Required - The ID of the attribute. - **value** (string) - Required - The value of the attribute. - **attachments** (array) - Optional - An array of URLs for attached files. ### Request Example ```php post('crm/v1/deals', [ "pipelineId" => 0, "stepId" => 0, "responsibleId" => 0, "name" => "string", "price" => 0, "currency" => "string", "sourceId" => 0, "contact" => [ 0 ], "attributes" => [ [ "attributeId" => 0, "value" => "string" ] ], "attachments" => [ "https://link-to-file.com/file.jpg" ] ]); var_dump($crmCreateDeal); ?> ``` ### Response #### Success Response (200) - **Returns** the result of the CRM deal creation operation. ``` -------------------------------- ### PHP: Send WhatsApp Template Message via SendPulse API Source: https://github.com/sendpulse/sendpulse-rest-api-php/blob/master/README.md Sends a WhatsApp template message to a specified contact using the SendPulse API. It requires a bot ID, phone number, and template details including name and language. Error handling is included for API client exceptions. ```php /** * Example: Whatsapp send a template message to the specified contact */ try { $sendTemplateByPhoneResult = $apiClient->post('whatsapp/contacts/sendTemplateByPhone', [ "bot_id" => "xxxxxxxxxxxxxxxxxxxxxxxx", "phone" => "380931112233", "template" => [ "name" => "thanks_for_buying", "language" => [ "code" => "en" ], "components" => [] ] ]); var_dump($sendTemplateByPhoneResult); } catch (ApiClientException $e) { var_dump([ 'message' => $e->getMessage(), 'http_code' => $e->getCode(), 'response' => $e->getResponse(), 'curl_errors' => $e->getCurlErrors(), 'headers' => $e->getHeaders() ]); } ``` -------------------------------- ### Send POST Request: Add Emails to Mailing List with SendPulse PHP API Source: https://github.com/sendpulse/sendpulse-rest-api-php/blob/master/README.md Shows how to send a POST request to add new emails, including custom variables, to a specific mailing list using the SendPulse PHP SDK. It details the request structure and exception handling. ```php post('addressbooks/33333/emails', [ 'emails' => [ [ 'email' => 'test_email@test.com', 'variables' => [ 'phone' => '+123456789', 'my_var' => 'my_var_value' ] ], [ 'email' => 'email_test@test.com', 'variables' => [ 'phone' => '+987654321', 'my_var' => 'my_var_value' ] ] ] ]); var_dump($addEmailsResult); } catch (ApiClientException $e) { var_dump([ 'message' => $e->getMessage(), 'http_code' => $e->getCode(), 'response' => $e->getResponse(), 'curl_errors' => $e->getCurlErrors(), 'headers' => $e->getHeaders() ]); } ``` -------------------------------- ### POST /addressbooks/{id}/emails Source: https://github.com/sendpulse/sendpulse-rest-api-php/blob/master/README.md Adds new emails to a specified mailing list with associated variables. ```APIDOC ## POST /addressbooks/{id}/emails ### Description Adds new emails to a specified mailing list. ### Method POST ### Endpoint /addressbooks/{id}/emails ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the address book to add emails to. #### Request Body - **emails** (array) - Required - An array of email objects to add. - **email** (string) - Required - The email address. - **variables** (object) - Optional - Key-value pairs for custom variables. ### Request Example ```php post('addressbooks/33333/emails', [ 'emails' => [ [ 'email' => 'test_email@test.com', 'variables' => [ 'phone' => '+123456789', 'my_var' => 'my_var_value' ] ], [ 'email' => 'email_test@test.com', 'variables' => [ 'phone' => '+987654321', 'my_var' => 'my_var_value' ] ] ] ]); var_dump($addEmailsResult); ?> ``` ### Response #### Success Response (200) - **Returns** the result of the email addition operation. ``` -------------------------------- ### PUT /addressbooks/{id} Source: https://github.com/sendpulse/sendpulse-rest-api-php/blob/master/README.md Edits an existing mailing list by its ID. ```APIDOC ## PUT /addressbooks/{id} ### Description Edits an existing mailing list. ### Method PUT ### Endpoint /addressbooks/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the address book to edit. #### Request Body - **name** (string) - Required - The new name for the address book. ### Request Example ```php put('addressbooks/33333', [ 'name' => "New Name" ]); var_dump($addEmailsResult); ?> ``` ### Response #### Success Response (200) - **Returns** the result of the mailing list update operation. ``` -------------------------------- ### PATCH /campaigns/{id} Source: https://github.com/sendpulse/sendpulse-rest-api-php/blob/master/README.md Edits a scheduled campaign by its ID. ```APIDOC ## PATCH /campaigns/{id} ### Description Edits a scheduled campaign. ### Method PATCH ### Endpoint /campaigns/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the campaign to edit. #### Request Body - **name** (string) - Optional - The new name for the campaign. - **sender_name** (string) - Optional - The sender's name. - **sender_email** (string) - Optional - The sender's email address. - **subject** (string) - Optional - The subject of the campaign. - **template_id** (integer) - Optional - The ID of the template to use. - **send_date** (string) - Optional - The scheduled send date and time (YYYY-MM-DD HH:MM:SS). ### Request Example ```php patch('campaigns/333333', [ "name" => "My_API_campaign", "sender_name" => "sender", "sender_email" => "sender@test.com", "subject" => "Hello customer", "template_id" => 351594, "send_date" => "2023-10-21 11:45:00" ]); var_dump($editScheduledCampaignResult); ?> ``` ### Response #### Success Response (200) - **Returns** the result of the campaign update operation. ``` -------------------------------- ### Send PUT Request: Edit Mailing List with SendPulse PHP API Source: https://github.com/sendpulse/sendpulse-rest-api-php/blob/master/README.md Illustrates how to send a PUT request to modify an existing mailing list, such as renaming it, using the SendPulse PHP SDK. It includes the necessary parameters and error handling. ```php put('addressbooks/33333', [ 'name' => "New Name" ]); var_dump($addEmailsResult); } catch (ApiClientException $e) { var_dump([ 'message' => $e->getMessage(), 'http_code' => $e->getCode(), 'response' => $e->getResponse(), 'curl_errors' => $e->getCurlErrors(), 'headers' => $e->getHeaders() ]); } ``` -------------------------------- ### POST /whatsapp/contacts/sendTemplateByPhone Source: https://github.com/sendpulse/sendpulse-rest-api-php/blob/master/README.md Sends a pre-defined template message to a specified phone number via WhatsApp. This is useful for notifications, confirmations, or customer service interactions. ```APIDOC ## POST /whatsapp/contacts/sendTemplateByPhone ### Description Sends a pre-defined template message to a specified phone number via WhatsApp. This is useful for notifications, confirmations, or customer service interactions. ### Method POST ### Endpoint /whatsapp/contacts/sendTemplateByPhone ### Parameters #### Request Body - **bot_id** (string) - Required - The ID of the WhatsApp bot. - **phone** (string) - Required - The recipient's phone number. - **template** (object) - Required - The template message details. - **name** (string) - Required - The name of the template. - **language** (object) - Required - The language of the template. - **code** (string) - Required - The language code (e.g., "en"). - **components** (array) - Optional - Components of the template message (e.g., buttons, media). ### Request Example ```json { "bot_id": "xxxxxxxxxxxxxxxxxxxxxxxx", "phone": "380931112233", "template": { "name": "thanks_for_buying", "language": { "code": "en" }, "components": [] } } ``` ### Response #### Success Response (200) - **result** (object) - Details of the sent message. - **message** (string) - Confirmation message. #### Response Example ```json { "result": { "message_id": "message_id_123", "status": "sent" }, "message": "Message sent successfully." } ``` #### Error Response (e.g., 4xx, 5xx) - **message** (string) - Error message. - **http_code** (integer) - HTTP status code. - **response** (object) - API response details. - **curl_errors** (array) - cURL error details, if any. - **headers** (object) - Response headers. ``` -------------------------------- ### DELETE /addressbooks/{id}/emails Source: https://github.com/sendpulse/sendpulse-rest-api-php/blob/master/README.md Deletes specified emails from a mailing list. ```APIDOC ## DELETE /addressbooks/{id}/emails ### Description Deletes specified emails from a mailing list. ### Method DELETE ### Endpoint /addressbooks/{id}/emails ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the address book from which to delete emails. #### Request Body - **emails** (array) - Required - An array of email addresses to delete. ### Request Example ```php delete('addressbooks/33333/emails', [ 'emails' => ['test@test.com'] ]); var_dump($removeEmailsResult); ?> ``` ### Response #### Success Response (200) - **Returns** the result of the email deletion operation. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.