Please enable JS

Exemplos

Pesquisar Clientes & Fornecedores

Nome
NIF
E-mail
Tipo
Data da Última Atualização

Código Fonte

<?php

require_once '../vendor/autoload.php';

use Swagger\Client\Api\AccountApi;
use Swagger\Client\ApiException;

// PARAMETERS
$offset      = clear('offset');
$limit       = clear('limit');
$name        = clear('name');
$vat_number  = clear('vat_number');
$email       = clear('email');
$type        = clear('type');
$update_date = formatDate('update_date');
$deleted     = false;
$ids         = null;
$salesman    = null;

// ADD WILDCARD
if (!empty($name)) {
    $name .= '%';
}

// E2E ACCESS KEYS
$client = new GuzzleHttp\Client([
    'headers' => [
        'api_key' => 'JHSV2V6KyqcbxvMHshRlPfunJymVt7GDfXyoK229o=',
        'company_key' => 'E2ELIVE',
    ]
]);

try {
    
    // SEARCH ACCOUNTS
    $api = new AccountApi($client);
    $result = $api->accountList(
        $offset,
        $limit,
        $name,
        $vat_number,
        $email,
        $type,
        $update_date,
        $deleted,
        $ids,
        $salesman
    );
    
    header('Content-Type: application/json; charset=utf-8');
    echo $result->__toString();
    
} catch (Exception $e) {
    
    http_response_code($e->getCode());
    
    $msg = $e instanceof ApiException ? $e->getResponseBody() : $e->getMessage();
    
    if (!empty($msg)) {
        echo $msg;
    }
}

function clear($field)
{
    return empty($_REQUEST[$field]) ? null : $_REQUEST[$field];
}

function formatDate($field)
{
    $date = clear($field);
    
    if (!empty($date)) {
        $date = DateTime::createFromFormat('Y-m-d', $date);
        $date = $date->format(DateTime::ISO8601);
    }
    
    return $date;
}