Listagem de Clientes

Requisição para a consulta de clientes.

Método GET

https://{api_address}/customers

Código de Exemplo

<?php
    $params["access_token"] = "### Chave de Acesso ###";
    $params["sort"] = "id_desc";

    $url = "https://{api_address}/customers/?".http_build_query($params);

    ob_start();

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
    curl_exec($ch);

    // JSON de retorno  
    $resposta = json_decode(ob_get_contents());
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    ob_end_clean();
    curl_close($ch);

    if($code == "200"){
        //Tratamento dos dados de resposta da consulta.
    }else{
        //Tratamento das mensagens de erro
    }
?>

string URLAuth = "https://{api_address}/customers/";

NameValueCollection queryParameters = new NameValueCollection();

queryParameters.Add("access_token", "### Chave de Acesso ###");    
queryParameters.Add("sort", "id_desc");

List items = new List();

foreach (String name in queryParameters)
    items.Add(String.Concat(name, "=", System.Web.HttpUtility.UrlEncode(queryParameters[name])));

string argsString = String.Join("&", items.ToArray());

WebRequest request = WebRequest.Create(URLAuth + "?" + argsString);
    
request.Credentials = CredentialCache.DefaultCredentials;
    
WebResponse response = request.GetResponse();
  
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
    
Stream dataStream = response.GetResponseStream();
    
StreamReader reader = new StreamReader(dataStream);

string responseData = reader.ReadToEnd();

Console.WriteLine(responseData);
reader.Close();
response.Close();

String url = "https://{api_address}/customers/";

Map<String, String> mapToConvert = new HashMap<>();
mapToConvert.put("access_token", "### Chave de Acesso ###");
mapToConvert.put("sort", "id_desc");

String queryString = "";

for (Entry<String, String> entry : mapToConvert.entrySet()) {
    queryString += entry.getKey()+"="+ entry.getValue()+"&";
}

try {
    URL obj = new URL(url+"?"+queryString);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();
    
    con.setRequestMethod("GET");
    con.setRequestProperty("User-Agent", USER_AGENT);

    int responseCode = con.getResponseCode();

    BufferedReader in ;
    if (responseCode >= 200 && responseCode < 300){
        in = new BufferedReader(
            new InputStreamReader(con.getInputStream()));
    }else{
        in = new BufferedReader(
            new InputStreamReader(con.getErrorStream()));
    }
    
    String inputLine;
    StringBuilder response = new StringBuilder();

    while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
    }
    in.close();
    
    String resposta = response.toString();

} catch (Exception ex){
    // Tratamento da Exception
}

Parâmetros enviados

Field Type Description
access_token String

Chave de acesso

email String

Email do cliente

attrs String

Atributos do cliente

limit Number

Limite de registros

page Number

Página corrente

sort String

Ordenação ex.: [campo]_[asc/desc]

Retorno em caso de sucesso (status code 200 ou 201)

 
Field Type Description
paging Object

Dados de paginação

  total Number

Total de registros

  page Number

Página corrente

  offset Number

Registro inicial da página

  limit Number

Limite de registros

  maxLimit Number

Máximo de registros

sort Object[]

Ordenação

availableFilters String[]

Filtros disponíveis

appliedFilters String[]

Filtros utilizados

Customers Object[]

Lista de clientes

  Customer Object

Dados do cliente

    id Number

Código do cliente

    name String

Nome

    cpf String

CPF

    birth_date Date

Data de aniversário

    gender Number

Sexo (Veja Tabela A)

    email String

E-mail

    cnpj String

CNPJ

    last_visit Date

Data da última visita

    city String

Cidade

    state String

Sigla do estado

    newsletter Number

Newsletter ativa

    created Date

Data de criação

    registration_date Date

Data de registro

    modified Date

Data de modificação

    CustomerAddress Object[]

Endereços do cliente

      id Number

Código do endereço do cliente

Json de Retorno

HTTP/1.1200 OK
{"paging":{"total":6,"page":1,"offset":0,"limit":1,"maxLimit":50},"sort":[{"id":"desc"}],"availableFilters":["id","name","email","cpf","cnpj","created","modified"],"appliedFilters":[],"Customers":[{"Customer":{"id":"123","name":"Nome do Cliente","cpf":"00000000000","birth_date":"0000-00-00","gender":"0","email":"emaildo@cliente.com.br","cnpj":"00.000.000/0000-00","last_visit":"2016-08-15","city":"Cidade do Cliente","state":"SP","newsletter":"1","created":"2008-10-14 18:17:23","registration_date":"2008-10-14","modified":"2016-08-15 18:17:23","CustomerAddress":[{"id":"1"},{"id":"2"}]}}]}

Consultar Dados do Cliente

Requisição para a consulta de dados de um cliente.

 Método GET

https://{api_address}/customers/:id

Código de Exemplo


 

<?php
    $params["access_token"] = "### Chave de Acesso ###";

    $url = "https://{api_address}/customers/123?".http_build_query($params);

    ob_start();

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
    curl_exec($ch);

    // JSON de retorno  
    $resposta = json_decode(ob_get_contents());
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    ob_end_clean();
    curl_close($ch);

    if($code == "200"){
        //Tratamento dos dados de resposta da consulta.
    }else{
        //Tratamento das mensagens de erro
    }
?>

sstring URLAuth = "https://{api_address}/customers/123";

NameValueCollection queryParameters = new NameValueCollection();

queryParameters.Add("access_token", "### Chave de Acesso ###");    

List items = new List();

foreach (String name in queryParameters)
    items.Add(String.Concat(name, "=", System.Web.HttpUtility.UrlEncode(queryParameters[name])));

string argsString = String.Join("&", items.ToArray());

WebRequest request = WebRequest.Create(URLAuth + "?" + argsString);
    
request.Credentials = CredentialCache.DefaultCredentials;
    
WebResponse response = request.GetResponse();
  
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
    
Stream dataStream = response.GetResponseStream();
    
StreamReader reader = new StreamReader(dataStream);

string responseData = reader.ReadToEnd();

Console.WriteLine(responseData);
reader.Close();
response.Close();

String url = "https://{api_address}/customers/123";

Map<String, String> mapToConvert = new HashMap<>();
mapToConvert.put("access_token", "### Chave de Acesso ###");

String queryString = "";

for (Entry<String, String> entry : mapToConvert.entrySet()) {
    queryString += entry.getKey()+"="+ entry.getValue()+"&";
}

