APIs de Características
Requisição para consultar os dados das características dos produtos.
Método GET
https://{api_address}/products/properties
Código de Exemplo
<?php
$params["access_token"] = "### Chave de Acesso ###";
$url = "https://{api_address}/products/properties/?".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/properties/";
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/properties/";
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 | String |
Código da característica |
name | String |
Nome da característica |
position | String |
Posição da característica |
display | String |
Visível na loja virtual |
active_display | String |
Ativo na loja virtual |
Success 200
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 |
Properties | Object[] |
Dados das características |
Property | Object |
Dados da característica |
id | Number |
Código da característica |
active_display | Number |
Característica ativa na loja virtual |
name | String |
Nome da característica |
position | Number |
Posição da característica |
display | Number |
Característica visível na loja virtual |
has_product | Number |
Característica com produtos |
PropertyValues | Object[] |
Valores da característica |
id | Number |
Código do valor da característica |
name | String |
Nome do valor da característica |
property_id | Number |
Código da característica |
image | Object |
Código da característica |
http | Object |
Imagem da característica |
https | Object |
Imagem da característica em ambiente seguro |
{
"paging": {
"total": 24,
"page": 1,
"offset": 0,
"limit": 30,
"maxLimit": 50
},
"sort": [
{
"id": "asc"
}
],
"availableFilters": [
"id",
"name",
"position",
"display",
"active_display"
],
"appliedFilters": {
"Property.active_display": "1"
},
"Properties": [
{
"Property": {
"id": "2",
"active_display": "1",
"name": "Cor",
"position": "1",
"display": "1",
"has_product": "1",
"PropertyValues": [
{
"id": "72",
"name": "Preto",
"property_id": "2",
"image": {
"http": "http://urldaimagem/img/img_prod/123/cor_4.png?123",
"https": "https://urldaimagem/img/img_prod/123/cor_4.png?123"
}
},
{
"id": "74",
"name": "Vermelho",
"property_id": "2",
"image": {
"http": "http://urldaimagem/img/img_prod/123/cor_12.png?123",
"https": "https://urldaimagem/img/img_prod/123/cor_12.png?123"
}
}
]
}
}
]
}
Cadastrar Características de Produtos
Requisição para cadastro das características dos produtos.
Método POST
https://{api_address}/products/:id/properties
Código de Exemplo
<?php
$params["access_token"] = "### Chave de Acesso ###";
$data[] = ["property_id" => "1", "value" => "Branco"];
$data[] = ["property_id" => "2", "value" => "220v"];
$data[] = ["property_id" => "3", "value" => "Teste"];
$url = "https://{api_address}/products/123/properties/?".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/123/properties/";
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 += " {";
postString += " \"property_id\": \"1\",";
postString += " \"value\": \"Branco\",";
postString += " \"index\": \"0\"";
postString += " },";
postString += " {";
postString += " \"property_id\": \"2\",";
postString += " \"value\": \"220v\",";
postString += " \"index\": \"0\"";
postString += " },";
postString += " {";
postString += " \"property_id\": \"3\",";
postString += " \"value\": \"Teste\"";
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/123/properties/";
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 += " {";
postString += " \"property_id\": \"1\",";
postString += " \"value\": \"Branco\",";
postString += " \"index\": \"0\"";
postString += " },";
postString += " {";
postString += " \"property_id\": \"2\",";
postString += " \"value\": \"220v\",";
postString += " \"index\": \"0\"";
postString += " },";
postString += " {";
postString += " \"property_id\": \"3\",";
postString += " \"value\": \"Teste\"";
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âmetros enviados
Campo | Tipo (Tamanho) | Descrição |
---|---|---|
access_token | String |
Chave de acesso |
property_id | String |
Código da característica do produto |
value | String (100) |
característica do produto |
POST /products/123/properties?access_token=abc96fb7b1defd2496b9a9d81071fa12319b12306465e057d0ebca9bd9ab19
[
{
"property_id": "1",
"value": "Branco"
},
{
"property_id": "2",
"value": "220v"
},
{
"property_id": "3",
"value": "Teste"
}
]
Retorno em caso de sucesso
Campo | Tipo | Descrição |
---|---|---|
message | String |
Mensagem de retorno |
code | Number |
Código do retorno (201) |
{
"message": "Created",
"code": 201
}
Comentários