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-04-13 16:51:30 UTC


README

Conesso header

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f434f4e4553534f2d626c75653f7374796c653d666f722d7468652d6261646765266c6f676f436f6c6f723d253233313733453538 68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636f6e6573736f2f6170692d7068702f74657374732e796d6c3f7374796c653d666f722d7468652d6261646765 68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f6e6573736f2f636c69656e743f7374796c653d666f722d7468652d6261646765 68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f6e6573736f2f636c69656e743f7374796c653d666f722d7468652d6261646765

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