Requisição para a consulta de diversos newsletter.

Listagem de Newsletter

Método GET

https://{api_address}/newsletter/

Código de Exemplo

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

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

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

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

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

Newsletters Object[]

Lista de newsletters

  Newsletter Object

Dados do newsletter

    id Number

Código do newsletters

    name String

Nome do cliente

    email String

Email do cliente

    status String

Newsletter ativo (Veja Tabela A)

    created String

Data de criação

    modified String

Data de modificação

Json de Retorno

HTTP/1.1 200 OK
{
    "paging": {
        "total": 1,
        "page": 1,
        "offset": 0,
        "limit": 1,
        "maxLimit": 50
    },
    "sort": [
        {
            "id": "asc"
        }
    ],
    "availableFilters": [
        "created",
        "modified"
    ],
    "appliedFilters": [],
    "Newsletters": [
        {
            "Newsletter": {
                "id": "123",
                "name": "Nome do Cliente",
                "email": "emaildo@cliente.com.br",
                "status": "0",
                "created": "2016-08-15 11:39:28",
                "modified": "2016-08-15 11:39:28",
            }
        }
    ]
}
 

Requisição para confirmar a inclusão de um newsletter. Deverá enviar o JSON com o email para a confirmação.

Método POST

https://{api_address}/newsletter/confirmation/

Código de Exemplo

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

    $data["email"] = "emaildo@cliente.com.br";

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

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 += "  \"email\": \"emaildo@cliente.com.br\"";
       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}/newsletter/confirmation/";
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 += "  \"email\": \"emaildo@cliente.com.br\"";
           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

Newsletter JSON

Dados do newsletter

  email String

Email do cliente

Estrutura de Json

POST /newsletter/confirmation/?access_token=abc96fb7b1defd2496b9a9d81071fa12319b12306465e057d0ebca9bd9ab19
{
    "email": "emaildo@cliente.com.br"
}

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

Field Type Description
code Number

Código do retorno (200)

message String

Mensagem de retorno

Json de retorno

HTTP/1.1 200 OK
{
    "code": 200,
    "message": "Email emaildo@cliente.com.br confirmed"
}

Cadastrar Newsletter

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

Método POST

https://{api_address}/newsletter/

Código de Exemplo

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

    $data["Newsletter"]["name"] = "Nome do Cliente";
    $data["Newsletter"]["email"] = "emaildo@cliente.com.br";

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

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 += "  \"Newsletter\": {";
       postString += "      \"name\": \"Nome do Cliente\",";
       postString += "      \"email\": \"emaildo@cliente.com.br\"";
       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}/newsletter/";
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 += "  \"Newsletter\": {";
           postString += "      \"name\": \"Nome do Cliente\",";
           postString += "      \"email\": \"emaildo@cliente.com.br\"";
           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

Newsletter JSON

Dados do newsletter

  name String

Nome do cliente

  email String

Email do cliente

Estrutura de Json

POST /newsletter/?access_token=abc96fb7b1defd2496b9a9d81071fa12319b12306465e057d0ebca9bd9ab19
{
    "Newsletter":{
        "name": "Nome do Cliente",
        "email": "emaildo@cliente.com.br"
    }
}

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

Field Type Description
message String

Mensagem de retorno

id Number

Código do newsletter

code Number

Código do retorno (201)

Json de retorno

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

 

Tabelas Auxiliares

Tabelas Auxiliares de Newsletter

Tabela A - Newsletter ativo (campo status)

Valor Descrição
0 Newsletter inativo
1 Newsletter ativo
Frontend - Agencia 
Tem mais dúvidas? Envie uma solicitação

Comentários

    Artigos nessa seção

    Powered by Zendesk