try {
    URL obj = new URL(url+"?"+queryString);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();
    
    con.setRequestMethod("GET");
    con.setRequestProperty("User-Agent", USER_AGENT);

    int responseCode = con.getResponseCode();

    BufferedReader in ;
    if (responseCode >= 200 && responseCode < 300){
        in = new BufferedReader(
            new InputStreamReader(con.getInputStream()));
    }else{
        in = new BufferedReader(
            new InputStreamReader(con.getErrorStream()));
    }
    
    String inputLine;
    StringBuilder response = new StringBuilder();

    while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
    }
    in.close();
    
    String resposta = response.toString();

} catch (Exception ex){
    // Tratamento da Exception
}

Parâmetros enviados

Field Type Description
access_token String

Chave de acesso

:id Number

Código do cliente

 

Retorno em caso de sucesso (status code 200 ou 201)

 
Field Type Description
Customer Object

Dados do cliente

  id Number

Código do cliente

  name String

Nome

  rg String

RG

  cpf String

CPF

  phone String

Telefone fixo

  cellphone String

Telefone celular

  birth_date Date

Data de aniversário

  gender Number

Sexo (Veja Tabela A)

  email String

E-mail

  nickname String

Apelido

  token String

Chave única do cliente

  total_orders Number

Total de pedidos

  observation String

Informações sobre o cliente

  type Number

Tipo de cliente (Veja Tabela B)

  cnpj String

CNPJ

  company_name String

Razão social

  state_inscription String

Inscrição estatual

  reseller Number

Cliente revendedor

  discount Decimal

Valor de desconto

  blocked Number

Cliente bloqueado (Veja Tabela C)

  credit_limit Decimal

Valor de crédito

  indicator_id Number

Código de indicação

  profile_customer_id Number

Código do perfil do cliente

  last_sending_newsletter Date

Data do último envio de newsletter

  last_purchase Date

Data da última compra

  last_visit Date

Data da última visita

  last_modification Date

Data de modificação

  address String

Logradouro

  zip_code String

CEP

  number Number

Número do endereço

  complement String

Complemento

  neighborhood String

Bairro

  city String

Cidade

  state String

Sigla do estado

  newsletter Number

Newsletter ativa

  created Date

Data de criação

  registration_date Date

Data de registro

  modified Date

Data de modificação

  CustomerAddress Object[]

Endereços do cliente

    id Number

Código do endereço do cliente

 

Json de Retorno

HTTP/1.1 200 OK
{
    "Customer": {
        "id": "123",
        "name": "Nome do Cliente",
        "rg": "00.000.000-0",
        "cpf": "00000000000",
        "phone": "1133330000",
        "cellphone": "11999990000",
        "birth_date": "0000-00-00",
        "gender": "0",
        "email": "emaildo@cliente.com.br",
        "nickname": "",
        "token": "123QWE123QWE123ASD",
        "total_orders": "8",
        "observation": "",
        "type": "1",
        "cnpj": "00.000.000/0000-00",
        "company_name": "Razão Social do Cliente",
        "state_inscription": "Isento",
        "reseller": "0",
        "discount": "0.00",
        "blocked": "0",
        "credit_limit": "10.00",
        "indicator_id": "0",
        "profile_customer_id": "1",
        "last_sending_newsletter": "2016-08-02",
        "last_purchase": "2016-08-02",
        "last_visit": "2016-08-15",
        "last_modification": "0000-00-00 00:00:00",
        "address": "Endereço do Cliente",
        "zip_code": "04001-001",
        "number": "123",
        "complement": "Sala 123",
        "neighborhood": "Bairro do Cliente",
        "city": "Cidade do Cliente",
        "state": "SP",
        "newsletter": "1",
        "created": "2008-10-14 18:17:23",
        "registration_date": "2008-10-14",
        "modified": "2016-08-15 18:17:23",
        "CustomerAddress": [
            {
                "id": "1"
            },
            {
                "id": "2"
            }
        ]
    }
}

Cadastrar Cliente

Requisição para inclusão de um cliente. Deverá enviar o JSON com os dados do cliente para a criação.

 Método POST

https://{api_address}/customers

Código de Exemplo


 

<?php
    $params["access_token"] = "### Chave de Acesso ###";

    $data["Customer"]["name"] = "Nome do Cliente";
    $data["Customer"]["rg"] = "00.000.000-0";
    $data["Customer"]["cpf"] = "00000000000";
    $data["Customer"]["phone"] = "1133330000";
    $data["Customer"]["cellphone"] = "11999990000";
    $data["Customer"]["birth_date"] = "0000-00-00";
    $data["Customer"]["gender"] = "0";
    $data["Customer"]["email"] = "emaildo@cliente.com.br";
    $data["Customer"]["nickname"] = "";
    $data["Customer"]["observation"] = "";
    $data["Customer"]["type"] = "1";
    $data["Customer"]["company_name"] = "Razão Social do Cliente";
    $data["Customer"]["cnpj"] = "00.000.000/0000-00";
    $data["Customer"]["state_inscription"] = "Isento";
    $data["Customer"]["reseller"] = "0";
    $data["Customer"]["discount"] = "0";
    $data["Customer"]["blocked"] = "0";
    $data["Customer"]["credit_limit"] = "0";
    $data["Customer"]["indicator_id"] = "0";
    $data["Customer"]["profile_customer_id"] = "1";
    $data["Customer"]["address"] = "Endereço do Cliente";
    $data["Customer"]["zip_code"] = "04001-001";
    $data["Customer"]["number"] = "123";
    $data["Customer"]["complement"] = "Sala 123";
    $data["Customer"]["neighborhood"] = "Bairro do Cliente";
    $data["Customer"]["city"] = "Cidade do Cliente";
    $data["Customer"]["state"] = "SP";
    $data["Customer"]["newsletter"] = "1";
    $data["Customer"]["CustomerAddress"][0]["recipient"] = "Nome do Cliente";
    $data["Customer"]["CustomerAddress"][0]["address"] = "Outro Endereço do Cliente";
    $data["Customer"]["CustomerAddress"][0]["number"] = "456";
    $data["Customer"]["CustomerAddress"][0]["complement"] = "Sala 456";
    $data["Customer"]["CustomerAddress"][0]["neighborhood"] = "Bairro do Cliente";
    $data["Customer"]["CustomerAddress"][0]["city"] = "Cidade do Cliente";
    $data["Customer"]["CustomerAddress"][0]["state"] = "SP";
    $data["Customer"]["CustomerAddress"][0]["zip_code"] = "04001-001";
    $data["Customer"]["CustomerAddress"][0]["country"] = "BRA";
    $data["Customer"]["CustomerAddress"][0]["type"] = "1";
    $data["Customer"]["CustomerAddress"][0]["active"] = "1";
    $data["Customer"]["CustomerAddress"][0]["description"] = "";

    $url = "https://{api_address}/customers/?".http_build_query($params);

    ob_start();

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Content-Length: ' . strlen(json_encode($data)))
    );
    curl_exec($ch);

    // JSON de retorno  
    $resposta = json_decode(ob_get_contents());
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    ob_end_clean();
    curl_close($ch);

    if($code == "201"){
        //Tratamento dos dados de resposta da consulta.
    }else{
        //Tratamento das mensagens de erro
    }
