Store Hugs Developers

Addresses

The signed-in shopper's address book, the same one checkout offers them.

Reach it through $shopper->customer->addresses. It needs a client with the shopper's access token (see sign-in).

List addresses

$shopper->customer->addresses->list(): array

The address book, the default first. Not paginated.

Returns

A list of CustomerAddress arrays, each:

FieldTypeDescription
[].idinteger
[].labelstring or null
[].namestring
[].phonestring
[].countryCodestring
[].statestring or null
[].stateIdinteger or null
[].citystring or null
[].cityIdinteger or null
[].neighbourhoodstring or null
[].neighbourhoodIdinteger or null
[].addressLine1string
[].addressLine2string or null
[].postalCodestring or null
[].isDefaultboolean

Errors

StatusWhen
401invalid_api_key, or invalid_customer_token: the shopper's token is missing or not valid for this shop.
402The shop is suspended (message only).
403origin_not_allowed (publishable key from an unlisted site), secret_key_in_browser, or the shop is not live (message only).
404Not found, or the shop's plan has no Integration API.
429Rate limited.

Example

$addresses = $shopper->customer->addresses->list();

Add an address

$shopper->customer->addresses->create(array $input, string|false|null $idempotencyKey = null): array

A new address. The first address, or one sent with isDefault, becomes the default. Limited like cart writes.

Parameters

Parameter Type
$input array The address's fields, below.
$idempotencyKey string|false|null Your own Idempotency-Key, or false for none. One is made for you when null.

Request fields

FieldTypeDescription
labelstring or nullAt most 50 characters.
name requiredstringAt most 255 characters.
phone requiredstringAt most 50 characters.
countryCode requiredstringISO 3166-1 alpha-3, one the shop ships to. At most 3 characters.
city requiredstringAt most 100 characters.
statestring or nullAt most 100 characters.
addressLine1 requiredstringAt most 500 characters.
addressLine2string or nullAt most 500 characters.
postalCodestring or nullAt most 20 characters.
isDefaultboolean
shippingStateIdinteger or null
shippingCityIdinteger or null
shippingNeighbourhoodIdinteger or null
shippingLocationUnlistedboolean or null

Returns

The new CustomerAddress array:

FieldTypeDescription
idinteger
labelstring or null
namestring
phonestring
countryCodestring
statestring or null
stateIdinteger or null
citystring or null
cityIdinteger or null
neighbourhoodstring or null
neighbourhoodIdinteger or null
addressLine1string
addressLine2string or null
postalCodestring or null
isDefaultboolean

Errors

StatusWhen
401invalid_api_key, or invalid_customer_token: the shopper's token is missing or not valid for this shop.
402The shop is suspended (message only).
403origin_not_allowed (publishable key from an unlisted site), secret_key_in_browser, or the shop is not live (message only).
404Not found, or the shop's plan has no Integration API.
409idempotency_in_progress: a request with this Idempotency-Key is still running. Retry with the same key after Retry-After seconds; the first answer is then replayed.
422Validation errors ({ message, errors }), or an idempotency refusal(idempotency_key_reused, idempotency_key_invalid).
429Rate limited.

Example

$address = $shopper->customer->addresses->create([
    'name' => 'Sara Ali',
    'phone' => '+966500000000',
    'countryCode' => 'SAU',
    'city' => 'Riyadh',
    'addressLine1' => '12 King Fahd Road',
    'isDefault' => true,
]);

Edit an address

$shopper->customer->addresses->update(int $id, array $changes, string|false|null $idempotencyKey = null): array

Changes one of the shopper's addresses. It is validated with the same rules as a new address, so send every required field.

Parameters

Parameter Type
$id int The address's id.
$changes array The address's fields, below.
$idempotencyKey string|false|null Your own Idempotency-Key, or false for none.

Request fields

FieldTypeDescription
labelstring or nullAt most 50 characters.
name requiredstringAt most 255 characters.
phone requiredstringAt most 50 characters.
countryCode requiredstringISO 3166-1 alpha-3, one the shop ships to. At most 3 characters.
city requiredstringAt most 100 characters.
statestring or nullAt most 100 characters.
addressLine1 requiredstringAt most 500 characters.
addressLine2string or nullAt most 500 characters.
postalCodestring or nullAt most 20 characters.
isDefaultboolean
shippingStateIdinteger or null
shippingCityIdinteger or null
shippingNeighbourhoodIdinteger or null
shippingLocationUnlistedboolean or null

Returns

The changed CustomerAddress array:

FieldTypeDescription
idinteger
labelstring or null
namestring
phonestring
countryCodestring
statestring or null
stateIdinteger or null
citystring or null
cityIdinteger or null
neighbourhoodstring or null
neighbourhoodIdinteger or null
addressLine1string
addressLine2string or null
postalCodestring or null
isDefaultboolean

Errors

StatusWhen
401invalid_api_key, or invalid_customer_token: the shopper's token is missing or not valid for this shop.
402The shop is suspended (message only).
403origin_not_allowed (publishable key from an unlisted site), secret_key_in_browser, or the shop is not live (message only).
404address_not_found, or the plan has no Integration API.
409idempotency_in_progress: a request with this Idempotency-Key is still running. Retry with the same key after Retry-After seconds; the first answer is then replayed.
422Validation errors ({ message, errors }), or an idempotency refusal(idempotency_key_reused, idempotency_key_invalid).
429Rate limited.

Example

$shopper->customer->addresses->update(7, [
    'name' => 'Sara Ali',
    'phone' => '+966500000000',
    'countryCode' => 'SAU',
    'city' => 'Jeddah',
    'addressLine1' => '4 Tahlia Street',
]);

Delete an address

$shopper->customer->addresses->delete(int $id): void

Deletes one of the shopper's addresses. Deleting the default makes the next address the default.

Parameters

Parameter Type
$id int The address's id.

Returns

Nothing.

Errors

StatusWhen
401invalid_api_key, or invalid_customer_token: the shopper's token is missing or not valid for this shop.
402The shop is suspended (message only).
403origin_not_allowed (publishable key from an unlisted site), secret_key_in_browser, or the shop is not live (message only).
404address_not_found, or the plan has no Integration API.
409idempotency_in_progress: a request with this Idempotency-Key is still running. Retry with the same key after Retry-After seconds; the first answer is then replayed.
422Validation errors ({ message, errors }), or an idempotency refusal(idempotency_key_reused, idempotency_key_invalid).
429Rate limited.

Make an address the default

$shopper->customer->addresses->makeDefault(int $id): array

Makes one of the shopper's addresses their default.

Parameters

Parameter Type
$id int The address's id.

Returns

The CustomerAddress array:

FieldTypeDescription
idinteger
labelstring or null
namestring
phonestring
countryCodestring
statestring or null
stateIdinteger or null
citystring or null
cityIdinteger or null
neighbourhoodstring or null
neighbourhoodIdinteger or null
addressLine1string
addressLine2string or null
postalCodestring or null
isDefaultboolean

Errors

StatusWhen
401invalid_api_key, or invalid_customer_token: the shopper's token is missing or not valid for this shop.
402The shop is suspended (message only).
403origin_not_allowed (publishable key from an unlisted site), secret_key_in_browser, or the shop is not live (message only).
404address_not_found, or the plan has no Integration API.
409idempotency_in_progress: a request with this Idempotency-Key is still running. Retry with the same key after Retry-After seconds; the first answer is then replayed.
422Validation errors ({ message, errors }), or an idempotency refusal(idempotency_key_reused, idempotency_key_invalid).
429Rate limited.

Example

$shopper->customer->addresses->makeDefault(7);