Pular para o conteúdo
Documentação API Reference FAQ Changelog Status

Mage_Customer

magento-1

Módulo Mage_Customer: gerenciamento de customers, customer groups e customer addresses via SOAP v1/v2.

Fonte oficial (devdocs-m1)

Module: Mage_Customer

The Mage_Customer module exposes three SOAP resources that together cover the customer lifecycle: customers, customer groups, and customer addresses. All calls require a sessionId obtained from login().

Nota (PT-BR): este módulo agrupa 3 recursos diferentes do devdocs-m1 em uma mesma página. Use o filtro do TOC à esquerda para saltar rapidamente entre customer.*, customer_group.* e customer_address.*.

Resource: customer

Allows you to create, retrieve, update, and delete customers (5 methods: list, create, info, update, delete).

Faults — customer

CodeMessage
100Invalid customer data. Details in error message.
101Invalid filters specified. Details in error message.
102Customer does not exist.
103Customer not deleted. Details in error message.

Resource: customer_group

Read-only access to customer groups (1 method: list). This resource has no specific faults — apenas os Global API Faults.

Resource: customer_address

Create, retrieve, update, and delete addresses attached to a customer (5 methods: list, create, info, update, delete).

Faults — customer_address

CodeMessage
100Invalid address data. Details in error message.
101Customer not exists.
102Address not exists.
103Address not deleted. Details in error message.

v1 × v2 — detalhes práticos para customer.create

Na API v1, customer.create costuma receber password_hash (MD5 com ou sem salt, formato md5($salt.$password).":".$salt). Na API v2 o campo é password em texto — o próprio Magento calcula o hash. Misturar os dois formatos gera login quebrado: se você passar password na v1 em versões < 1.3.2.4, a senha pode ser gravada em claro sem hash. Padronize por versão, não misture.

Exemplos oficiais de CRUD (SOAP V1)

Os blocos abaixo reproduzem verbatim os exemplos do devdocs-m1 (customer.html e customerAddress/customerAddress.html). Useful como referência end-to-end para quem está começando.

1 · View, create, update, and delete a customer

$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');

$newCustomer = array(
    'firstname'     => 'First',
    'lastname'      => 'Last',
    'email'         => 'test@example.com',
    // em Magento < 1.3.2.4 NÃO hashear a senha manualmente;
    // 'password_hash' => md5($password) ou md5($salt.$password).":".$salt
    'password_hash' => md5('password'),
    'store_id'      => 0,
    'website_id'    => 0,
);

$newCustomerId = $proxy->call($sessionId, 'customer.create', array($newCustomer));

// Read
var_dump($proxy->call($sessionId, 'customer.info', $newCustomerId));

// Update
$proxy->call($sessionId, 'customer.update', array($newCustomerId, ['firstname' => 'Changed Firstname']));
var_dump($proxy->call($sessionId, 'customer.info', $newCustomerId));

// Delete
$proxy->call($sessionId, 'customer.delete', $newCustomerId);

2 · Working with customer address

$proxy = new SoapClient('http://magentohost/api/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');

$newCustomerId = $proxy->call($sessionId, 'customer.create', array([
    'firstname'  => 'First',
    'lastname'   => 'Last',
    'email'      => 'test@example.com',
    'password'   => 'password',
    'store_id'   => 0,
    'website_id' => 0,
]));

$newAddressId = $proxy->call($sessionId, 'customer_address.create', array($newCustomerId, [
    'firstname'           => 'First',
    'lastname'            => 'Last',
    'country_id'          => 'USA',
    'region_id'           => '43',
    'region'              => 'New York',
    'city'                => 'New York',
    'street'              => ['street1', 'street2'],
    'telephone'           => '5555-555',
    'postcode'            => 10021,
    'is_default_billing'  => true,
    'is_default_shipping' => true,
]));

var_dump($proxy->call($sessionId, 'customer_address.list', $newCustomerId));
$proxy->call($sessionId, 'customer_address.update', array($newAddressId, ['firstname' => 'Changed Firstname']));
$proxy->call($sessionId, 'customer_address.delete', $newAddressId);
SOAP customer.list Session_token

