Listagem de Parceiros

Requisição para a consulta de diversos Parceiros.

Método GET

https://{api_address}/partners

Código de Exemplo

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

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

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

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

Campo Tipo Descrição
access_token String

Chave de acesso

attrs String

Atributos do parceiro

limit Number

Limite de registros

page Number

Página corrente

sort String

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

Success 200

Campo Tipo Descrição
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

Partners Object[]

Lista de parceiros

  Partner Object

Dados do parceiro

    id Number

Código do parceiro

    name String

Nome do parceiro

    site String

Site do parceiro

HTTP/1.1 200 OK
{
    "paging": {
        "total": 1,
        "page": 1,
        "offset": 0,
        "limit": 1,
        "maxLimit": 50
    },
    "sort": [
        {
            "id": "desc"
        }
    ],
    "availableFilters": [
        "id",
        "name"
    ],
    "appliedFilters": [],
    "Partners": [
        {
            "Partner": {
                "id": "123",
                "name": "Nome do Parceiro",
                "site": "http://www.sitedoparceiro.com.br",
            }
        }
    ]
}

Consultar Dados do Parceiro

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

Método GET

https://{api_address}/partners/:id

Código de Exemplo

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

    $url = "https://{api_address}/partners/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}/partners/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}/partners/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âmetro

Campo Tipo Descrição
access_token String

Chave de acesso

:id Number

Código do parceiro

Success 200

Campo Tipo Descrição
Partner Object

Dados do parceiro

  id Number

Código do parceiro

  name String

Nome do parceiro

  site String

Site do parceiro

  commission Decimal

Valor de comissão do parceiro

HTTP/1.1 200 OK

{
    "Partner":{
        "id": "123",
        "name": "Nome do Parceiro",
        "site": "http://www.sitedoparceiro.com.br",
        "commission": "0.20"
    }
}

Cadastrar Parceiro

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

Método POST

https://{api_address}/partners

Código de Exemplo

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

    $data["Partner"]["name"] = "Nome do Parceiro";
    $data["Partner"]["site"] = "http://www.sitedoparceiro.com.br";
    $data["Partner"]["commission"] = "0.20";

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

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 += "  \"Partner\": {";
       postString += "      \"name\": \"Nome do Parceiro\",";
       postString += "      \"site\": \"http://www.sitedoparceiro.com.br\",";
       postString += "      \"commission\": \"00000000000\"";
       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}/partners/";
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 += "  \"Partner\": {";
           postString += "      \"name\": \"Nome do Parceiro\",";
           postString += "      \"site\": \"http://www.sitedoparceiro.com.br\",";
           postString += "      \"commission\": \"00000000000\"";
           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

Partner JSON

Dados do parceiro

  name String

Nome do parceiro

  site String

Site do parceiro

  commission Decimal

Valor de comissão do parceiro

JSON Partner

POST /partners/?access_token=abc96fb7b1defd2496b9a9d81071fa12319b12306465e057d0ebca9bd9ab19
{
    "Partner":{
        "name": "Nome do Parceiro",
        "site": "http://www.sitedoparceiro.com.br",
        "commission": "0.20"
    }
}

Success 200

Campo Tipo Descrição
message String

Mensagem de retorno

id Number

Código do parceiro

code Number

Código do retorno (201)

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

Atualizar Dados do Parceiro

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

Método PUT

https://{api_address}/partners/:id

Código de Exemplo

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

    $data["Partner"]["name"] = "Nome do Parceiro";
    $data["Partner"]["site"] = "http://www.sitedoparceiro.com.br";
    $data["Partner"]["commission"] = "0.20";

    $url = "https://{api_address}/partners/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}/partners/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 += "  \"Partner\": {";
       putString += "      \"name\": \"Nome do Parceiro\",";
       putString += "      \"site\": \"http://www.sitedoparceiro.com.br\",";
       putString += "      \"commission\": \"00000000000\"";
       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}/partners/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 += "  \"Partner\": {";
           putString += "      \"name\": \"Nome do Parceiro\",";
           putString += "      \"site\": \"http://www.sitedoparceiro.com.br\",";
           putString += "      \"commission\": \"00000000000\"";
           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
}

Parâmetro

Campo Tipo Descrição
access_token String

Chave de acesso

:id Number

Código do parceiro

Partner JSON

Dados do parceiro

  name String

Nome do parceiro

  site String

Site do parceiro

  commission Decimal

Valor de comissão do parceiro

JSON Partner

PUT /partners/123?access_token=abc96fb7b1defd2496b9a9d81071fa12319b12306465e057d0ebca9bd9ab19
{
    "Partner":{
        "name": "Nome do Parceiro",
        "site": "http://www.sitedoparceiro.com.br",
        "commission": "0.20"
    }
}

Success 200

Campo Tipo Descrição
message String

Mensagem de retorno

id Number

Código do parceiro

code Number

Código do retorno (200)

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

Excluir Parceiro

Requisição para excluir um parceiro.

Método DELETE

https://{api_address}/partners/:id

Código de Exemplo

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

    $url = "https://{api_address}/partners/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}/partners/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}/partners/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 do parceiro

Success 200

Campo Tipo Descrição
message String

Mensagem de retorno

id Number

Código do parceiro

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