Listagem de Marcas

Requisição para consultar os dados de diversas marcas.

Método GET

https://{api_address}/products/brands/

Código de Exemplo

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

    $url = "https://{api_address}/products/brands/?".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}/products/brands/";

NameValueCollection queryParameters = new NameValueCollection();

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

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}/products/brands/";

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

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âmetro

Campo Tipo Descrição
access_token String

Chave de acesso

attrs String

Filtro de campos disponíveis na listagem

sort String

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

limit Number

Quantidade de registros (max. 50)

page Number

Número da página da consulta

Retorno em caso de sucesso

Campo Tipo Descrição
paging Object

Dados de paginação

  total Number

Total de registros

  page Number

Páginas 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

Brands Object[]

Dados da marcas dos produtos

  Brand Object

Dados da marca

    id Number

Código da marca

    brand String

Nome da marca

    slug String

Final da URL da marca

HTTP/1.1 200 OK
{
    "paging": {
        "total": 1,
        "page": 1,
        "offset": 0,
        "limit": 1,
        "maxLimit": 50
    },
    "sort": [
        {
            "id": "asc"
        }
    ],
    "availableFilters": [
        "id",
        "brand"
    ],
    "appliedFilters": [ ],
    "Brands": [
        {
          "Brand": {
            "id": "1",
            "slug": "marca-teste",
            "brand": "Marca Teste"
          }
        }
    ]
}

Consultar Dados da Marca

Requisição para consultar os dados de uma marca do produto.

Método GET

https://{api_address}/products/brands/:id

Código de Exemplo

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

    $url = "https://{api_address}/products/brands/1?".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}/products/brands/1";

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}/products/brands/1";

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âmetro

Campo Tipo Descrição
access_token String

Chave de acesso

:id Number

Código da marca do produto

Retorno em caso de sucesso

Campo Tipo Descrição
Brand Object

Dados da marca

  id Number

Código da marca

  slug String

Final da URL da marca

  brand String

Nome da marca

HTTP/1.1 200 OK
{
    "Brand": {
        "id": "9",
        "slug": "marca-produto",
        "brand": "Marca Produto"
    }
}

Cadastrar Marca

Requisição para inclusão de marca do produto. Deverá enviar o JSON com os dados da marca para a criação.

Método POST

https://{api_address}/products/brands/

Código de Exemplo

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

    $data["Brand"]["slug"] = "new-brand";
    $data["Brand"]["brand"] = "Nova Marca";

    $url = "https://{api_address}/products/brands/?".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}/products/brands/";

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 += "  \"Brand\": {";
       postString += "      \"brand\": \"Nova Marca\",";
       postString += "      \"slug\": \"new-brand\"";
       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}/products/brands/";
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 += "  \"Brand\": {";
           postString += "      \"brand\": \"Nova Marca\",";
           postString += "      \"slug\": \"new-brand\"";
           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
}

Parâmetro

Campo Tipo Descrição
access_token String

Chave de acesso

Brand JSON

Dados da marca

  brand String

Nome da marca

  slug String

Final da URL da marca

{
    "Brand": {
        "slug": "new-brand",
        "brand": "Nova Marca"
    }
}

Retorno em caso de sucesso

Campo Tipo Descrição
message String

Mensagem de retorno

id Number

Código da marca

code Number

Código do retorno (201)

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

Atualizar Dados da Marca

Requisição para alterar os dados da marca. Deverá enviar o JSON com os dados da marca para alteração.

Método PUT

https://{api_address}/products/brands/:id

Código de Exemplo

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

    $data["Brand"]["slug"] = "new-brand";
    $data["Brand"]["brand"] = "Nova Marca";
    
    $url = "https://{api_address}/products/brands/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}/products/brands/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 postString  = "{";
       postString += "  \"Brand\": {";
       postString += "      \"brand\": \"Nova Marca\",";
       postString += "      \"slug\": \"new-brand\"";
       postString += "  }";
       postString += "}";

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}/products/brands/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 postString  = "{";
           postString += "  \"Brand\": {";
           postString += "      \"brand\": \"Nova Marca\",";
           postString += "      \"slug\": \"new-brand\"";
           postString += "  }";
           postString += "}";
           
    // 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
}

Parâmetro

Campo Tipo Descrição
access_token String

Chave de acesso

:id Number

Código da marca

Brand JSON

Dados da marca

  brand String

Nome da marca

  slug String

Final da URL da marca

{
    "Brand": {
        "slug": "new-brand",
        "brand": "Nova Marca"
    }
}

Success 200

Campo Tipo Descrição
message String

Mensagem de retorno

id Number

Código da marca

code Number

Código do retorno (200)

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

Excluir Marca

Requisição para excluir uma marca do produto.

Método DELETE

https://{api_address}/products/brands/:id

Código de Exemplo

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

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

    ob_start();

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
    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}/products/brands/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}/products/brands/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
}

Parâmetro

Campo Tipo Descrição
access_token String

Chave de acesso

:id Number

Código da marca

Success 200

Campo Tipo Descrição
message String

Mensagem de retorno

id Number

Código da marca

code Number

Código do retorno (200)

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

 

Frontend - Agencia 
Tem mais dúvidas? Envie uma solicitação

Comentários

    Artigos nessa seção

    Powered by Zendesk