Retrieve the list of customers

Allows you to retrieve the list of customers.

The response is an array of customerCustomerEntity. Optional filters can narrow results by any customer attribute — in SOAP V2 prefer complex_filter with operators (in, gt, eq, …).

SOAP V2 method: customerCustomerList.

Returns

TypeNameDescription
arraystoreViewArray of customerCustomerEntity

Entity: customerCustomerEntity

TypeNameDescription
intcustomer_idID of the customer
stringcreated_atDate when the customer was created
stringupdated_atDate when the customer was updated
stringincrement_idIncrement ID
intstore_idStore ID
intwebsite_idWebsite ID
stringcreated_inStore view the customer was created in
stringemailCustomer email
stringfirstnameCustomer first name
stringmiddlenameCustomer middle name
stringlastnameCustomer last name
intgroup_idCustomer group ID
stringprefixCustomer prefix
stringsuffixCustomer suffix
stringdobCustomer date of birth
stringtaxvatTax/VAT number
booleanconfirmationConfirmation flag
stringpassword_hashPassword hash
stringrp_tokenReset password token (apenas em customer.info)
stringrp_token_created_atDate when the password was reset (apenas em customer.info)

Note: The password_hash only matches if you replicate the exact MD5+salt format Magento used at write time — there is no server-side re-hash for comparison.

Applies resource faults — customer (4 faults: 100–103) Ver no overview ↗

Todos os métodos do resource customer podem lançar os faults abaixo além dos Global API Faults.

CodeMessage
100Invalid customer data. Details in error message.
101Invalid filters specified. Details in error message.
102Customer does not exist.
103Customer not deleted. Details in error message.

Parâmetros

Nome Tipo Obrigatório Descrição
sessionId string Sim Session ID returned by login()
filters array Não Map of customer attribute → value. In V2 use complex_filter for operators.

Exemplo de Resposta

array
  0 =>
    array
      'customer_id' => string '2' (length=1)
      'created_at' => string '2012-03-29 12:37:23' (length=19)
      'updated_at' => string '2012-04-03 11:20:18' (length=19)
      'store_id' => string '2' (length=1)
      'website_id' => string '2' (length=1)
      'created_in' => string 'English' (length=7)
      'default_billing' => string '3' (length=1)
      'default_shipping' => string '3' (length=1)
      'disable_auto_group_change' => string '0' (length=1)
      'email' => string 'test@example.com' (length=16)
      'firstname' => string 'John' (length=4)
      'group_id' => string '1' (length=1)
      'lastname' => string 'Doe' (length=3)
      'password_hash' => string 'cccfb3ecf54c9644a34106783148eff2:sp' (length=35)
      'rp_token' => string '15433dd072f1f4e5aae83231b93f72d0' (length=32)
      'rp_token_created_at' => string '2012-03-30 15:10:31' (length=19)
  1 =>
    array
      'customer_id' => string '4' (length=1)
      'created_at' => string '2012-04-03 11:21:15' (length=19)
      'email' => string 'shon@example.com' (length=16)
      'firstname' => string 'Shon' (length=4)
      'group_id' => string '1' (length=1)
      'lastname' => string 'McMiland' (length=8)

Exemplos de Código

SOAP customer.create Session_token

Create a new customer

Create a new customer. The required fields vary by Magento configuration — at minimum supply email, firstname, lastname, website_id, group_id and the appropriate password field for your API version (see overview → v1 × v2).

SOAP V2 method: customerCustomerCreate.

Returns

TypeNameDescription
intresultID of the created customer

Entity: customerCustomerEntityToCreate

TypeNameDescription
stringemailCustomer email
stringfirstnameCustomer first name
stringlastnameCustomer last name
stringpasswordCustomer password (v2 text; em v1 prefira password_hash — ver overview)
intwebsite_idWebsite ID
intstore_idStore ID
intgroup_idGroup ID
stringprefixCustomer prefix (optional)
stringsuffixCustomer suffix (optional)
stringdobCustomer date of birth (optional)
stringtaxvatCustomer tax/VAT number (optional)
intgenderCustomer gender: 1 - Male, 2 - Female (optional)
stringmiddlenameCustomer middle name/initial (optional)
Applies resource faults — customer (4 faults: 100–103) Ver no overview ↗

