Listagem de Scripts Externos

Requisição para a listagem dos scripts externos cadastrados.

Método GET

https://{api_address}/external_scripts

Código de Exemplo

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

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

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

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

source String

URL do script externo

created String

Data de criação

modified Number

Data de modificação

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

ExternalScripts Object[]

Lista de scripts externos

  ExternalScript Object

Dados do script externo

    id Number

Código do script externo

    source String

URL do scripts externo

HTTP/1.1 200 OK
{
    "paging": {
        "total": 2,
        "page": 1,
        "offset": 0,
        "limit": 2,
        "maxLimit": 50
    },
    "sort": [],
    "availableFilters": [
        "id",
    ],
    "appliedFilters": [
        "application_id": 1
    ],
    "ExternalScripts": [
        {
            "ExternalScript": {
                "id": "1",
                "source": "http://localhost/assets/store/js/dist/script.js?12345678941c144778663a20caa7dfc4"
            }
        },
        {
            "ExternalScript": {
                "id": "2",
                "source": "http://localhost/assets/store/css/script.css?12345678941c144778663a20caa7dfc4"
            }
        }
    ]
}

Cadastrar Script Externo

Requisição para cadastrar scripts externos. Deverá enviar o JSON com os dados do scritp externo para a criação.

Método POST

https://{api_address}/external_scripts/

Código de Exemplo

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

    $data["ExternalScript"]["source"] = "http://localhost/assets/store/css/script.css";

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

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 += "  \"ExternalScript\": {";
       postString += "      \"source\": \"http://localhost/assets/store/css/script.css\"";
       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}/external_scripts/";
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 += "    \"ExternalScript\": {";
           postString += "        \"source\": \"http://localhost/assets/store/css/script.css\"";
           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

ExternalScript JSON

Dados do script externo

  source String

URL do script externo

POST /external_scripts/?access_token=abc96fb7b1defd2496b9a9d81071fa12319b12306465e057d0ebca9bd9ab19
{
    "ExternalScript":{
        "source":"http://localhost/assets/store/css/script.css"
    }
}

Success 200

Campo Tipo Descrição
message String

Mensagem de retorno

id Number

Código do script externo

code Number

Código do retorno (201)

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

Atualizar Dados Script Externo

Requisição para atualizar os dados de scripts externos. Deverá enviar o JSON com os dados do scritp externo para a criação.

Método PUT

https://{api_address}/external_scripts/:id

Código de Exemplo

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

    $data["ExternalScript"]["source"] = "http://localhost/assets/store/css/script.css";

    $url = "https://{api_address}/external_scripts/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 == "201"){
        //Tratamento dos dados de resposta da consulta.
    }else{
        //Tratamento das mensagens de erro
    }
?>
string URLAuth = "https://{api_address}/external_scripts/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 += "  \"ExternalScript\": {";
       postString += "      \"source\": \"http://localhost/assets/store/css/script.css\"";
       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(postString);
requestWriter.Close();

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

responseReader.Close();
webRequest.GetResponse().Close();
String url = "https://{api_address}/external_scripts/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 += "    \"ExternalScript\": {";
           postString += "        \"source\": \"http://localhost/assets/store/css/script.css\"";
           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

:id Number

Código do script externo

ExternalScript JSON

Dados do script externo

  source String

URL do script externo

PUT /external_scripts/123?access_token=abc96fb7b1defd2496b9a9d81071fa12319b12306465e057d0ebca9bd9ab19
{
    "ExternalScript":{
        "source":"http://localhost/assets/store/css/script.css"
    }
}

Success 200

Campo Tipo Descrição
message String

Mensagem de retorno

id Number

Código do script externo

code Number

Código do retorno (201)

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

Excluir Script Externo

Requisição para excluir um script externo

Método DELETE

https://{api_address}/external_scripts/:id

Código de Exemplo

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

    $url = "https://{api_address}/external_scripts/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}/external_scripts/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}/external_scripts/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 script externo

Success 200

Campo Tipo Descrição
message String

Mensagem de retorno

id Number

Código do script externo

code Number

Código do retorno (201)

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

    Desenvolvido por Zendesk