?>

string URLAuth = "https://{api_address}/customers/";

NameValueCollection queryParameters = new NameValueCollection();

queryParameters.Add("access_token", "### Chave de Acesso ###");

List items = new List();

foreach (String name in queryParameters)
    items.Add(String.Concat(name, "=", System.Web.HttpUtility.UrlEncode(queryParameters[name])));

string argsString = String.Join("&", items.ToArray());

string postString  = "{";
       postString += "  \"Customer\": {";
       postString += "      \"name\": \"Nome do Cliente\",";
       postString += "      \"rg\": \"00.000.000-0\",";
       postString += "      \"cpf\": \"00000000000\",";
       postString += "      \"phone\": \"1133330001\",";
       postString += "      \"cellphone\": \"11999990000\",";
       postString += "      \"birth_date\": \"0000-00-00\",";
       postString += "      \"gender\": \"M\",";
       postString += "      \"email\": \"email@doscliente.com\",";
       postString += "      \"nickname\": \"\",";
       postString += "      \"observation\": \"\",";
       postString += "      \"type\": \"1\",";
       postString += "      \"company_name\": \"Razão Social do Cliente\",";
       postString += "      \"cnpj\": \"00.000.000/0000-00\",";
       postString += "      \"state_inscription\": \"Isento\",";
       postString += "      \"reseller\": \"0\",";
       postString += "      \"discount\": \"0\",";
       postString += "      \"blocked\": \"0\",";
       postString += "      \"credit_limit\": \"0\",";
       postString += "      \"indicator_id\": \"0\",";
       postString += "      \"profile_customer_id\": \"1\",";
       postString += "      \"address\": \"Endereço do Cliente\",";
       postString += "      \"zip_code\": \"04001-001\",";
       postString += "      \"number\": \"123\",";
       postString += "      \"complement\": \"Sala 123\",";
       postString += "      \"neighborhood\": \"Bairro do Cliente\",";
       postString += "      \"city\": \"Cidade do Cliente\",";
       postString += "      \"state\": \"SP\",";
       postString += "      \"newsletter\": \"1\",";
       postString += "      \"CustomerAddress\": [";
       postString += "          {";
       postString += "              \"recipient\": \"Nome do Cliente\",";
       postString += "              \"address\": \"Outro Endereço do Cliente\",";
       postString += "              \"number\": \"456\",";
       postString += "              \"complement\": \"Sala 456\",";
       postString += "              \"neighborhood\": \"Bairro do Cliente\",";
       postString += "              \"city\": \"Cidade do Cliente\",";
       postString += "              \"state\": \"SP\",";
       postString += "              \"zip_code\": \"04001-001\",";
       postString += "              \"country\": \"BRA\",";
       postString += "              \"type\": \"1\",";
       postString += "              \"active\": \"1\",";
       postString += "              \"description\": \"0\"";
       postString += "          }";
       postString += "      ]";
       postString += "  }";
       postString += "}";

HttpWebRequest webRequest = WebRequest.Create(URLAuth + "?" + argsString) as HttpWebRequest;
webRequest.Method = "POST";
webRequest.ContentType = "application/json";

StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream());
requestWriter.Write(postString);
requestWriter.Close();

StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());
string responseData = responseReader.ReadToEnd();

responseReader.Close();
webRequest.GetResponse().Close();

String url = "https://{api_address}/customers/";
StringBuffer response = null ;
try{
    String access_token = "?access_token=### Chave de Acesso ###";
    
    URL obj = new URL(url+access_token);
    HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();

    //add reuqest header
    con.setRequestMethod("POST");
    con.setRequestProperty("User-Agent", USER_AGENT);
    con.setRequestProperty("Content-Type", "application/json");
    con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");

    String postString  = "{";
           postString += "  \"Customer\": {";
           postString += "      \"name\": \"Nome do Cliente\",";
           postString += "      \"rg\": \"00.000.000-0\",";
           postString += "      \"cpf\": \"00000000000\",";
           postString += "      \"phone\": \"1133330001\",";
           postString += "      \"cellphone\": \"11999990000\",";
           postString += "      \"birth_date\": \"0000-00-00\",";
           postString += "      \"gender\": \"M\",";
           postString += "      \"email\": \"email@doscliente.com\",";
           postString += "      \"nickname\": \"\",";
           postString += "      \"observation\": \"\",";
           postString += "      \"type\": \"1\",";
           postString += "      \"company_name\": \"Razão Social do Cliente\",";
           postString += "      \"cnpj\": \"00.000.000/0000-00\",";
           postString += "      \"state_inscription\": \"Isento\",";
           postString += "      \"reseller\": \"0\",";
           postString += "      \"discount\": \"0\",";
           postString += "      \"blocked\": \"0\",";
           postString += "      \"credit_limit\": \"0\",";
           postString += "      \"indicator_id\": \"0\",";
           postString += "      \"profile_customer_id\": \"1\",";
           postString += "      \"address\": \"Endereço do Cliente\",";
           postString += "      \"zip_code\": \"04001-001\",";
           postString += "      \"number\": \"123\",";
           postString += "      \"complement\": \"Sala 123\",";
           postString += "      \"neighborhood\": \"Bairro do Cliente\",";
           postString += "      \"city\": \"Cidade do Cliente\",";
           postString += "      \"state\": \"SP\",";
           postString += "      \"newsletter\": \"1\",";
           postString += "      \"CustomerAddress\": [";
           postString += "          {";
           postString += "              \"recipient\": \"Nome do Cliente\",";
           postString += "              \"address\": \"Outro Endereço do Cliente\",";
           postString += "              \"number\": \"456\",";
           postString += "              \"complement\": \"Sala 456\",";
           postString += "              \"neighborhood\": \"Bairro do Cliente\",";
           postString += "              \"city\": \"Cidade do Cliente\",";
           postString += "              \"state\": \"SP\",";
           postString += "              \"zip_code\": \"04001-001\",";
           postString += "              \"country\": \"BRA\",";
           postString += "              \"type\": \"1\",";
           postString += "              \"active\": \"1\",";
           postString += "              \"description\": \"0\"";
           postString += "          }";
           postString += "      ]";
           postString += "  }";
           postString += "}";
           
    // Send post request
    con.setDoOutput(true);
    DataOutputStream wr = new DataOutputStream(con.getOutputStream());
    wr.writeBytes(postString);
    wr.flush();
    wr.close();

    int responseCode = con.getResponseCode();

    BufferedReader in ;
    if (responseCode >= 200 && responseCode < 300){
        in = new BufferedReader(
            new InputStreamReader(con.getInputStream()));
    }else{
        in = new BufferedReader(
            new InputStreamReader(con.getErrorStream()));
    }
    
    String inputLine;
    response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
    }
    in.close();

} catch (Exception ex){
    // Tratamento da Exception
}
String resposta = response.toString();

