### Get Contacts Data (cURL Example) Source: https://cartsguru.gitbook.io/custom-integration/carts-guru-integration/contact-management This cURL command demonstrates how to make a GET request to the Carts Guru API to retrieve contact data. It includes the necessary site ID as a query parameter and an authorization key in the headers. ```bash curl -XGET https://api.carts.guru/contacts.csv?siteId=0000000-0000-0000-0000-0000000000 \ --header 'x-auth-key: 00000000000000000' ``` -------------------------------- ### Get Contacts Data (JavaScript Example) Source: https://cartsguru.gitbook.io/custom-integration/carts-guru-integration/contact-management This JavaScript code snippet demonstrates the structure of a successful response when retrieving contact data from the Carts Guru API. It includes details like contact ID, site ID, and communication preferences. ```javascript { "data": [{ "_id": "Contact's id", "siteId": "Your site id", "firstName": "undefined" "lastName": "undefined", "addresses": "undefined", "phoneNumbers": "undefined", "emails": "undefined", "communicationPreferences": { "sms": "Default", "call": "Optin", "email": "Optout" } }] } ``` -------------------------------- ### Import CSV File (cURL Example) Source: https://cartsguru.gitbook.io/custom-integration/carts-guru-integration/contact-management This cURL command shows how to import a CSV file into the Carts Guru API using a PUT request. It specifies the site ID, authorization key, and sends the CSV file as form-data. ```bash curl -XPUT https://api.carts.guru/contacts.csv?siteId=0000000-0000-0000-0000-000000 \ --header 'x-auth-key: 00000000000000000' \ --form "file=@valid.csv;type=application/csv" ``` -------------------------------- ### API Error Responses (JavaScript Examples) Source: https://cartsguru.gitbook.io/custom-integration/carts-guru-integration/contact-management These JavaScript code snippets illustrate common error responses from the Carts Guru API. They cover scenarios such as an invalid action being requested (400 Bad Request) and a contact not being found (404 Not Found). ```javascript { "statusCode": "400", "error": "Bad Request", "message": "Action: jump Not found" } ``` ```javascript { "statusCode": "404", "error": 'Not Found', "message": 'Contact: x Not found' } ``` -------------------------------- ### Carts API Data Model Example Source: https://cartsguru.gitbook.io/custom-integration/carts-guru-integration/carts This JSON data model defines the structure for cart creation and update requests. It includes fields for site information, cart totals, buyer details, and a list of items within the cart. All fields are required unless otherwise specified. ```json { "siteId": "" // SiteId is part of configuration "id": "", // Cart reference (use SessionId if you don’t have specific ID) "totalATI": 0, // Total price including taxes "totalET": 0, // Total price excluding taxes "currency": "", // (optional) Currency, ISO code "accountId": "", // Account id of the buyer (we advise to use the email address) "ip": "", // (optional) Visitor IP address "recoverUrl": "", // Link to recover the cart (link to cart checkout with security token included). If you do not have a way to recover the cart the best will be to send the url to the checkout page "civility": "", // (optional) Use string in this list : 'mister','madam','miss' "lastname": "", // (optional) Lastname "firstname": "", // (optional but really important) Firstname "email": "", // Email address "homePhoneNumber": "", // (optional) Landline phone number "mobilePhoneNumber": "", // (optional) Mobile phone number "phoneNumber": "", // Phone number of buyer, if you don’t know the kind of it (optional) "countryCode": "", // (Required) if you send any phone number. Country ISO code of the buyer, 2 or 3 letters. "language": "", // (optional) language of the customer, can be different from the country: ISO code and lower case ex: en,fr,es. "custom": { }, // (optional) Any custom fields you want to send with the cart. Standard fields are language (ISO code), customerGroup and isNewCustomer ​"buyerAcceptsMarketing": true, //(optional) True or false, depending if the customer wants to receive marketing //Details of each items "items": [ { "id": "", // SKU or product id "label": "", // Designation "quantity": 1, // Count "totalATI": 0, // Total price included taxes "totalET": 0, // Total price excluded taxes "url": "", // URL of product sheet "imageUrl": "", // Image URL of product, size should be min 150*150, max 180*180 "universe": "", // (optional) Main category of the product "category": "" // (optional) Sub category of the product, "custom": {} // (optional) Any custom fields you want to send with the cart in order to do specific segmentation on your retargating strategy } ] } ``` -------------------------------- ### Batch Contact Operations using Javascript Source: https://cartsguru.gitbook.io/custom-integration/data-apis/contacts/batch This Javascript snippet demonstrates how to perform batch operations on contacts via the Carts.Guru API. It utilizes the 'node-fetch' library to send POST requests with a JSON payload. The payload includes an array of actions, such as creating, updating, and deleting contacts identified by email, phone number, or account ID. Ensure you have 'node-fetch' installed and provide a valid authorization token. ```javascript import fetch from 'node-fetch' const res = await fetch(`https://api.carts.guru/contacts/v1/batch`, { method: 'POST', headers: { 'content-type': 'application/json', authorization: 'Basic c8l0ZS0xOjE1ODQwMzc4MTI6Q2wwWHNoVHLaUFdHaDR0ZkZpVkdlbFlaMUxpeDdtdVR6SnBDUndHZlgydz0=' }, body: JSON.stringify({ actions: [ { delete: { email: 'hi@carts.guru' } }, { delete: { phoneNumber: '41343432413' } }, { delete: { accountId: 'accountId-1' } }, { create: { phoneNumber: '14158888888', email: 'bobsburgers@carts.guru', firstname: 'bob', lastname: 'burger' } }, { update: { accountId: '7777777', email: 'bern777@carts.guru', phoneNumber: '14157777777', firstname: 'Bern' } } ] }) }) ``` -------------------------------- ### Get Contact Information using Javascript Source: https://cartsguru.gitbook.io/custom-integration/carts-guru-integration/contact-management Retrieves information for a single contact using their siteId and accountId. Requires an x-auth-key header for authentication. Returns contact details or an error object. ```javascript { "data": [{ "_id": "Contact's id", "siteId": "Your site id", "firstName": "Contacts first name" "lastName": "Contacts last name", "addresses": [{ "title": "Residence type", "line1": "", "line2": "", "postcode": "Contacts zipcode", "city": "Contacts city", "country": "Contacts Country" }], "phoneNumbers": [{ "title": "type", "phoneNumber": "Contacts phone number" }], "emails": ["Contacts email"], "communicationPreferences": { "sms": "Default", "call": "Optin", "email": "Optout" } }] } ``` ```javascript {} ``` -------------------------------- ### Untitled No description -------------------------------- ### Import CSV File Success Response (JavaScript Example) Source: https://cartsguru.gitbook.io/custom-integration/carts-guru-integration/contact-management This JavaScript object represents a successful response when importing a CSV file containing contact information into the Carts Guru system. It indicates the operation was successful. ```javascript { status: "success" } ``` -------------------------------- ### Get Contact Source: https://cartsguru.gitbook.io/custom-integration/carts-guru-integration/contact-management Retrieves information for a single contact based on siteId and accountId. ```APIDOC ## GET /contacts ### Description This endpoint allows you to get the information for single contact. ### Method GET ### Endpoint https://api.carts.guru/contacts #### Query Parameters - **siteId** (string) - Required - Your site ID (provided at integration). - **accountId** (string) - Required - The contact's ID in your website. #### Headers - **x-auth-key** (string) - Required - Personal token to access Carts Guru API (provided at integration). ### Request Example ```json { "siteId": "YOUR_SITE_ID", "accountId": "CONTACT_ACCOUNT_ID" } ``` ### Response #### Success Response (200) - **data** (array) - An array of contact objects. - **_id** (string) - Contact's ID. - **siteId** (string) - Your site ID. - **firstName** (string) - Contacts first name. - **lastName** (string) - Contacts last name. - **addresses** (array) - Array of address objects. - **title** (string) - Residence type. - **line1** (string) - Address line 1. - **line2** (string) - Address line 2. - **postcode** (string) - Contacts zipcode. - **city** (string) - Contacts city. - **country** (string) - Contacts Country. - **phoneNumbers** (array) - Array of phone number objects. - **title** (string) - Type of phone number. - **phoneNumber** (string) - Contacts phone number. - **emails** (array) - Array of email addresses. - **communicationPreferences** (object) - Communication preferences for the contact. - **sms** (string) - SMS preference (e.g., Default, Optin, Optout). - **call** (string) - Call preference (e.g., Default, Optin, Optout). - **email** (string) - Email preference (e.g., Default, Optin, Optout). #### Response Example (200) ```json { "data": [{ "_id": "Contact's id", "siteId": "Your site id", "firstName": "Contacts first name", "lastName": "Contacts last name", "addresses": [{ "title": "Residence type", "line1": "", "line2": "", "postcode": "Contacts zipcode", "city": "Contacts city", "country": "Contacts Country" }], "phoneNumbers": [{ "title": "type", "phoneNumber": "Contacts phone number" }], "emails": ["Contacts email"], "communicationPreferences": { "sms": "Default", "call": "Optin", "email": "Optout" } }] } ``` #### Error Response (401) - **message** (string) - Error message indicating invalid parameters. #### Response Example (401) ```json { "message": "Something in your request parameters is wrong." } ``` ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### GET /contacts.csv Source: https://cartsguru.gitbook.io/custom-integration/carts-guru-integration/contact-management Retrieves contact information from Carts Guru. Supports anonymizing contact data based on the 'cg_action' query parameter. ```APIDOC ## GET /contacts.csv ### Description Retrieves contact information from Carts Guru. Supports anonymizing contact data based on the 'cg_action' query parameter. ### Method GET ### Endpoint `/contacts.csv` ### Parameters #### Path Parameters None #### Query Parameters - **id** (string) - Required - The contacts _id from the Carts Guru document (see get method). - **cg_action** (string) - Required - Describes the action you want the Carts Guru API to perform on your contact ('anonymize' is the only one allowed). - **siteId** (string) - Required - Your site ID (provided at integration). #### Headers - **x-auth-key** (string) - Required - Personal token to access Carts Guru API (provided at integration). ### Request Example ```bash curl -XGET https://api.carts.guru/contacts.csv?siteId=0000000-0000-0000-0000-0000000000 \ --header 'x-auth-key: 00000000000000000' ``` ### Response #### Success Response (200) - **data** (array) - An array of contact objects. - **_id** (string) - The contact's ID. - **siteId** (string) - The site ID. - **firstName** (string) - The contact's first name (undefined if anonymized). - **lastName** (string) - The contact's last name (undefined if anonymized). - **addresses** (string) - The contact's addresses (undefined if anonymized). - **phoneNumbers** (string) - The contact's phone numbers (undefined if anonymized). - **emails** (string) - The contact's emails (undefined if anonymized). - **communicationPreferences** (object) - The contact's communication preferences. - **sms** (string) - SMS communication preference. - **call** (string) - Call communication preference. - **email** (string) - Email communication preference. #### Response Example ```json { "data": [{ "_id": "Contact's id", "siteId": "Your site id", "firstName": "undefined" "lastName": "undefined", "addresses": "undefined", "phoneNumbers": "undefined", "emails": "undefined", "communicationPreferences": { "sms": "Default", "call": "Optin", "email": "Optout" } }] } ``` #### Error Response (400) - **statusCode** (string) - The HTTP status code. - **error** (string) - The error type. - **message** (string) - A message describing the error. #### Error Response Example (400) ```json { "statusCode": "400", "error": "Bad Request", "message": "Action: jump Not found" } ``` #### Error Response (401) An empty JSON object is returned. #### Error Response Example (401) ```json {} ``` #### Error Response (404) - **statusCode** (string) - The HTTP status code. - **error** (string) - The error type. - **message** (string) - A message describing the error. #### Error Response Example (404) ```json { "statusCode": "404", "error": 'Not Found', "message": 'Contact: x Not found' } ``` ``` -------------------------------- ### Initialize Cartsguru Order Object and Script Source: https://cartsguru.gitbook.io/custom-integration/manual-integration/other Defines the structure for an order object, including item details and order status. It then demonstrates how to initialize the Cartsguru library with this order object and asynchronously load the Cartsguru bundle script. The script loading ensures the library is ready before initialization. ```javascript var order = { id: '', cartId: '', totalATI: 0, totalET: 0, currency: '', state: '', //Status of the order accountId: '', //Email address email: '', countryCode: '', // (Required) if you send any phone number. Country ISO code of the buyer, 2 or 3 letters. items: [{ id: '', // SKU or product id label: '', // Designation quantity: 0, // Count totalATI: 0, // Total price included taxes totalET: 0, // Total price excluded taxes url: '', // URL of product sheet imageUrl: '', // Image URL of the product, size should be min 150*150, max 180*180 }] }; // INIT CG('init', { order: order, //we don't set cart on confirmation page, because cart is now empty }); (function (d, s, id) { if (d.getElementById(id)) return; var t = d.getElementsByTagName(s)[0]; var cgs = d.createElement(s); cgs.id = id; cgs.src = 'https://t.carts.guru/bundle.js?sid={{SITE_ID}}'; t.parentNode.insertBefore(cgs, t); cgs.onload = cgAsyncInit; }(document, 'script', 'cg-bundle')); ``` -------------------------------- ### Create Javascript Authorization Header for Basic Authentication Source: https://cartsguru.gitbook.io/custom-integration/data-apis/authorization Generates a Basic authorization header for Carts.Guru API requests. It takes siteId and apiToken as input, concatenates them with a colon, and encodes the result in base64. This header is essential for accessing secured data endpoints. ```javascript /* @description: create authorization header ** @params {{siteId: string, apiToken: string}} args - ** these parameters are available in the integration tab ** of the site settings */ const createAuthorizationHeader = ({ siteId, apiToken }) => { // concatenate the siteId,timestamp, and hash // with `:` as separator, and store it as base64 string const authToken = `Buffer.from([siteId, apiToken].join(':')).toString('base64')` return { // authorization: `Basic ${authToken}` } } ``` -------------------------------- ### Default Frontend Tracking Script Initialization Source: https://cartsguru.gitbook.io/custom-integration/manual-integration/other This is the default JavaScript snippet to be added to your frontend. It initializes the Cartsguru tracking script without specific cart or customer data. The script dynamically loads 'bundle.js' from the provided CDN. ```javascript function cgAsyncInit() { // INIT CG('init'); } (function (d, s, id) { if (d.getElementById(id)) return; var t = d.getElementsByTagName(s)[0]; var cgs = d.createElement(s); cgs.id = id; cgs.src = 'https://t.carts.guru/bundle.js?sid={{SITE_ID}}'; t.parentNode.insertBefore(cgs, t); cgs.onload = cgAsyncInit; }(document, 'script', 'cg-bundle')); ``` -------------------------------- ### POST /carts Source: https://cartsguru.gitbook.io/custom-integration/carts-guru-integration/carts Creates a new cart with the provided details. The request must include authentication, cart content, and an account ID. ```APIDOC ## POST /carts ### Description Creates a new cart with the provided details. The request must include authentication, cart content, and an account ID. ### Method POST ### Endpoint https://api.carts.guru/carts ### Parameters #### Headers - **x-auth-key** (string) - Required - Authentication key found in your Carts.guru account settings. #### Request Body - **siteId** (string) - Required - Site ID from configuration. - **id** (string) - Required - Cart reference (use SessionId if no specific ID). - **totalATI** (number) - Required - Total price including taxes. - **totalET** (number) - Required - Total price excluding taxes. - **currency** (string) - Optional - Currency ISO code. - **accountId** (string) - Required - Account ID of the buyer (recommended to use email address). - **ip** (string) - Optional - Visitor IP address. - **recoverUrl** (string) - Required - Link to recover the cart. - **civility** (string) - Optional - Buyer's civility ('mister', 'madam', 'miss'). - **lastname** (string) - Optional - Buyer's last name. - **firstname** (string) - Optional - Buyer's first name. - **email** (string) - Required - Buyer's email address. - **homePhoneNumber** (string) - Optional - Buyer's landline phone number. - **mobilePhoneNumber** (string) - Optional - Buyer's mobile phone number. - **phoneNumber** (string) - Optional - Buyer's phone number. - **countryCode** (string) - Required (if phone number is provided) - Buyer's country ISO code (2 or 3 letters). - **language** (string) - Optional - Buyer's language ISO code (lowercase, e.g., 'en', 'fr'). - **custom** (object) - Optional - Any custom fields for segmentation. - **buyerAcceptsMarketing** (boolean) - Optional - Indicates if the customer accepts marketing communications. - **items** (array) - Required - Array of items in the cart. - **id** (string) - Required - SKU or product ID. - **label** (string) - Required - Product designation. - **quantity** (number) - Required - Number of units. - **totalATI** (number) - Required - Total price including taxes for the item. - **totalET** (number) - Required - Total price excluding taxes for the item. - **url** (string) - Required - URL of the product sheet. - **imageUrl** (string) - Required - URL of the product image (min 150x150, max 180x180). - **universe** (string) - Optional - Main product category. - **category** (string) - Optional - Sub-category of the product. - **custom** (object) - Optional - Custom fields for item segmentation. ### Request Example ```json { "siteId": "your_site_id", "id": "cart_reference_123", "totalATI": 100.50, "totalET": 90.00, "currency": "USD", "accountId": "buyer_email@example.com", "ip": "192.168.1.1", "recoverUrl": "https://yourstore.com/checkout?token=abc", "firstname": "John", "lastname": "Doe", "email": "buyer_email@example.com", "countryCode": "US", "language": "en", "buyerAcceptsMarketing": true, "items": [ { "id": "SKU001", "label": "Product A", "quantity": 1, "totalATI": 50.25, "totalET": 45.00, "url": "https://yourstore.com/product/a", "imageUrl": "https://yourstore.com/images/a.jpg", "category": "Electronics" } ] } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json { "message": "Cart created successfully" } ``` #### Error Response (500) - **error** (object) - Contains details about the validation error. - **code** (string) - Error code. - **message** (string) - Error description. #### Error Response Example ```json { "error": { "code": "VALIDATION_ERROR", "message": "The provided data is invalid. Please check the 'items' field." } } ``` ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### POST /contacts/v1/batch Source: https://cartsguru.gitbook.io/custom-integration/data-apis/contacts/batch This endpoint allows for batch processing of contact actions, including creating, updating, and deleting contacts. It requires an authorization header and a request body containing an array of actions. ```APIDOC ## POST /contacts/v1/batch ### Description This endpoint allows for batch processing of contact actions, including creating, updating, and deleting contacts. It requires an authorization header and a request body containing an array of actions. ### Method POST ### Endpoint https://api.carts.guru/contacts/v1/batch ### Parameters #### Headers - **authorization** (string) - Required - See Authorization page for example. #### Request Body - **actions** (array) - Required - An array of actions matching the sample objects below which contain either a delete, create, or update property. ### Request Example **Create Action Example:** ```json { "actions": [ { "create": { "email": "test@example.com", "firstName": "John", "lastName": "Doe", "optoutEmail": false, "optoutSms": false, "addresses": [ { "title": "Home", "line1": "123 Main St", "city": "Anytown", "zipcode": "12345", "country": "USA" } ] } } ] } ``` **Delete Action Example:** ```json { "actions": [ { "delete": { "email": "test@example.com" } } ] } ``` **Update Action Example:** ```json { "actions": [ { "update": { "email": "test@example.com", "firstName": "Jane", "lastName": "Doe", "optoutEmail": true } } ] } ``` ### Response #### Success Response (200 Batch successfully queued.) - **data** (object) - Contains the batchId. - **batchId** (string) - The unique identifier for the batch operation. #### Response Example (200) ```json { "data": { "batchId": "1234asdf1234" } } ``` #### Error Response (400 Your request failed validation) - **errors** (array) - A list of validation errors. #### Response Example (400) ```json { "errors": [ "siteId" is required, "optoutEmail" must be a boolean ] } ``` #### Error Response (401 You failed authentication.) - **errors** (array) - Contains authentication error details. - **status** (integer) - The HTTP status code (401). - **message** (string) - The error message (e.g., 'UNAUTHORIZED'). #### Response Example (401) ```json { "errors": [ { "status": 401, "message": "UNAUTHORIZED" } ] } ``` ``` -------------------------------- ### Extend CartsGuru for PHP SDK Source: https://cartsguru.gitbook.io/custom-integration/manual-integration/php-sdk Extend the CartsGuru class to customize API credentials and adapt cart, order, and product data models for the CartsGuru API. This is the primary class for interacting with the SDK. ```php 'your-site-id', 'auth_key' => 'your-auth-key', ); parent::__construct($params); } public function adaptCart($item) { return $item; } public function adaptOrder($item) { return $item; } public function adaptProduct($item) { return $item; } } ``` -------------------------------- ### Untitled No description -------------------------------- ### POST Cart API Endpoint Source: https://cartsguru.gitbook.io/custom-integration/carts-guru-integration/carts This snippet shows the API endpoint for creating a new cart. Requests to this endpoint should be authenticated using an 'x-auth-key' in the HTTP header. The data structure for the cart is JSON-based. ```javascript https://api.carts.guru/carts ``` -------------------------------- ### Track Cart using PHP SDK Source: https://cartsguru.gitbook.io/custom-integration/manual-integration/php-sdk Send cart data to CartsGuru for tracking. The `trackCart` method should be called every time a cart is updated to ensure accurate data synchronization. ```php $cg = new CartsGuruController(); $cg->trackCart($cart); ``` -------------------------------- ### POST /contacts/v1/batch API Request Structure Source: https://cartsguru.gitbook.io/custom-integration/data-apis/contacts/batch This snippet defines the structure for the POST /contacts/v1/batch API request. It includes the authorization header and the request body, which contains an array of actions. Each action can be a create, update, or delete operation on a contact. ```javascript { "actions": [ { "create": { // At least one of the three identifiers is REQUIRED // email, phoneNumber, accountId email: String, // The contact's email phoneNumber: String, // The contact's phone number accountId: String, //The contact's accountId on your platform firstname: Optional (String), // The contact's first name lastname: Optional (String), // The contact's last name optoutEmail: Optional (Boolean), // true if they are opted out. optoutSms: Optional (Boolean), // true if they are opted out. addresses: Optional (Array of Objects) - Addresses of the contact. ex: [ { title line1 line2 city zipcode country - Required if passing in addresses. } ] } } ] } ``` ```javascript { actions: [ { delete: { // Only one of these three, will error if you provide more than one email: The contact's email phoneNumber: The contact's phone number accountId: The contact's accountId on your platform } } } ``` ```javascript { actions: [{ update: { email: Identifying (String), // The contact's email phoneNumber: Identifying (String), // The contact's phone number accountId: Identifying (String), // The contact's accountId on your platform firstname: Optional (String), // The contact's first name lastname: Optional (String), // The contact's last name optoutEmail: Optional (Boolean), // if they are opted out, false if they are opted in optoutSms: Optional (Boolean), // if they are opted out, false if they are opted in addresses: [{ // Addresses of the contact. // You can pass a list of addresses in // the following format title: Optional (String), // The contact's first name line1: Optional (String), line2: Optional (String), city: Optional (String), zipcode :Optional (String), country: Require(String) } ] } }] } ```