Code Snippet Example
Send and receive messages directly from your web application with the Voice API.
var myHeaders = new Headers();
myHeaders.append("XApiKey", "MY API KEY");
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({
"from": "sender Id",
"body": "My message",
"to": "country code + phone number"
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://ypapikey-test.azurewebsites.net/Voice", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
const axios = require('axios');
let data = JSON.stringify({
"from": "sender Id",
"body": "My message",
"to": "country code + phone number"
});
let config = {
method: 'post',
url: 'https://ypapikey.azurewebsites.net/SMS',
headers: {
'XApiKey': 'MY API KEY',
'Content-Type': 'application/json'
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
import http.client
import json
conn = http.client.HTTPSconnection("https://ypapikey.azurewebsites.net")
payload = json.dumps({
"from": "sender Id",
"body": "My message",
"to": "country code + phone number"
})
headers = {
'XApiKey': 'MY API KEY',
'Content-Type': 'application/json',
}
conn.request("POST", "/SMS", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
var options = new RestClientOptions("https://ypapikey.azurewebsites.net") { MaxTimeout = -1 };
var client = new RestClient(options);
var request = new RestRequest("/SMS", Method.Post);
request.AddHeader("XApiKey", "MY API KEY");
request.AddHeader("Content-Type", "application/json");
var body = @"{
@" ""from"": ""sender Id"",
@" ""body"": ""My message"",
@" ""to"": ""country code + phone number""
@"}";
request.AddStringBody(body, DataFormat.Json);
RestResponse response = await client.ExecuteAsync(request);
Console.WriteLine(response.Content);
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.post("https://ypapikey.azurewebsites.net/Voice")
.header("XApiKey", "MY API KEY")
.header("Content-Type", "application/json")
.body("{
"from": "sender Id",
"body": "My message",
"to": "country code + phone number"
}")
.asString();
Last updated