Todos os métodos do resource customer podem lançar os faults abaixo além dos Global API Faults.

CodeMessage
100Invalid customer data. Details in error message.
101Invalid filters specified. Details in error message.
102Customer does not exist.
103Customer not deleted. Details in error message.

Parâmetros

Nome Tipo Obrigatório Descrição
sessionId string Sim Session ID returned by login()
customerData customerCustomerEntityToCreate Sim Objeto com os atributos do novo customer (ver schema abaixo)

Exemplos de Código

SOAP customer.info Session_token

Retrieve information about the specified customer

Retrieve information about the specified customer. When attributes is provided, only those attributes are returned — customer_id is always included regardless.

SOAP V2 method: customerCustomerInfo.

Returns

TypeNameDescription
arraycustomerInfoArray/objeto customerCustomerEntity (ver schema abaixo)

Entity: customerCustomerEntity

TypeNameDescription
intcustomer_idID of the customer
stringcreated_atDate when the customer was created
stringupdated_atDate when the customer was updated
stringincrement_idIncrement ID
intstore_idStore ID
intwebsite_idWebsite ID
stringcreated_inStore view the customer was created in
stringemailCustomer email
stringfirstnameCustomer first name
stringmiddlenameCustomer middle name
stringlastnameCustomer last name
intgroup_idCustomer group ID
stringprefixCustomer prefix
stringsuffixCustomer suffix
stringdobCustomer date of birth
stringtaxvatTax/VAT number
booleanconfirmationConfirmation flag
stringpassword_hashPassword hash
stringrp_tokenReset password token (apenas em customer.info)
stringrp_token_created_atDate when the password was reset (apenas em customer.info)
Applies resource faults — customer (4 faults: 100–103) Ver no overview ↗

Todos os métodos do resource customer podem lançar os faults abaixo além dos Global API Faults.

CodeMessage
100Invalid customer data. Details in error message.
101Invalid filters specified. Details in error message.
102Customer does not exist.
103Customer not deleted. Details in error message.

Parâmetros

Nome Tipo Obrigatório Descrição
sessionId string Sim Session ID
customerId int Sim ID of the target customer
attributes ArrayOfString Não Lista de atributos a retornar; vazio = todos

Exemplo de Resposta

array
  'customer_id' => string '2' (length=1)
  'created_at' => string '2012-03-29 12:37:23' (length=19)
  'updated_at' => string '2012-03-30 12:59:21' (length=19)
  'increment_id' => null
  'store_id' => string '2' (length=1)
  'website_id' => string '2' (length=1)
  'confirmation' => null
  'created_in' => string 'English' (length=7)
  'default_billing' => null
  'default_shipping' => string '2' (length=1)
  'disable_auto_group_change' => string '0' (length=1)
  'dob' => null
  'email' => string 'john@example.com' (length=16)
  'firstname' => string 'johny' (length=5)
  'gender' => null
  'group_id' => string '1' (length=1)
  'lastname' => string 'doe' (length=3)
  'middlename' => null
  'password_hash' => string 'cccfb3ecf54c9644a34106783148eff2:sp' (length=35)
  'prefix' => null
  'rp_token' => string '15433dd072f1f4e5aae83231b93f72d0' (length=32)
  'rp_token_created_at' => string '2012-03-30 15:10:31' (length=19)
  'suffix' => null
  'taxvat' => null

Exemplos de Código

SOAP customer.update Session_token

Update information about the required customer

Update information about the required customer. Pass only the fields you want to change. Fields omitted from customerData are left as-is; fields set to an empty string "" are overwritten with empty.

SOAP V2 method: customerCustomerUpdate.

Returns

TypeDescription
booleanTrue if the customer was updated

Entity: customerCustomerEntityToCreate