Parâmetros enviados

Field Type Description
access_token String

Chave de acesso

Customer JSON

Dados do cliente

  name String

Nome

  rg String

RG

  cpf String

CPF

  phone String

Telefone fixo

  cellphone String

Telefone celular

  birth_date Date

Data de aniversário

  gender Number

Sexo (Veja Tabela A)

  email String

E-mail

  nickname String

Apelido

  observation String

Informações sobre o cliente

  type Number

Tipo de cliente (Veja Tabela B)

  company_name String

Razão social

  cnpj String

CNPJ

  state_inscription String

Inscrição estatual

  reseller Number

Cliente revendedor

  discount Decimal

Valor de desconto

  blocked Number

Cliente bloqueado (Veja Tabela C)

  credit_limit Decimal

Valor de crédito

  indicator_id Number

Código de indicação

  profile_customer_id Number

Código do perfil do cliente

  address String

Logradouro

  zip_code String

CEP

  number Number

Número do endereço

  complement String

Complemento

  neighborhood String

Bairro

  city String

Cidade

  state String

Sigla do estado

  newsletter Number

Newsletter ativa

  CustomerAddress Object[]

Endereços do cliente

    recipient String

Nome do cliente

    address String

Logradouro

    number Number

Número do endereço

    complement String

Complemento

    neighborhood String

Bairro

    city String

Cidade

    state String

Sigla do estado

    zip_code String

CEP

    country String

País

    type Number

Tipo de endereço (Veja Tabela D)

    active Number

Endereço ativo (Veja Tabela E)

    description String

Descrição do Endereço

Estrutura de Json

POST /customers/?access_token=abc96fb7b1defd2496b9a9d81071fa12319b12306465e057d0ebca9bd9ab19
{
    "Customer": {
        "name": "Nome do Cliente",
        "rg": "00.000.000-0",
        "cpf": "00000000000",
        "phone": "1133330000",
        "cellphone": "11999990000",
        "birth_date": "0000-00-00",
        "gender": "0",
        "email": "emaildo@cliente.com.br",
        "nickname": "",
        "observation": "",
        "type": "1",
        "company_name": "Razão Social do Cliente",
        "cnpj": "00.000.000/0000-00",
        "state_inscription": "Isento",
        "reseller": "0",
        "discount": "0",
        "blocked": "0",
        "credit_limit": "0",
        "indicator_id": "0",
        "profile_customer_id": "1",
        "address": "Endereço do Cliente",
        "zip_code": "04001-001",
        "number": "123",
        "complement": "Sala 123",
        "neighborhood": "Bairro do Cliente",
        "city": "Cidade do Cliente",
        "state": "SP",
        "newsletter": "1",
        "CustomerAddress": [
            {
                "recipient": "Nome do Cliente",
                "address": "Outro Endereço do Cliente",
                "number": "456",
                "complement": "Sala 456",
                "neighborhood": "Bairro do Cliente",
                "city": "Cidade do Cliente",
                "state": "SP",
                "zip_code": "04001-001",
                "country": "BRA",
                "type": "1",
                "active": "1",
                "description": ""
            }
        ]
    }
}

Retorno em caso de sucesso (status code 200 ou 201)

Field Type Description
message String

Mensagem de retorno

id Number

Código do cliente

code Number

Código do retorno (201)

 

Json de retorno

HTTP/1.1 201 OK
{
    "message": "Created",
    "id": "123",
    "code": 201
}

Atualizar Dados do Cliente

Requisição para alterar os dados de um cliente. Deverá enviar o JSON com os dados do cliente para a alteração.

Método PUT

https://{api_address}/customers/:id

Código de Exemplo

<?php
    $params["access_token"] = "### Chave de Acesso ###";

    $data["Customer"]["name"] = "Nome do Cliente";
    $data["Customer"]["rg"] = "00.000.000-0";
    $data["Customer"]["cpf"] = "00000000000";
    $data["Customer"]["phone"] = "1133330000";
    $data["Customer"]["cellphone"] = "11999990000";
    $data["Customer"]["birth_date"] = "0000-00-00";
    $data["Customer"]["gender"] = "0";
    $data["Customer"]["email"] = "emaildo@cliente.com.br";
    $data["Customer"]["nickname"] = "";
    $data["Customer"]["observation"] = "";
    $data["Customer"]["type"] = "1";
    $data["Customer"]["company_name"] = "Razão Social do Cliente";
    $data["Customer"]["cnpj"] = "00.000.000/0000-00";
    $data["Customer"]["state_inscription"] = "Isento";
    $data["Customer"]["reseller"] = "0";
    $data["Customer"]["discount"] = "0";
    $data["Customer"]["blocked"] = "0";
    $data["Customer"]["credit_limit"] = "0";
    $data["Customer"]["indicator_id"] = "0";
    $data["Customer"]["profile_customer_id"] = "1";
    $data["Customer"]["newsletter"] = "1";

    $url = "https://{api_address}/customers/123?".http_build_query($params);

    ob_start();

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Content-Length: ' . strlen(json_encode($data)))
    );
    curl_exec($ch);

    // JSON de retorno  
    $resposta = json_decode(ob_get_contents());
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    ob_end_clean();
    curl_close($ch);

    if($code == "200"){
        //Tratamento dos dados de resposta da consulta.
    }else{
        //Tratamento das mensagens de erro
    }
?>

string URLAuth = "https://{api_address}/customers/123";

NameValueCollection queryParameters = new NameValueCollection();

queryParameters.Add("access_token", "### Chave de Acesso ###");

List items = new List();

foreach (String name in queryParameters)
    items.Add(String.Concat(name, "=", System.Web.HttpUtility.UrlEncode(queryParameters[name])));

string argsString = String.Join("&", items.ToArray());

