API > Customers - New customer

Customers - New customer

POST  https://{entorno}.ticketbaiws.eus/clientes/

These are the customers and products of the company's invoicing tool in the private area. They are meant for looking up the customer and the products before issuing an invoice with POST /tbai/: the field names match those of the invoice (nombre, nif, pais_cliente, importe_unitario, tipo_iva, tipo_req...).

They do not depend on the environment: with the test token (api-test) you read and modify the same data as with the production token.

Creates a customer and returns it with its id. Returns ERROR if another customer with the same NIF already exists (or, if there is no NIF, with the same name).

PARAMETERS

nombre string required
Name or registered (legal) name. Alias: nombre_social
Empresa de ejemplo S.L.
nif string optional
Customer's NIF (Spanish tax ID). Stored without spaces, dots or hyphens. It cannot be repeated in another customer; if there is no NIF, the name cannot be repeated
B01000012
nombre_comercial string optional
Trade name. When creating the customer, defaults to the name
Ejemplo
tipo_documento string optional
ID document type for foreign customers: 02 NIF-IVA (EU VAT number, default), 03 passport, 04 official ID document issued by the country of residence, 05 certificate of residence, 06 other document
02
direccion string optional
Address
Calle Mayor 1
cp string optional
Postal code
48001
poblacion string optional
Town/city
Bilbao
provincia string optional
Province
Bizkaia
pais string optional
Country: ISO 3166 alpha-2 code or name. Alias: pais_cliente
ES
email string optional
Email
facturas@ejemplo.com
telefono string optional
Phone
944000000
web string optional
Website
https://...

POST https://{entorno}.ticketbaiws.eus/clientes/
$ curl --request POST \
     --url https://api-test.ticketbaiws.eus/clientes/ \
     --header 'Accept: application/json' \
     --header 'Content-Type: application/json' \
     --header 'Token: xxx' \
     --header 'Nif: 00000014Z' \
     --data '
{
    "nombre": "Empresa de ejemplo S.L.",
    "nif": "B01000012",
    "direccion": "Calle Mayor 1",
    "cp": "48001",
    "poblacion": "Bilbao",
    "provincia": "Bizkaia",
    "pais": "ES",
    "email": "facturas@ejemplo.com"
}'
$ composer require ticketbaiws/ticketbaiws-php
<?php
// Installation: composer require ticketbaiws/ticketbaiws-php
require 'vendor/autoload.php';

$tbai = new \TicketbaiWS\Client('xxx', '00000014Z', ['entorno' => 'test']);

$r = $tbai->clientes()->crear([
    'nombre' => 'Empresa de ejemplo S.L.',
    'nif' => 'B01000012',
    'direccion' => 'Calle Mayor 1',
    'cp' => '48001',
    'poblacion' => 'Bilbao',
    'provincia' => 'Bizkaia',
    'pais' => 'ES',
    'email' => 'facturas@ejemplo.com',
]);

if ($r->isError()) {
    echo $r->getMessageText();
} else {
    print_r($r->getData());
}
$ python -m pip install requests
import requests

url = "https://api-test.ticketbaiws.eus/clientes/"
payload = {
    "nombre": "Empresa de ejemplo S.L.",
    "nif": "B01000012",
    "direccion": "Calle Mayor 1",
    "cp": "48001",
    "poblacion": "Bilbao",
    "provincia": "Bizkaia",
    "pais": "ES",
    "email": "facturas@ejemplo.com"
}

headers = {"Accept": "application/json", "Token" : "xxx", "Nif" : "00000014Z"}
response = requests.request("POST", url, json=payload, headers=headers)

print(response.text)
CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_URL, "https://api-test.ticketbaiws.eus/clientes/");

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Accept: application/json");
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "Token: xxx");
headers = curl_slist_append(headers, "Nif: 00000014Z");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, R"({"nombre": "Empresa de ejemplo S.L.", "nif": "B01000012", "direccion": "Calle Mayor 1", "cp": "48001", "poblacion": "Bilbao", "provincia": "Bizkaia", "pais": "ES", "email": "facturas@ejemplo.com"})");

CURLcode ret = curl_easy_perform(hnd);
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"nombre\": \"Empresa de ejemplo S.L.\", \"nif\": \"B01000012\", \"direccion\": \"Calle Mayor 1\", \"cp\": \"48001\", \"poblacion\": \"Bilbao\", \"provincia\": \"Bizkaia\", \"pais\": \"ES\", \"email\": \"facturas@ejemplo.com\"}");

Request request = new Request.Builder()
  .url("https://api-test.ticketbaiws.eus/clientes/")
  .post(body)
  .addHeader("Accept", "application/json")
  .addHeader("Token", "xxx")
  .addHeader("Nif", "00000014Z")
  .build();

Response response = client.newCall(request).execute();
{ } Response JSON
HTTP/1.1 200 OK
{
    "result": "OK",
    "return": {
        "id": 1532,
        "nif": "B01000012",
        "tipo_documento": "02",
        "nombre": "Empresa de ejemplo S.L.",
        "nombre_comercial": "Empresa de ejemplo S.L.",
        "direccion": "Calle Mayor 1",
        "cp": "48001",
        "poblacion": "Bilbao",
        "provincia": "Bizkaia",
        "pais": "España",
        "pais_cliente": "ES",
        "email": "facturas@ejemplo.com",
        "telefono": "",
        "web": "",
        "fecha_alta": "28/11/2026"
    },
    "msg": ""
}
{ } Response (duplicate) JSON
HTTP/1.1 200 OK
{
    "result": "ERROR",
    "return": null,
    "msg": "nif: a client with this NIF already exists (id 1532)"
}

TicketBAI / Verifactu methods

Representation document

BATUZ BIZKAIA specific methods

SII (AEAT)

Customers and products (invoicing tool)

Other methods