Envio de mensagens (MT)
Last updated
Last updated
POST https://api-messaging.wavy.global/v1/send-sms - Content-Type: application/json
* Campo obrigatório
Campo | Detalhes | Tipo |
---|---|---|
curl -X POST \
https://api-messaging.wavy.global/v1/send-sms \
-H 'authenticationtoken: <authenticationtoken>' \
-H 'username: <username>' \
-H 'content-type: application/json' \
-d '{"destination": "5511900000000" , "messageText": "linha\nquebrada"}'
require 'uri'
require 'net/http'
url = URI("https://api-messaging.wavy.global/v1/send-sms")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["username"] = '<username>'
request["authenticationtoken"] = '<authenticationtoken>'
request["content-type"] = 'application/json'
request.body = "{\"destination\": \"5511900000000\" , \"messageText\": \"linha\\nquebrada\"}"
response = http.request(request)
puts response.read_body
import requests
url = "https://api-messaging.wavy.global/v1/send-sms"
payload = "{\"destination\": \"5511900000000\" , \"messageText\": \"linha\\nquebrada\"}"
headers = {
'username': "<username>",
'authenticationtoken': "<authenticationtoken>",
'content-type': "application/json"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
> sudo apt-get/yum install php5-curl
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api-messaging.wavy.global/v1/send-sms",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\"destination\": \"5511900000000\" , \"messageText\": \"linha\\nquebrada\"}",
CURLOPT_HTTPHEADER => array(
"authenticationtoken: <authenticationtoken>",
"username: <username>",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
public class SendSms {
public static void main(String[] args) {
String url = "https://api-messaging.wavy.global/v1/send-sms";
String userName = "<username>";
String authenticationToken = "<authenticationtoken>";
String body = "{\"destination\": \"5511900000000\" , \"messageText\": \"linha\\nquebrada\"}";
String response = doPost(url, body, userName, authenticationToken);
System.out.println(response);
}
public static String doPost(String strUrl, String request, String userName, String authenticationToken) {
HttpURLConnection conn = null;
OutputStreamWriter wr = null;
BufferedReader br = null;
try {
URL url = new URL(strUrl);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setInstanceFollowRedirects(true);
conn.setConnectTimeout(30000);
conn.setReadTimeout(30000);
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("UserName", userName);
conn.setRequestProperty("AuthenticationToken", authenticationToken);
// write the request
wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(request);
wr.close();
// read the response
br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder resp = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
resp.append(line).append("\n");
}
return resp.toString();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (wr != null) {
wr.close();
}
if (br != null) {
br.close();
}
if (conn != null) {
conn.disconnect();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
}
Ao fazer o envio, você receberá um JSON informando o id que foi gerado para esta mensagem (Response ou Resposta síncrona da Wavy):
[
{
"id":"9cb87d36-79af-11e5-89f3-1b0591cdf807",
"correlationId":"myId"
}
]
[
{
"id":"9cb87d36-79af-11e5-89f3-1b0591cdf807",
"correlationId":"myId"
}
]
[
{
"id":"9cb87d36-79af-11e5-89f3-1b0591cdf807",
"correlationId":"myId"
}
]
[
{
"id":"9cb87d36-79af-11e5-89f3-1b0591cdf807",
"correlationId":"myId"
}
]
[
{
"id":"9cb87d36-79af-11e5-89f3-1b0591cdf807",
"correlationId":"myId"
}
]
Via método GET, é possivel realizar o envio de uma mensagem passando todos os parâmetros como query string.
GET https://api-messaging.wavy.global/v1/send-sms?destination=..
Via método POST, é possivel realizar o envio de uma mensagem passando todos os parâmetros no body.
POST https://api-messaging.wavy.global/v1/send-sms - Content-Type: application/json
* Campo obrigatório
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
public class SendSms {
public static void main(String[] args) {
String url = "https://api-messaging.wavy.global/v1/send-bulk-sms";
String userName = "<username>";
String authenticationToken = "<authenticationtoken>";
String body = "{ \"messages\":[{ \"destination\":\"5519999999999\", \"messageText\":\"First message\" }," +
" { \"destination\":\"5519999999999\" }, { \"destination\":\"5519999999999\" }]," +
" \"defaultValues\":{\"messageText\":\"Default message\" }}";
String response = doPost(url, body, userName, authenticationToken);
System.out.println(response);
}
public static String doPost(String strUrl, String request, String userName, String authenticationToken) {
HttpURLConnection conn = null;
OutputStreamWriter wr = null;
BufferedReader br = null;
try {
URL url = new URL(strUrl);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setInstanceFollowRedirects(true);
conn.setConnectTimeout(30000);
conn.setReadTimeout(30000);
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("UserName", userName);
conn.setRequestProperty("AuthenticationToken", authenticationToken);
// write the request
wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(request);
wr.close();
// read the response
br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder resp = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
resp.append(line).append("\n");
}
return resp.toString();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (wr != null) {
wr.close();
}
if (br != null) {
br.close();
}
if (conn != null) {
conn.disconnect();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
}
Permite o envio de mensagens em lote ou individuais passando os parametros em um objeto JSON
Existe um limite de 1000 mensagens por requisição
POST https://api-messaging.wavy.global/v1/send-bulk-sms Content-Type: application/json
O corpo da requisição precisa conter o objeto JSON com as informações conforme campos abaixo:
* Campo obrigatório
IMPORTANTE! Para cada subconta existe um usuário de sistema único.
curl --request POST \
--url https://api-messaging.wavy.global/v1/send-bulk-sms \
--header 'authenticationtoken: <Token de autenticação>' \
--header 'username:<Usuário Wavy Messaging>' \
--header 'content-type: application/json' \
--data "{ "messages":[{ "destination":"5519999999999", "messageText":"First message" }, { "destination":"5519999999999" }, { "destination":"5519999999999" }], "defaultValues":{"messageText":"Default message" }}"
require 'uri'
require 'net/http'
url = URI("https://api-messaging.wavy.global/v1/send-bulk-sms")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["username"] = '<username>'
request["authenticationtoken"] = '<authenticationtoken>'
request["content-type"] = 'application/json'
request.body = '{ "messages":[{ "destination":"5519999999999", "messageText":"First message" }, { "destination":"5519999999999" }, { "destination":"5519999999999" }], "defaultValues":{"messageText":"Default message" }}'
response = http.request(request)
puts response.read_body
import requests
url = "https://api-messaging.wavy.global/v1/send-bulk-sms"
payload = '{ "messages":[{ "destination":"5519999999999", "messageText":"First message" }, { "destination":"5519999999999" }, { "destination":"5519999999999" }], "defaultValues":{"messageText":"Default message" }}'
headers = {
'username': "<username>",
'authenticationtoken': "<authenticationtoken>",
'content-type': "application/json"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
Mod: curl
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api-messaging.wavy.global/v1/send-bulk-sms",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{ \"messages\":[{ \"destination\":\"5519999999999\", \"messageText\":\"First message\" }, { \"destination\":\"5519999999999\" }, { \"destination\":\"5519999999999\" }], \"defaultValues\":{\"messageText\":\"Default message\" }}",
CURLOPT_HTTPHEADER => array(
"authenticationtoken: <authenticationtoken>",
"content-type: application/json",
"username: <username>"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
public class SendSms {
public static void main(String[] args) {
String url = "https://api-messaging.wavy.global/v1/send-bulk-sms";
String userName = "<username>";
String authenticationToken = "<authenticationtoken>";
String body = "{ \"messages\":[{ \"destination\":\"5519999999999\", \"messageText\":\"First message\" }," +
" { \"destination\":\"5519999999999\" }, { \"destination\":\"5519999999999\" }]," +
" \"defaultValues\":{\"messageText\":\"Default message\" }}";
String response = doPost(url, body, userName, authenticationToken);
System.out.println(response);
}
public static String doPost(String strUrl, String request, String userName, String authenticationToken) {
HttpURLConnection conn = null;
OutputStreamWriter wr = null;
BufferedReader br = null;
try {
URL url = new URL(strUrl);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setInstanceFollowRedirects(true);
conn.setConnectTimeout(30000);
conn.setReadTimeout(30000);
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("UserName", userName);
conn.setRequestProperty("AuthenticationToken", authenticationToken);
// write the request
wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(request);
wr.close();
// read the response
br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder resp = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
resp.append(line).append("\n");
}
return resp.toString();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (wr != null) {
wr.close();
}
if (br != null) {
br.close();
}
if (conn != null) {
conn.disconnect();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
}
Ao fazer o envio, será retornado um objeto JSON com o UUID do lote e das mensagens individuais :
{
"id": "ce528d70-013b-11e7-98f2-e27c463c8809",
"messages": [
{
"id": "ce528d71-013b-11e7-98f2-e27c463c8809"
},
{
"id": "ce528d72-013b-11e7-98f2-e27c463c8809"
}
]
}
Permite o envio de mensagens em lote ou individuais passando os parametros em um objeto JSON
Existe um limite de 1000 mensagens por requisição
Exemplo de JSON para envio em Lote:
Exemplo 1:
{
"messages":[
{
"destination":"5519900001111",
"messageText":"First message"
},
{
"destination":"5519900002222"
},
{
"destination":"5519900003333"
}
],
"defaultValues":{
"messageText":"Default message"
}
}
Exemplo 2:
{
"messages":[
{
"destination":"5519900001111",
"messageText":"First message"
},
{
"destination":"5519900002222"
}
],
"timeZone":"America/Sao_Paulo",
"scheduledDate": "2017-01-28T02:30:43",
"timeWindow": [12, 15, 20],
"defaultValues":{
"messageText":"Default message"
}
}
Exemplo 3:
{
"messages":[
{
"destination":"5519900001111"
},
{
"destination":"5519900002222"
}
],
"defaultValues":{
"messageText":"Default message",
"flashSMS":"true"
}
}
Exemplo 4, com flowId e params:
{
"messages":[
{
"destination":"5519900001111",
"params": {
"param1": "other_value1",
"param2": "other_value2"
}
},
{
"destination":"5519900002222"
}
],
"defaultValues":{
"params": {
"param1": "value1",
"param2": "value2"
}
},
"flowId": "14f8142d-e731-4971-8220-5a76a12c413f"
}
{
"id": "ce528d70-013b-11e7-98f2-e27c463c8809",
"messages": [
{
"id": "ce528d71-013b-11e7-98f2-e27c463c8809"
},
{
"id": "ce528d72-013b-11e7-98f2-e27c463c8809"
}
]
}
Permite o envio de mensagens em lote ou individuais passando os parametros em um objeto JSON
Existe um limite de 1000 mensagens por requisição
Exemplo de JSON para envio em Lote:
Exemplo 1:
{
"messages":[
{
"destination":"5519900001111",
"messageText":"First message"
},
{
"destination":"5519900002222"
},
{
"destination":"5519900003333"
}
],
"defaultValues":{
"messageText":"Default message"
}
}
Exemplo 2:
{
"messages":[
{
"destination":"5519900001111",
"messageText":"First message"
},
{
"destination":"5519900002222"
}
],
"timeZone":"America/Sao_Paulo",
"scheduledDate": "2017-01-28T02:30:43",
"timeWindow": [12, 15, 20],
"defaultValues":{
"messageText":"Default message"
}
}
Exemplo 3:
{
"messages":[
{
"destination":"5519900001111"
},
{
"destination":"5519900002222"
}
],
"defaultValues":{
"messageText":"Default message",
"flashSMS":"true"
}
}
Exemplo 4, com flowId e params:
{
"messages":[
{
"destination":"5519900001111",
"params": {
"param1": "other_value1",
"param2": "other_value2"
}
},
{
"destination":"5519900002222"
}
],
"defaultValues":{
"params": {
"param1": "value1",
"param2": "value2"
}
},
"flowId": "14f8142d-e731-4971-8220-5a76a12c413f"
}
{
"id": "ce528d70-013b-11e7-98f2-e27c463c8809",
"messages": [
{
"id": "ce528d71-013b-11e7-98f2-e27c463c8809"
},
{
"id": "ce528d72-013b-11e7-98f2-e27c463c8809"
}
]
}
Permite o envio de mensagens em lote ou individuais passando os parametros em um objeto JSON
Existe um limite de 1000 mensagens por requisição
Exemplo de JSON para envio em Lote:
Exemplo 1:
{
"messages":[
{
"destination":"5519900001111",
"messageText":"First message"
},
{
"destination":"5519900002222"
},
{
"destination":"5519900003333"
}
],
"defaultValues":{
"messageText":"Default message"
}
}
Exemplo 2:
{
"messages":[
{
"destination":"5519900001111",
"messageText":"First message"
},
{
"destination":"5519900002222"
}
],
"timeZone":"America/Sao_Paulo",
"scheduledDate": "2017-01-28T02:30:43",
"timeWindow": [12, 15, 20],
"defaultValues":{
"messageText":"Default message"
}
}
Exemplo 3:
{
"messages":[
{
"destination":"5519900001111"
},
{
"destination":"5519900002222"
}
],
"defaultValues":{
"messageText":"Default message",
"flashSMS":"true"
}
}
Exemplo 4, com flowId e params:
{
"messages":[
{
"destination":"5519900001111",
"params": {
"param1": "other_value1",
"param2": "other_value2"
}
},
{
"destination":"5519900002222"
}
],
"defaultValues":{
"params": {
"param1": "value1",
"param2": "value2"
}
},
"flowId": "14f8142d-e731-4971-8220-5a76a12c413f"
}
{
"id": "ce528d70-013b-11e7-98f2-e27c463c8809",
"messages": [
{
"id": "ce528d71-013b-11e7-98f2-e27c463c8809"
},
{
"id": "ce528d72-013b-11e7-98f2-e27c463c8809"
}
]
}
Permite o envio de mensagens em lote ou individuais passando os parametros em um objeto JSON
Existe um limite de 1000 mensagens por requisição
Exemplo de JSON para envio em Lote:
Exemplo 1:
{
"messages":[
{
"destination":"5519900001111",
"messageText":"First message"
},
{
"destination":"5519900002222"
},
{
"destination":"5519900003333"
}
],
"defaultValues":{
"messageText":"Default message"
}
}
Exemplo 2:
{
"messages":[
{
"destination":"5519900001111",
"messageText":"First message"
},
{
"destination":"5519900002222"
}
],
"timeZone":"America/Sao_Paulo",
"scheduledDate": "2017-01-28T02:30:43",
"timeWindow": [12, 15, 20],
"defaultValues":{
"messageText":"Default message"
}
}
Exemplo 3:
{
"messages":[
{
"destination":"5519900001111"
},
{
"destination":"5519900002222"
}
],
"defaultValues":{
"messageText":"Default message",
"flashSMS":"true"
}
}
Exemplo 4, com flowId e params:
{
"messages":[
{
"destination":"5519900001111",
"params": {
"param1": "other_value1",
"param2": "other_value2"
}
},
{
"destination":"5519900002222"
}
],
"defaultValues":{
"params": {
"param1": "value1",
"param2": "value2"
}
},
"flowId": "14f8142d-e731-4971-8220-5a76a12c413f"
}
{
"id": "ce528d70-013b-11e7-98f2-e27c463c8809",
"messages": [
{
"id": "ce528d71-013b-11e7-98f2-e27c463c8809"
},
{
"id": "ce528d72-013b-11e7-98f2-e27c463c8809"
}
]
}
Permite o envio de mensagens em lote ou individuais passando os parametros em um objeto JSON
Existe um limite de 1000 mensagens por requisição
Exemplo de JSON para envio em Lote:
Exemplo 1:
{
"messages":[
{
"destination":"5519900001111",
"messageText":"First message"
},
{
"destination":"5519900002222"
},
{
"destination":"5519900003333"
}
],
"defaultValues":{
"messageText":"Default message"
}
}
Exemplo 2:
{
"messages":[
{
"destination":"5519900001111",
"messageText":"First message"
},
{
"destination":"5519900002222"
}
],
"timeZone":"America/Sao_Paulo",
"scheduledDate": "2017-01-28T02:30:43",
"timeWindow": [12, 15, 20],
"defaultValues":{
"messageText":"Default message"
}
}
Exemplo 3:
{
"messages":[
{
"destination":"5519900001111"
},
{
"destination":"5519900002222"
}
],
"defaultValues":{
"messageText":"Default message",
"flashSMS":"true"
}
}
Exemplo 4, com flowId e params:
{
"messages":[
{
"destination":"5519900001111",
"params": {
"param1": "other_value1",
"param2": "other_value2"
}
},
{
"destination":"5519900002222"
}
],
"defaultValues":{
"params": {
"param1": "value1",
"param2": "value2"
}
},
"flowId": "14f8142d-e731-4971-8220-5a76a12c413f"
}
Observe que nos exemplos acima, alguns campos “destination” não possuem um “messageText” atribuido direto a eles, nestes casos, o texto da mensagem será o “messageText” dentro de “defaultValues”. Essa função é útil quando é necessário o envio da mesma mensagem para vários números diferentes
A resposta do envio em lote conterá um arquivo JSON com as informações necessárias para rastreio, será gerado um id para o lote todo e um id e correlationId individual para cada mensagem:
Campo | Detalhes | Tipo |
---|---|---|
Campo | Detalhes | Tipo |
---|---|---|
Campo | Detalhes | Tipo |
---|---|---|