string putString  = "{";
       putString += "  \"Customer\": {";
       putString += "      \"name\": \"Nome do Cliente\",";
       putString += "      \"rg\": \"00.000.000-0\",";
       putString += "      \"cpf\": \"00000000000\",";
       putString += "      \"phone\": \"1133330001\",";
       putString += "      \"cellphone\": \"11999990000\",";
       putString += "      \"birth_date\": \"0000-00-00\",";
       putString += "      \"gender\": \"M\",";
       putString += "      \"email\": \"email@doscliente.com\",";
       putString += "      \"nickname\": \"\",";
       putString += "      \"observation\": \"\",";
       putString += "      \"type\": \"1\",";
       putString += "      \"company_name\": \"Razão Social do Cliente\",";
       putString += "      \"cnpj\": \"00.000.000/0000-00\",";
       putString += "      \"state_inscription\": \"Isento\",";
       putString += "      \"reseller\": \"0\",";
       putString += "      \"discount\": \"0\",";
       putString += "      \"blocked\": \"0\",";
       putString += "      \"credit_limit\": \"0\",";
       putString += "      \"indicator_id\": \"0\",";
       putString += "      \"profile_customer_id\": \"1\",";
       putString += "      \"newsletter\": \"1\",";
       putString += "  }";
       putString += "}";

HttpWebRequest webRequest = WebRequest.Create(URLAuth + "?" + argsString) as HttpWebRequest;
webRequest.Method = "PUT";
webRequest.ContentType = "application/json";

StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream());
requestWriter.Write(putString);
requestWriter.Close();

StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());
string responseData = responseReader.ReadToEnd();

responseReader.Close();
webRequest.GetResponse().Close();

String url = "https://{api_address}/customers/123";
StringBuffer response = null ;
try{
    String access_token = "?access_token=### Chave de Acesso ###";
    
    URL obj = new URL(url+access_token);
    HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();

    //add reuqest header
    con.setRequestMethod("PUT");
    con.setRequestProperty("User-Agent", USER_AGENT);
    con.setRequestProperty("Content-Type", "application/json");
    con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");

    String putString  = "{";
           putString += "  \"Customer\": {";
           putString += "      \"name\": \"Nome do Cliente\",";
           putString += "      \"rg\": \"00.000.000-0\",";
           putString += "      \"cpf\": \"00000000000\",";
           putString += "      \"phone\": \"1133330001\",";
           putString += "      \"cellphone\": \"11999990000\",";
           putString += "      \"birth_date\": \"0000-00-00\",";
           putString += "      \"gender\": \"M\",";
           putString += "      \"email\": \"email@doscliente.com\",";
           putString += "      \"nickname\": \"\",";
           putString += "      \"observation\": \"\",";
           putString += "      \"type\": \"1\",";
           putString += "      \"company_name\": \"Razão Social do Cliente\",";
           putString += "      \"cnpj\": \"00.000.000/0000-00\",";
           putString += "      \"state_inscription\": \"Isento\",";
           putString += "      \"reseller\": \"0\",";
           putString += "      \"discount\": \"0\",";
           putString += "      \"blocked\": \"0\",";
           putString += "      \"credit_limit\": \"0\",";
           putString += "      \"indicator_id\": \"0\",";
           putString += "      \"profile_customer_id\": \"1\",";
           putString += "      \"newsletter\": \"1\",";
           putString += "  }";
           putString += "}";
           
    // Send put request
    con.setDoOutput(true);
    DataOutputStream wr = new DataOutputStream(con.getOutputStream());
    wr.writeBytes(putString);
    wr.flush();
    wr.close();

    int responseCode = con.getResponseCode();

    BufferedReader in ;
    if (responseCode == 200){
        in = new BufferedReader(
            new InputStreamReader(con.getInputStream()));
    }else{
        in = new BufferedReader(
            new InputStreamReader(con.getErrorStream()));
    }
    
    String inputLine;
    response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
    }
    in.close();

} catch (Exception ex){
    // Tratamento da Exception
}
String resposta = response.toString();

Parâmetros enviados

Field Type Description
access_token String

Chave de acesso

:id Number

Código do cliente

Customer JSON

Dados do cliente

  name String

Nome

  rg String

RG

  cpf String

CPF

  phone String

Telefone fixo

  cellphone String

Telefone celular

  birth_date Date

Data de aniversário

  gender Number

Sexo (Veja Tabela A)

  email String

E-mail

  nickname String

Apelido

  observation String

Informações sobre o cliente

  type Number

Tipo de cliente (Veja Tabela B)

  company_name String

Razão social

  cnpj String

CNPJ

  state_inscription String

Inscrição estatual

  reseller Number

Cliente revendedor

  discount Decimal

Valor de desconto

  blocked Number

Cliente bloqueado (Veja Tabela C)

  credit_limit Decimal

Valor de crédito

  indicator_id Number

Código de indicação

  profile_customer_id Number

Código do perfil do cliente

  newsletter Number

Newsletter ativa

 

Estrutura de Json

PUT /customers/123?access_token=abc96fb7b1defd2496b9a9d81071fa12319b12306465e057d0ebca9bd9ab19
{"Customer":{"name":"Nome do Cliente","rg":"00.000.000-0","cpf":"00000000000","phone":"1133330000","cellphone":"11999990000","birth_date":"0000-00-00","gender":"0","email":"emaildo@cliente.com.br","nickname":"","observation":"","type":"1","company_name":"Razão Social do Cliente","cnpj":"00.000.000/0000-00","state_inscription":"Isento","reseller":"0","discount":"0","blocked":"0","credit_limit":"0","indicator_id":"0","profile_customer_id":"1","newsletter":"1"}}

Retorno em caso de sucesso (status code 200 ou 201)

Field Type Description
message String

Mensagem de retorno

id Number

Código do cliente

code Number

Código do retorno (200)

Json de retorno

HTTP/1.1200 OK
{"message":"Saved","id":"123","code":200}

Excluir Cliente

Requisição para excluir um cliente.

 Método DELETE

https://{api_address}/customers/:id

Código de Exemplo


 

<?php
     $params["access_token"] = "### Chave de Acesso ###";

    $url = "https://{api_address}/customers/123?".http_build_query($params);

    ob_start();

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Content-Length: ' . strlen(json_encode($data)))
    );
    curl_exec($ch);

    // JSON de retorno  
    $resposta = json_decode(ob_get_contents());
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    ob_end_clean();
    curl_close($ch);

    if($code == "200"){
        //Tratamento dos dados de resposta da consulta.
    }else{
        //Tratamento das mensagens de erro
    }
?>

string URLAuth = "https://{api_address}/customers/123";

NameValueCollection queryParameters = new NameValueCollection();

queryParameters.Add("access_token", "### Chave de Acesso ###");

List items = new List();

foreach (String name in queryParameters)
    items.Add(String.Concat(name, "=", System.Web.HttpUtility.UrlEncode(queryParameters[name])));

string argsString = String.Join("&", items.ToArray());

HttpWebRequest webRequest = WebRequest.Create(URLAuth + "?" + argsString) as HttpWebRequest;
webRequest.Method = "DELETE";
webRequest.ContentType = "application/json";

StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());
string responseData = responseReader.ReadToEnd();

responseReader.Close();
webRequest.GetResponse().Close();

String url = "https://{api_address}/customers/123";
StringBuffer response = null ;
try{
    String access_token = "?access_token=### Chave de Acesso ###";
    
    URL obj = new URL(url+access_token);
    HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();

    //add reuqest header
    con.setRequestMethod("DELETE");
    con.setRequestProperty("User-Agent", USER_AGENT);
    con.setRequestProperty("Content-Type", "application/json");
    con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");

    int responseCode = con.getResponseCode();

    BufferedReader in ;
    if (responseCode == 200){
        in = new BufferedReader(
            new InputStreamReader(con.getInputStream()));
    }else{
        in = new BufferedReader(
            new InputStreamReader(con.getErrorStream()));
    }
    
    String inputLine;
    response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
    }
    in.close();

} catch (Exception ex){
    // Tratamento da Exception
}
String resposta = response.toString();

Parâmetros enviados

Field Type Description
access_token String

Chave de acesso

:id Number

Código do cliente

Retorno em caso de sucesso (status code 200 ou 201)

 
Field Type Description
message String

Mensagem de retorno

id Number

Código do cliente

code Number

Código do retorno (200)

Json de retorno

HTTP/1.1 200 OK
{
    "message": "Deleted",
    "id": "123",
    "code": 200
}
 

Listagem de Endereços de Cliente

Requisição para a consulta de diversos endereços do cliente.

Método GET

https://{api_address}/customers/addresses

Código de Exemplo

<?php
    $params["access_token"] = "### Chave de Acesso ###";
    $params["sort"] = "id_desc";

    $url = "https://{api_address}/customers/addresses/?".http_build_query($params);

    ob_start();

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
    curl_exec($ch);

    // JSON de retorno  
    $resposta = json_decode(ob_get_contents());
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    ob_end_clean();
    curl_close($ch);

    if($code == "200"){
        //Tratamento dos dados de resposta da consulta.
    }else{
        //Tratamento das mensagens de erro
    }
?>

string URLAuth = "https://{api_address}/customers/addresses/";

NameValueCollection queryParameters = new NameValueCollection();

queryParameters.Add("access_token", "### Chave de Acesso ###");    
queryParameters.Add("sort", "id_desc");

List items = new List();

foreach (String name in queryParameters)
    items.Add(String.Concat(name, "=", System.Web.HttpUtility.UrlEncode(queryParameters[name])));

string argsString = String.Join("&", items.ToArray());

WebRequest request = WebRequest.Create(URLAuth + "?" + argsString);
    
request.Credentials = CredentialCache.DefaultCredentials;
    
WebResponse response = request.GetResponse();
  
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
    
Stream dataStream = response.GetResponseStream();
    
StreamReader reader = new StreamReader(dataStream);

string responseData = reader.ReadToEnd();

Console.WriteLine(responseData);
reader.Close();
response.Close();

String url = "https://{api_address}/customers/addresses/";

Map<String, String> mapToConvert = new HashMap<>();
mapToConvert.put("access_token", "### Chave de Acesso ###");
mapToConvert.put("sort", "id_desc");

String queryString = "";

for (Entry<String, String> entry : mapToConvert.entrySet()) {
    queryString += entry.getKey()+"="+ entry.getValue()+"&";
}

try {
    URL obj = new URL(url+"?"+queryString);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();
    
    con.setRequestMethod("GET");
    con.setRequestProperty("User-Agent", USER_AGENT);

    int responseCode = con.getResponseCode();

    BufferedReader in ;
    if (responseCode >= 200 && responseCode < 300){
        in = new BufferedReader(
            new InputStreamReader(con.getInputStream()));
    }else{
        in = new BufferedReader(
            new InputStreamReader(con.getErrorStream()));
    }
    
    String inputLine;
    StringBuilder response = new StringBuilder();

    while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
    }
    in.close();
    
    String resposta = response.toString();

} catch (Exception ex){
    // Tratamento da Exception
}

Parâmetros enviados

Field Type Description
access_token String

Chave de acesso

attrs String

Atributos do endereço do cliente

limit Number

Limite de registros

page Number

Página corrente

sort String

Ordenação ex.: [campo]_[asc/desc]

Retorno em caso de sucesso (status code 200 ou 201)

 
Field Type Description
paging Object

Dados de paginação

  total Number

Total de registros

  page Number

Página corrente

  offset Number

Registro inicial da página

  limit Number

Limite de registros

  maxLimit Number

Máximo de registros

sort Object[]

Ordenação

availableFilters String[]

Filtros disponíveis

appliedFilters String[]

Filtros utilizados

CustomerAddresses Object[]

Lista de endereços do cliente

  CustomerAddress Object

Dados do endereço do cliente

    id String

Código do endereço

    customer_id String

Código do cliente

    address String

Endereço do Cliente

    number String

Numero do endereço do Cliente

    complement String

Complemento do endereço do Cliente

    neighborhood String

Bairro do Cliente

    city String

Cidade

    state String

Sigla do estado

    zip_code String

CEP

    country String

País

    type Number

Tipo do Endereço. Tabela B

    active Number

Endereço ativo (Veja Tabela E)

    description String

Descrição do Endereço

    recipient String

 Nome do Cliente

    type_delivery Number

 

  no_list Number

 

 

Json de Retorno

HTTP/1.1200 OK
        {
    "paging": {
        "total": 3,
        "page": 1,
        "offset": 0,
        "limit": 30,
        "maxLimit": 50
    },
    "sort": [
        {
            "id": "asc"
        }
    ],
    "availableFilters": [
        "customer_id",
        "type",
        "not_list"
    ],
    "appliedFilters": {
        "CustomerAddress.customer_id !=": "0"
    },
    "CustomerAddresses": [
        {
            "CustomerAddress": {
                "id": "1",
                "customer_id": "1",
                "address": "Nome da Rua do Cliente",
                "number": "130",
                "complement": "",
                "neighborhood": "Bairro do Cliente",
                "city": "Cidade do Cliente",
                "state": "SP",
                "zip_code": "04001-001",
                "country": "Brasil",
                "type": "1",
                "active": "0",
                "description": "",
                "recipient": "",
                "type_delivery": "1",
                "not_list": "0"
            }
        }
    ]
}

Consultar Dados do Endereço

Requisição para a consulta de dados de um endereço do cliente.

 Método GET

https://{api_address}/customers/addresses/:id

Código de Exemplo


 

