Playing variables to be parameters in the API

0

I have a website and to enter it needs to log in, and the data is: cpf and email. And I have an API that I need to play the cpf and email variables to be parameters in the api, but I do not have much knowledge in api and also just have the link to it.

I need to play this data because each user will have different data, and api will need this data in the parameter to make a select and search the data of the person registered with cpf and email.

eg link

Consuming API:

 function load(){

  var xhr = new XMLHttpRequest();
  xhr.open("GET", "http://api/api/TRCKCLICODCPF=12345678901&EMAIL=fulano%40email.com");



  xhr.addEventListener("load", function() {
      var resposta = xhr.responseText;
      // console.log("ola1");
      var clientes = JSON.parse(resposta);
      // console.log("ola2");
      // console.log(clientes);

      for (var i =0; i < 1; i++){
          // console.log("ola3");
         var clientes_1 = clientes.TRACKER[i];
         AdicionaNome(clientes_1);
         AdicionaCPF(clientes_1);
         AdicionaProduto(clientes_1);
         AdicionaCidade(clientes_1);
         AdicionaCodigoProduto(clientes_1);
         AdicionaCodigoCliente(clientes_1);
         AdicionaStatus(clientes_1);
         ActiveStatusImage(clientes_1);
         ActiveOnlyPostagem(clientes_1);
         adicionaClienteNaTabelaViagem(clientes_1);
         ActiveQtdViagem(clientes_1);


     }

  });

  xhr.send();
      }
      window.onload = load;

I've changed the api link, just an example

    
asked by anonymous 15.12.2017 / 12:52

1 answer

0

An interesting method is to access via Curl , it is similar to an ajax request, but with PHP , also check if the API has some comprehensive documentation ...

Generally for authentication the method is GET, so it would look something like this ...

PHP

$url="http://api/api/TRCKCLICODCPF=12345678901&EMAIL=fulano%40email.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);    // get the url contents

$data = curl_exec($ch); // execute curl request
curl_close($ch);

$xml = simplexml_load_string($data);
print_r($xml)

So your API will not be visible to any user if it is accessed on the client ...

    
15.12.2017 / 13:15