TypeNameDescription
stringemailCustomer email
stringfirstnameCustomer first name
stringlastnameCustomer last name
stringpasswordCustomer password (v2 text; em v1 prefira password_hash — ver overview)
intwebsite_idWebsite ID
intstore_idStore ID
intgroup_idGroup ID
stringprefixCustomer prefix (optional)
stringsuffixCustomer suffix (optional)
stringdobCustomer date of birth (optional)
stringtaxvatCustomer tax/VAT number (optional)
intgenderCustomer gender: 1 - Male, 2 - Female (optional)
stringmiddlenameCustomer middle name/initial (optional)
Applies resource faults — customer (4 faults: 100–103) Ver no overview ↗

Todos os métodos do resource customer podem lançar os faults abaixo além dos Global API Faults.

CodeMessage
100Invalid customer data. Details in error message.
101Invalid filters specified. Details in error message.
102Customer does not exist.
103Customer not deleted. Details in error message.

Parâmetros

Nome Tipo Obrigatório Descrição
sessionId string Sim Session ID
customerId int Sim ID of the customer to update
customerData customerCustomerEntityToCreate Sim Campos a atualizar (passe só os que mudam)

Exemplos de Código

SOAP customer.delete Session_token

Delete the required customer

Delete the required customer. Operação é irreversível — registros relacionados (endereços, pedidos antigos) seguem as regras de exclusão definidas no admin Magento.

SOAP V2 method: customerCustomerDelete.

Returns

TypeDescription
booleanTrue if the customer was deleted
Applies resource faults — customer (4 faults: 100–103) Ver no overview ↗

Todos os métodos do resource customer podem lançar os faults abaixo além dos Global API Faults.

CodeMessage
100Invalid customer data. Details in error message.
101Invalid filters specified. Details in error message.
102Customer does not exist.
103Customer not deleted. Details in error message.

Parâmetros

Nome Tipo Obrigatório Descrição
sessionId string Sim Session ID
customerId int Sim ID of the customer to delete

Exemplos de Código

SOAP customer_group.list Session_token

Retrieve the list of customer groups

Retrieve the list of customer groups defined in Magento (configuráveis em Customers → Customer Groups no admin). Sem argumentos além do sessionId.

SOAP V2 method: customerGroupList.

Returns

TypeNameDescription
arrayresultArray of customerGroupEntity

Entity: customerGroupEntity

TypeNameDescription
intcustomer_group_idID of the customer group
stringcustomer_group_codeHuman-readable group code (ex.: General, Wholesale)
Sem faults específicos — aplicam-se apenas os Global API Faults Ver na Introduction ↗

O devdocs-m1 não lista faults para o resource customer_group. Erros caem nos faults globais (0 Unknown, 1 Internal, 2 Access denied, 3 Invalid API path, 4 Resource path is not callable).

Parâmetros

Nome Tipo Obrigatório Descrição
sessionId string Sim Session ID

Exemplo de Resposta

array
  0 =>
    array
      'customer_group_id' => string '0' (length=1)
      'customer_group_code' => string 'NOT LOGGED IN' (length=13)
  1 =>
    array
      'customer_group_id' => string '1' (length=1)
      'customer_group_code' => string 'General' (length=7)
  2 =>
    array
      'customer_group_id' => string '2' (length=1)
      'customer_group_code' => string 'Wholesale' (length=9)
  3 =>
    array
      'customer_group_id' => string '3' (length=1)
      'customer_group_code' => string 'Retailer' (length=8)

Exemplos de Código

SOAP customer_address.list Session_token

Retrieve the list of customer addresses

Retrieve all addresses of a given customer. Retorna array vazio se o customer não tem endereços.

SOAP V2 method: customerAddressList.

Returns

TypeNameDescription
arrayresultArray of customerAddressEntity

Entity: customerAddressEntity (alias de customerAddressEntityItem)

TypeNameDescription
intcustomer_address_idID of the customer address
stringcreated_atDate when the address was created
stringupdated_atDate when the address was updated
stringincrement_idIncrement ID
stringcityCity
stringcompanyName of the company
stringcountry_idISO country ID (ex.: US, BR)
stringfaxFax
stringfirstnameCustomer first name
stringlastnameCustomer last name
stringmiddlenameCustomer middle name
stringpostcodePostcode
stringprefixCustomer prefix
stringregionRegion name
intregion_idRegion ID (lookup via directory_region.list)
stringstreetStreet line(s)
stringsuffixCustomer suffix
stringtelephoneTelephone number
booleanis_default_billingTrue if this is the default billing address
booleanis_default_shippingTrue if this is the default shipping address
Applies resource faults — customer_address (4 faults: 100–103) Ver no overview ↗