<?php
    $params["access_token"] = "### Chave de Acesso ###";

    $url = "https://{api_address}/customers/addresses/123?".http_build_query($params);

    ob_start();

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
    curl_exec($ch);

    // JSON de retorno  
    $resposta = json_decode(ob_get_contents());
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    ob_end_clean();
    curl_close($ch);

    if($code == "200"){
        //Tratamento dos dados de resposta da consulta.
    }else{
        //Tratamento das mensagens de erro
    }
?>

string URLAuth = "https://{api_address}/customers/addresses/123";

NameValueCollection queryParameters = new NameValueCollection();

queryParameters.Add("access_token", "### Chave de Acesso ###");    

List items = new List();

foreach (String name in queryParameters)
    items.Add(String.Concat(name, "=", System.Web.HttpUtility.UrlEncode(queryParameters[name])));

string argsString = String.Join("&", items.ToArray());

WebRequest request = WebRequest.Create(URLAuth + "?" + argsString);
    
request.Credentials = CredentialCache.DefaultCredentials;
    
WebResponse response = request.GetResponse();
  
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
    
Stream dataStream = response.GetResponseStream();
    
StreamReader reader = new StreamReader(dataStream);

string responseData = reader.ReadToEnd();

Console.WriteLine(responseData);
reader.Close();
response.Close();

String url = "https://{api_address}/customers/addresses/123";

Map<String, String> mapToConvert = new HashMap<>();
mapToConvert.put("access_token", "### Chave de Acesso ###");

String queryString = "";

for (Entry<String, String> entry : mapToConvert.entrySet()) {
    queryString += entry.getKey()+"="+ entry.getValue()+"&";
}

try {
    URL obj = new URL(url+"?"+queryString);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();
    
    con.setRequestMethod("GET");
    con.setRequestProperty("User-Agent", USER_AGENT);

    int responseCode = con.getResponseCode();

    BufferedReader in ;
    if (responseCode >= 200 && responseCode < 300){
        in = new BufferedReader(
            new InputStreamReader(con.getInputStream()));
    }else{
        in = new BufferedReader(
            new InputStreamReader(con.getErrorStream()));
    }
    
    String inputLine;
    StringBuilder response = new StringBuilder();

    while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
    }
    in.close();
    
    String resposta = response.toString();

} catch (Exception ex){
    // Tratamento da Exception
}

 

Parâmetros enviados

Field Type Description
access_token String

Chave de acesso

:id Number

Código do endereço do cliente

Retorno em caso de sucesso (status code 200 ou 201)

Field Type Description
CustomerAddress Object

Endereços do cliente

  id String

Código do endereço do cliente

  customer_id String

Código do cliente

  recipient String

Nome do cliente

  address String

Logradouro

  number Number

Número do endereço

  complement String

Complemento

  neighborhood String

Bairro

  city String

Cidade

  state String

Sigla do estado

  zip_code String

CEP

  country String

País

  type Number

Tipo de endereço (Veja Tabela D)

  active Number

Endereço ativo (Veja Tabela E)

  description String

Descrição do Endereço

  type_delivery Number

 

  not_list Number

 

Json de Retorno

HTTP/1.1 200 OK
{
    "CustomerAddress": {
        "id": "123",
        "customer_id": "123",
        "address": "Endereço do Cliente",
        "number": "123",
        "complement": "",
        "neighborhood": "Bairro do Cliente",
        "city": "Cidade do Cliente",
        "state": "SP",
        "zip_code": "04001-001",
        "country": "BRA",
        "type": "1",
        "active": "0",
        "description": "",
        "recipient": "",
        "type_delivery": "1",
        "not_list": "0"
    }
}

Cadastrar Endereço

Requisição para inclusão de um endereço do cliente. Deverá enviar o JSON com os dados do endereço para a criação.

Método POST

https://{api_address}/customers/addresses

Código de Exemplo

<?php
 $params["access_token"] = "### Chave de Acesso ###";

    $data["CustomerAddress"]["customer_id"] = "123";
    $data["CustomerAddress"]["recipient"] = "";
    $data["CustomerAddress"]["address"] = "Endereço do Cliente";
    $data["CustomerAddress"]["number"] = "123";
    $data["CustomerAddress"]["complement"] = "Sala 123";
    $data["CustomerAddress"]["neighborhood"] = "Bairro do Cliente";
    $data["CustomerAddress"]["city"] = "Cidade do Cliente";
    $data["CustomerAddress"]["state"] = "SP";
    $data["CustomerAddress"]["zip_code"] = "04001001";
    $data["CustomerAddress"]["country"] = "BRA";
    $data["CustomerAddress"]["type"] = "1";
    $data["CustomerAddress"]["active"] = "1";
    $data["CustomerAddress"]["description"] = "1";

    $url = "https://{api_address}/customers/addresses/?".http_build_query($params);

    ob_start();

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Content-Length: ' . strlen(json_encode($data)))
    );
    curl_exec($ch);

    // JSON de retorno  
    $resposta = json_decode(ob_get_contents());
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    ob_end_clean();
    curl_close($ch);

    if($code == "201"){
        //Tratamento dos dados de resposta da consulta.
    }else{
        //Tratamento das mensagens de erro
    }
?>

string URLAuth = "https://{api_address}/customers/addresses/";

NameValueCollection queryParameters = new NameValueCollection();

queryParameters.Add("access_token", "### Chave de Acesso ###");

List items = new List();

foreach (String name in queryParameters)
    items.Add(String.Concat(name, "=", System.Web.HttpUtility.UrlEncode(queryParameters[name])));

string argsString = String.Join("&", items.ToArray());

string postString  = "{";
       postString += "  \"CustomerAddress\": {";
       postString += "      \"customer_id\": \"123\",";
       postString += "      \"recipient\": \"\",";
       postString += "      \"address\": \"Endereço do Cliente\",";
       postString += "      \"number\": \"123\",";
       postString += "      \"complement\": \"Sala 123\",";
       postString += "      \"neighborhood\": \"Bairro do Cliente\",";
       postString += "      \"city\": \"Cidade do Cliente\",";
       postString += "      \"state\": \"SP\",";
       postString += "      \"zip_code\": \"04001001\",";
       postString += "      \"country\": \"BRA\",";
       postString += "      \"type\": \"1\",";
       postString += "      \"active\": \"1\",";
       postString += "      \"description\": \"\",";
       postString += "  }";
       postString += "}";

HttpWebRequest webRequest = WebRequest.Create(URLAuth + "?" + argsString) as HttpWebRequest;
webRequest.Method = "POST";
webRequest.ContentType = "application/json";

StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream());
requestWriter.Write(postString);
requestWriter.Close();

StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());
string responseData = responseReader.ReadToEnd();

responseReader.Close();
webRequest.GetResponse().Close();

