PDA

View Full Version : integração via API



Francimilson
21-Mar-2024, 01:04 PM
Boa tarde a todos

Estou precisando fazer uma integração via API como nunca fiz esse procedimento não tive muito sucesso.
Criei o arquivo JSON mas como precisa usar comando POST para comunicar com a API não sei como fazer isso em VDF se alguém compartilhar como eu poderia fazer isso passando um exemplo ficarei muito grato.
segue abaixo um exemplo em HTML usando a API em questão.
Queria fazer o mesmo em VDF


<button onclick="enviarSMS()">Enviar SMS</button>

<script>
functionenviarSMS() {
varxhr = newXMLHttpRequest();
varurl = 'https://gateway.apibrasil.io/api/v2/sms/send';
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('DeviceToken', 'e7f80f6c-ef28-4a15-a4cb');
xhr.setRequestHeader('Authorization', 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciJ9');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
console.log(xhr.responseText);
}
};
vardata = JSON.stringify({
"number":"5599991530101",
"message":"Teste de Mensagem SMS via API"
});
xhr.send(data);
}
</script>

Samuel Pizarro
21-Mar-2024, 03:05 PM
colega..

edite seu post, e mascare os tokens de acesso.. pra sua segurança

Francimilson
21-Mar-2024, 03:32 PM
colega..

edite seu post, e mascare os tokens de acesso.. pra sua segurança


Olá Samuel

os Tokens são fictícios

Samuel Pizarro
21-Mar-2024, 09:42 PM
Ah joia!

bom respondendo sua pergunta, nao inteiramente.
Vc precisa usar a classe chttptransfer

no. Help tem alguns exemplos. Eu nao tenho nada aqui pra compartilhar contigo

Mike Peat
22-Mar-2024, 02:47 AM
Hi

You might try my cHttpTransferREST class from here on GitHub (https://github.com/DataFlexCode/MSGraphAPI/blob/main/AppSrc/cHttpTransferREST.pkg) (it is part of a bigger project, but don't worry about that - it only relies on standard packages: cHttpTransfer & WinUUID). It - in its MakeJsonCall function - expects a handle to a JSON object to use as the body of an http POST (it handles any verb, but you want POST, I think) and will return a handle to a JSON object as the response, if there is any (or zero if there isn't, which can correctly happen). You are responsible for dealing with (i.e. destroying) that object if one is returned. If it returns an error (-1: C_httpNoJson) then you can find out what went wrong from its piError and psError properties.

Mike

AGMTECNOLOGIA
1-Apr-2024, 02:30 PM
ola. boa tarde. eu tenho porem em windows "desktop" se tiver interesse,