Todos os métodos do resource customer_address podem lançar os faults abaixo além dos Global API Faults.

CodeMessage
100Invalid address data. Details in error message.
101Customer not exists.
102Address not exists.
103Address not deleted. Details in error message.

Parâmetros

Nome Tipo Obrigatório Descrição
sessionId string Sim Session ID
customerId int Sim Customer ID

Exemplo de Resposta

array
  0 =>
    array
      'customer_address_id' => string '2' (length=1)
      'created_at' => string '2012-03-29 13:20:08' (length=19)
      'updated_at' => string '2012-03-29 13:39:29' (length=19)
      'city' => string 'Las Vegas' (length=9)
      'country_id' => string 'US' (length=2)
      'firstname' => string 'johny' (length=5)
      'lastname' => string 'doe' (length=3)
      'postcode' => string '89032' (length=5)
      'region' => string 'Nevada' (length=6)
      'region_id' => string '39' (length=2)
      'street' => string '3406 Hiney Road' (length=15)
      'telephone' => string '702-283-9556' (length=12)
      'is_default_billing' => boolean false
      'is_default_shipping' => boolean true

Exemplos de Código

SOAP customer_address.create Session_token

Create a new address for the customer

Create a new address for the specified customer and return its numeric ID. street deve ser um array mesmo com uma única linha. Campos opcionais podem ser omitidos ou enviados como string vazia.

SOAP V2 method: customerAddressCreate.

Returns

TypeNameDescription
intresultID of the created address

Entity: customerAddressEntityCreate

TypeNameDescription
stringcityCity
stringcompanyCompany (optional)
stringcountry_idISO country ID
stringfaxFax (optional)
stringfirstnameFirst name
stringlastnameLast name
stringmiddlenameMiddle name (optional)
stringpostcodePostcode
stringprefixPrefix (optional)
intregion_idRegion ID
stringregionRegion name (use region_id OR region; region_id tem precedência)
ArrayOfStringstreetLista de linhas de endereço (street1, street2, …)
stringsuffixSuffix (optional)
stringtelephoneTelephone
booleanis_default_billingMarca como endereço default de billing
booleanis_default_shippingMarca como endereço default de shipping

Note: If you want to leave any address fields empty, specify them as empty strings in the request body.

Applies resource faults — customer_address (4 faults: 100–103) Ver no overview ↗

Todos os métodos do resource customer_address podem lançar os faults abaixo além dos Global API Faults.

CodeMessage
100Invalid address data. Details in error message.
101Customer not exists.
102Address not exists.
103Address not deleted. Details in error message.

Parâmetros

Nome Tipo Obrigatório Descrição
sessionId string Sim Session ID
customerId int Sim Customer ID (dono do novo endereço)
addressdata customerAddressEntityCreate Sim Dados do endereço (ver schema abaixo)

Exemplos de Código

SOAP customer_address.info Session_token

Retrieve information about the required customer address

Retrieve information about the required customer address by its ID. Retorna o schema completo (customerAddressEntityItem) incluindo os campos vat_* (VAT validation) quando o módulo VAT está habilitado no admin.

SOAP V2 method: customerAddressInfo.

Returns

TypeNameDescription
arrayinfoArray de customerAddressEntityItem (ver schema abaixo)

Entity: customerAddressEntityItem (alias de customerAddressEntity)

TypeNameDescription
intcustomer_address_idID of the customer address
stringcreated_atDate when the address was created
stringupdated_atDate when the address was updated
stringincrement_idIncrement ID
stringcityCity
stringcompanyName of the company
stringcountry_idISO country ID (ex.: US, BR)
stringfaxFax
stringfirstnameCustomer first name
stringlastnameCustomer last name
stringmiddlenameCustomer middle name
stringpostcodePostcode
stringprefixCustomer prefix
stringregionRegion name
intregion_idRegion ID (lookup via directory_region.list)
stringstreetStreet line(s)
stringsuffixCustomer suffix
stringtelephoneTelephone number
booleanis_default_billingTrue if this is the default billing address
booleanis_default_shippingTrue if this is the default shipping address
Applies resource faults — customer_address (4 faults: 100–103) Ver no overview ↗

