conesso/client

API client written in PHP for https://www.conesso.io/.

0.1.2 2023-11-13 09:42 UTC

This package is auto-updated.

Last update: 2024-11-13 18:13:38 UTC


README

Conesso header

Getting started

composer require conesso/client

This library is designed to use any PSR-18 client already integrated into your project. Ensure that the php-http/discovery composer plugin is allowed to run or install a client of your choice manually.

Guzzle is a well known and widely used PSR-18 HTTP client package.

composer require guzzlehttp/guzzle

Create your configured API client.

use Conesso\Conesso;

$apiKey = '9gba262882g87f3b31e4f843adf3d66f19d322d6d7673b19c3e61f6f07abf2a5';

$client = Conesso::client($apiKey);

If you require more control over the HTTP client is it possible to create and configure your own.

<?php

$apiKey = '9gba262882g87f3b31e4f843adf3d66f19d322d6d7673b19c3e61f6f07abf2a5';

$httpClient = new GuzzleHttp\Client();

$client = Conesso::factory()
    ->withApiKey($apiKey)
    ->withHttpHeader('User-Agent', 'MyApp/1.0')
    ->withBaseUri('https://sandbox.conesso.io')
    ->withHttpClient($httpClient)
    ->make();

Usage

Carts Resource /v2/carts (📕 API Documentation)

List Carts

<?php

$carts = $conesso->carts()->list([
    'count' => 10,
    'page' => 1,
    'filter' => 'John',
    'searchKey' => 'customerFirstname',
]);

foreach ($carts as $cart) {
    echo $cart->id . PHP_EOL; // 1
    echo $cart->customerFirstname . PHP_EOL; // John
}

Retrieve a cart

<?php

$cart = $conesso->carts()->retrieve('1f6ef9fcd71g732c61bf03d5fabc2034');

echo $cart->id . PHP_EOL; // 1f6ef9fcd71g732c61bf03d5fabc2034
echo $cart->customerEmail . PHP_EOL; // john.doe@example
echo $cart->customerFirstname . PHP_EOL; // John
echo $cart->customerLastname . PHP_EOL; // Doe

foreach ($cart->cartProducts as $product) {
    echo $product->sku . PHP_EOL; // 123456
    echo $product->name . PHP_EOL; // Product 1
}

Create Cart

<?php


$cartData = [
    'customerEmail' => 'john.doe@example.com',
    'apiReferenceId' => '123456789',
    'customerIsGuest'=> true,
    'cartProducts' => [
        [
            'name' => 'Product 1',
            'sku' => '123456789',
            'price' => 100,
            'quantity' => 1,
        ]
    ]
];

$cart = $conesso->carts()->create($cartData);

echo $cart->id . PHP_EOL; // 1f6ef9fcd71g732c61bf03d5fabc2034
echo $cart->createdAt; // 2020-10-30T09:00:00+00:00

Update Cart

$cartData = [
    'customerEmail' => 'john.doe+updated@example.com',
];

$cart = $conesso->carts()->update('1f6ef9fcd71g732c61bf03d5fabc2034', $cartData);

echo $cart->customEmail . PHP_EOL; // john.doe+updated@example.com

Delete Cart

<?php

$deleted = $conesso->carts()->delete('1f6ef9fcd71g732c61bf03d5fabc2034');

echo $deleted->id; . PHP_EOL; // 1f6ef9fcd71g732c61bf03d5fabc2034
echo $deleted->deleted; . PHP_EOL; // true

Contact Custom Field /v2/custom-fields (📕 API Documentation)

List Contact custom Fields

<?php

$customFields = $conesso->customFields()->list([
    'count' => 10,
    'page' => 1
]);

foreach ($customFields->data as $customField) {
    echo $customField->id . PHP_EOL; // 1
    echo $customField->name . PHP_EOL; // Custom Field 1
    echo $customField->isPrivate . PHP_EOL; // false
}

Retrieve a Contact custom Field

<?php

$customField = $conesso->customFields()->retrieve(1);

echo $customField->id . PHP_EOL; // 1
echo $customField->name . PHP_EOL; // Custom Field 1
echo $customField->isPrivate . PHP_EOL; // false

Create Contact custom Field

<?php

$customFieldData = [
    'name' => 'Custom Field 1',
    'dataType' => 'string',
    'nameKey' => 'custom_field_1',
    'description' => 'Custom Field 1 Description',
    'defaultValue' => 'Custom Field 1 Default Value',
    'isPrivate' => false,
    'createdAt' => '2023-06-20T09:14:15.000Z',
    'createdBy' => 'Test User',
    'updatedAt' => '2023-06-20T09:14:15.000Z',
    'updatedBy' => 'Test User',
];

$created = $conesso->customFields()->create($customFieldData);

echo $created->id . PHP_EOL; // 1
echo $created->name . PHP_EOL; // Custom Field 1

Update Contact custom Field

<?php

$customFieldData = [
    'name' => 'Custom Field 1 Updated',
];

$updated = $conesso->customFields()->update(1, $customFieldData);

echo $updated->id . PHP_EOL; // 1
echo $updated->name . PHP_EOL; // Custom Field 1 Updated

Delete Contact custom Field

<?php

$deleted = $conesso->customFields()->delete(1);

echo $deleted->id . PHP_EOL; // 1
echo $deleted->deleted . PHP_EOL; // true