Client Addresses
The five endpoints that read, add, update and delete an address in a client's address book.
Overview
A client can hold several addresses, and an invoice is issued to one of them. The address book is separate from the client record.
One address is the default. Making a new address the default clears the flag on the previous one; there is never more than one default.
A notification preference is stored as a bitmask: one number carrying several choices.
Reference
Listing Addresses
Returns the client's whole address book. The default one is flagged with is_default.
Office.individual or corporate.reference/countries.active or passive.curl 'https://panel.example.com/api/v1/admin/clients/42/addresses' \
-H "Authorization: Bearer $API_KEY" \
-H 'Accept: application/json'const res = await fetch('https://panel.example.com/api/v1/admin/clients/42/addresses', {
headers: { Authorization: `Bearer ${apiKey}` },
});
const body = await res.json();$ch = curl_init('https://panel.example.com/api/v1/admin/clients/42/addresses');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $apiKey],
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);$response = Api::Clients()->GetClientAddresses(['id' => 42]);
foreach ($response['data'] as $address) {
if ($address['is_default']) {
$invoiceAddress = $address;
}
}Adding an Address
Adds a record to the address book and returns it in the same schema as the list.
reference/countries.individual or corporate. Defaults to individual.201. Same shape as the list schema.curl -X POST 'https://panel.example.com/api/v1/admin/clients/42/addresses' \
-H "Authorization: Bearer $API_KEY" \
-H 'Content-Type: application/json' \
-d '{"full_name":"John Doe","email":"[email protected]","country_id":840,"state":"California","city":"San Francisco","address":"123 Market Street","zipcode":"94105","is_default":true}'const res = await fetch('https://panel.example.com/api/v1/admin/clients/42/addresses', {
method: 'POST',
headers: {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({"full_name":"John Doe","email":"[email protected]","country_id":840,"state":"California","city":"San Francisco","address":"123 Market Street","zipcode":"94105","is_default":true}),
});
const body = await res.json();$ch = curl_init('https://panel.example.com/api/v1/admin/clients/42/addresses');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'full_name' => 'John Doe',
'email' => '[email protected]',
'country_id' => 840,
'state' => 'California',
'city' => 'San Francisco',
]),
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);$response = Api::Clients()->CreateClientAddress([
'id' => 42,
'full_name' => 'John Doe',
'email' => '[email protected]',
'country_id' => 840,
'state' => 'California',
'city' => 'San Francisco',
'is_default' => true,
]);
$addressId = $response['data']['id'] ?? 0;{
"data": {
"id": 13,
"full_name": "John Doe",
"type": "individual",
"country_id": 840,
"city": "San Francisco",
"zipcode": "94105",
"is_default": true,
"status": "active"
}
}{
"error": {
"code": "email_invalid",
"message": "A valid email is required."
}
}Address Detail
Returns one address. The schema is the same as in the list.
curl 'https://panel.example.com/api/v1/admin/clients/42/addresses/13' \
-H "Authorization: Bearer $API_KEY"const res = await fetch('https://panel.example.com/api/v1/admin/clients/42/addresses/13', {
headers: { Authorization: `Bearer ${apiKey}` },
});
const body = await res.json();$ch = curl_init('https://panel.example.com/api/v1/admin/clients/42/addresses/13');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $apiKey],
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);$response = Api::Clients()->GetClientAddress(['id' => 42, 'addr_id' => 13]);Updating an Address
Updates the address. The body takes the same fields as create, and the required ones stay required.
full_name is required.country_id is required.state is required.city is required.curl -X PUT 'https://panel.example.com/api/v1/admin/clients/42/addresses/13' \
-H "Authorization: Bearer $API_KEY" \
-H 'Content-Type: application/json' \
-d '{"full_name":"John Doe","email":"[email protected]","country_id":840,"state":"California","city":"San Francisco","address":"123 Market Street","zipcode":"94105","is_default":true}'const res = await fetch('https://panel.example.com/api/v1/admin/clients/42/addresses/13', {
method: 'PUT',
headers: {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({"full_name":"John Doe","email":"[email protected]","country_id":840,"state":"California","city":"San Francisco","address":"123 Market Street","zipcode":"94105","is_default":true}),
});
const body = await res.json();$ch = curl_init('https://panel.example.com/api/v1/admin/clients/42/addresses/13');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode($address),
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);// The required fields are sent again: this is a full update, not a partial one.
$response = Api::Clients()->UpdateClientAddress([
'id' => 42,
'addr_id' => 13,
'full_name' => 'John Doe',
'email' => '[email protected]',
'country_id' => 840,
'state' => 'California',
'city' => 'San Francisco',
]);Deleting an Address
Deletes the address and returns the id that was removed.
curl -X DELETE 'https://panel.example.com/api/v1/admin/clients/42/addresses/13' \
-H "Authorization: Bearer $API_KEY"const res = await fetch('https://panel.example.com/api/v1/admin/clients/42/addresses/13', {
method: 'DELETE',
headers: { Authorization: `Bearer ${apiKey}` },
});
const body = await res.json();$ch = curl_init('https://panel.example.com/api/v1/admin/clients/42/addresses/13');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'DELETE',
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $apiKey],
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);$response = Api::Clients()->DeleteClientAddress(['id' => 42, 'addr_id' => 13]);Pitfalls
Flagging an address with is_default clears the flag on the previous one. You do not have to update the old address; two defaults cannot exist.
Updating an address does not reach invoices that were already issued. Send overwrite_invoices if you want it to.
The endpoint is PUT. Leave a required field out and the request is refused; sending only the changed field is not enough.
Related Articles
¡Gracias por sus comentarios!
Nuestro equipo de soporte está disponible las 24 horas para ayudarle con lo que no encuentre aquí.