Todos os métodos do resource customer_address podem lançar os faults abaixo além dos Global API Faults.

CodeMessage
100Invalid address data. Details in error message.
101Customer not exists.
102Address not exists.
103Address not deleted. Details in error message.

Parâmetros

Nome Tipo Obrigatório Descrição
sessionId string Sim Session ID
addressId int Sim Address ID

Exemplo de Resposta

array
  'customer_address_id' => string '2' (length=1)
  'created_at' => string '2012-03-29 13:20:08' (length=19)
  'updated_at' => string '2012-03-29 13:20:08' (length=19)
  'increment_id' => null
  'city' => string 'Las Vegas' (length=9)
  'company' => null
  'country_id' => string 'US' (length=2)
  'fax' => null
  'firstname' => string 'johny' (length=5)
  'lastname' => string 'doe' (length=3)
  'middlename' => null
  'postcode' => string '89032' (length=5)
  'prefix' => null
  'region' => string 'Nevada' (length=6)
  'region_id' => string '39' (length=2)
  'street' => string '3406 Hiney Road' (length=15)
  'suffix' => null
  'telephone' => string '702-283-9556' (length=12)
  'vat_id' => null
  'vat_is_valid' => null
  'vat_request_date' => null
  'vat_request_id' => null
  'vat_request_success' => null
  'is_default_billing' => boolean false
  'is_default_shipping' => boolean true

Exemplos de Código

SOAP customer_address.update Session_token

Update address data of the required customer

Update address data of the required customer. Campos omitidos permanecem inalterados. Para trocar qual endereço é o default de billing/shipping, passe is_default_billing/is_default_shipping explicitamente.

SOAP V2 method: customerAddressUpdate.

Returns

TypeDescription
booleanTrue if the address was updated

Entity: customerAddressEntityCreate

TypeNameDescription
stringcityCity
stringcompanyCompany (optional)
stringcountry_idISO country ID
stringfaxFax (optional)
stringfirstnameFirst name
stringlastnameLast name
stringmiddlenameMiddle name (optional)
stringpostcodePostcode
stringprefixPrefix (optional)
intregion_idRegion ID
stringregionRegion name (use region_id OR region; region_id tem precedência)
ArrayOfStringstreetLista de linhas de endereço (street1, street2, …)
stringsuffixSuffix (optional)
stringtelephoneTelephone
booleanis_default_billingMarca como endereço default de billing
booleanis_default_shippingMarca como endereço default de shipping
Applies resource faults — customer_address (4 faults: 100–103) Ver no overview ↗

Todos os métodos do resource customer_address podem lançar os faults abaixo além dos Global API Faults.

CodeMessage
100Invalid address data. Details in error message.
101Customer not exists.
102Address not exists.
103Address not deleted. Details in error message.

Parâmetros

Nome Tipo Obrigatório Descrição
sessionId string Sim Session ID
addressId int Sim ID do endereço a atualizar
addressdata customerAddressEntityCreate Sim Campos a atualizar

Exemplos de Código

SOAP customer_address.delete Session_token

Delete the required customer address

Delete the required customer address by its ID. Não toca nos demais endereços do customer.

SOAP V2 method: customerAddressDelete.

Returns

TypeDescription
booleanTrue if the address was deleted
Applies resource faults — customer_address (4 faults: 100–103) Ver no overview ↗

Todos os métodos do resource customer_address podem lançar os faults abaixo além dos Global API Faults.

CodeMessage
100Invalid address data. Details in error message.
101Customer not exists.
102Address not exists.
103Address not deleted. Details in error message.

Parâmetros

Nome Tipo Obrigatório Descrição
sessionId string Sim Session ID
addressId int Sim Address ID

Exemplos de Código