String url = "https://{api_address}/customers/addresses/";
StringBuffer response = null ;
try{
    String access_token = "?access_token=### Chave de Acesso ###";
    
    URL obj = new URL(url+access_token);
    HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();

    //add reuqest header
    con.setRequestMethod("POST");
    con.setRequestProperty("User-Agent", USER_AGENT);
    con.setRequestProperty("Content-Type", "application/json");
    con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");

    String postString  = "{";
           postString += "  \"CustomerAddress\": {";
           postString += "      \"customer_id\": \"123\",";
           postString += "      \"recipient\": \"\",";
           postString += "      \"address\": \"Endereço do Cliente\",";
           postString += "      \"number\": \"123\",";
           postString += "      \"complement\": \"Sala 123\",";
           postString += "      \"neighborhood\": \"Bairro do Cliente\",";
           postString += "      \"city\": \"Cidade do Cliente\",";
           postString += "      \"state\": \"SP\",";
           postString += "      \"zip_code\": \"04001001\",";
           postString += "      \"country\": \"BRA\",";
           postString += "      \"type\": \"1\",";
           postString += "      \"active\": \"1\",";
           postString += "      \"description\": \"\",";
           postString += "  }";
           postString += "}";
           
    // Send post request
    con.setDoOutput(true);
    DataOutputStream wr = new DataOutputStream(con.getOutputStream());
    wr.writeBytes(postString);
    wr.flush();
    wr.close();

    int responseCode = con.getResponseCode();

    BufferedReader in ;
    if (responseCode >= 200 && responseCode < 300){
        in = new BufferedReader(
            new InputStreamReader(con.getInputStream()));
    }else{
        in = new BufferedReader(
            new InputStreamReader(con.getErrorStream()));
    }
    
    String inputLine;
    response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
    }
    in.close();

} catch (Exception ex){
    // Tratamento da Exception
}
String resposta = response.toString();

Parameter

Field Type Description
access_token String

Chave de acesso

CustomerAddress JSON

Endereços do cliente

  customer_id Number

Código do cliente

  recipient String

Nome do cliente

  address String

Logradouro

  number Number

Número do endereço

  complement String

Complemento

  neighborhood String

Bairro

  city String

Cidade

  state String

Sigla do estado

  zip_code String

CEP

  country String

País

  type Number

Tipo de endereço (Veja Tabela D)

  active Number

Endereço ativo (Veja Tabela E)

  description String

Descrição do Endereço


    POST /customers/addresses/?access_token=abc96fb7b1defd2496b9a9d81071fa12319b12306465e057d0ebca9bd9ab19
		
		
    
    {	
	"CustomerAddress":{
		"customer_id":"123",
		"recipient":"",
		"address":"Endereço do Cliente",
		"number":"123",
		"complement":"Sala 123",
		"neighborhood":"Bairro do Cliente",
		"city":"Cidade do Cliente",
		"state":"SP",
		"zip_code":"04001-001",
		"country":"BRA",
		"type":"1",
		"active":"0",
		"description":""
	}
}
    
    

Success 200

Field Type Description
message String

Mensagem de retorno

id Number

Código do do endereço do cliente

code Number

Código do retorno (201)

HTTP/1.1201 OK
{"message":"Created","id":"123","code":201}

Excluir Endereço

Requisição para excluir um endereço do cliente.

 Método DELETE

https://{api_address}/customers/addresses/:id

Código de Exemplo


 

<?php
   $params["access_token"] = "### Chave de Acesso ###";

    $url = "https://{api_address}/customers/addresses/123?".http_build_query($params);

    ob_start();

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Content-Length: ' . strlen(json_encode($data)))
    );
    curl_exec($ch);

    // JSON de retorno  
    $resposta = json_decode(ob_get_contents());
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    ob_end_clean();
    curl_close($ch);

    if($code == "200"){
        //Tratamento dos dados de resposta da consulta.
    }else{
        //Tratamento das mensagens de erro
    }
?>

string URLAuth = "https://{api_address}/customers/addresses/123";

NameValueCollection queryParameters = new NameValueCollection();

queryParameters.Add("access_token", "### Chave de Acesso ###");

List items = new List();

foreach (String name in queryParameters)
    items.Add(String.Concat(name, "=", System.Web.HttpUtility.UrlEncode(queryParameters[name])));

string argsString = String.Join("&", items.ToArray());

HttpWebRequest webRequest = WebRequest.Create(URLAuth + "?" + argsString) as HttpWebRequest;
webRequest.Method = "DELETE";
webRequest.ContentType = "application/json";

StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());
string responseData = responseReader.ReadToEnd();

responseReader.Close();
webRequest.GetResponse().Close();

String url = "https://{api_address}/customers/addresses/123";
StringBuffer response = null ;
try{
    String access_token = "?access_token=### Chave de Acesso ###";
    
    URL obj = new URL(url+access_token);
    HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();

    //add reuqest header
    con.setRequestMethod("DELETE");
    con.setRequestProperty("User-Agent", USER_AGENT);
    con.setRequestProperty("Content-Type", "application/json");
    con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");

    int responseCode = con.getResponseCode();

    BufferedReader in ;
    if (responseCode == 200){
        in = new BufferedReader(
            new InputStreamReader(con.getInputStream()));
    }else{
        in = new BufferedReader(
            new InputStreamReader(con.getErrorStream()));
    }
    
    String inputLine;
    response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
    }
    in.close();

} catch (Exception ex){
    // Tratamento da Exception
}
String resposta = response.toString();

Parâmetros enviados

Field Type Description
access_token String

Chave de acesso

:id Number

Código do endereço do cliente

Retorno em caso de sucesso (status code 200 ou 201)

 
Field Type Description
message String

Mensagem de retorno

id Number

Código do endereço do cliente

code Number

Código do retorno (200)

Json de Retorno

HTTP/1.1 200 OK
{
    "message": "Deleted",
    "id": "123",
    "code": 200
}

Tabelas Auxiliares

Tabelas Auxiliares de Produtos

Tabela A - Sexo do cliente (campo gender)

Valor Descrição
1 Masculino
2 Feminino

Tabela B - Tipo do cliente (campo type)

Valor Descrição
0 Pessoa física
1 Pessoa jurídica

Tabela C - Bloqueio do cliente (campo blocked)

Valor Descrição
0 Cliente desbloqueada
1 Cliente bloqueada

Tabela D - Tipo de endereço do cliente (campo CustomerAddress.type)

Valor Descrição
0 Endereço de cobrança
1 Endereço de entrega

Tabela E - Disponibilidade do endereço do cliente (campo CustomerAddress.active)

Valor Descrição
0 Endereço indisponível
1 Endereço disponível
Taynara Sene 
Tem mais dúvidas? Envie uma solicitação

Comentários

    Artigos nessa seção

    Powered by Zendesk