/**
* basic send example using Comapi "One" API
*/
JavaScript
// **** ENTER YOUR DETAILS HERE ****
// Enter your API Space Id here e.g. 11164198-3f3f-4993-ab8f-70680c1113b1
var yourAPISpaceId = 'YOUR_API_SPACE_ID';
// Enter your access token here
var yourAccessToken = 'YOUR_ACCESS_TOKEN';
// Enter your mobile number in international format here e.g. for the UK 447123123123
var yourMobileNumber = 'YOUR_MOBILE_NUMBER';
// **** Call the service ****
// Create RESTful URL with API Space Id in it
var comapiUrl = "https://api.comapi.com/apispaces/" + yourAPISpaceId + "/messages";
// Setup request JSON
var myRequest = {
body: "A test sent via the One API",
to: {
phoneNumber: yourMobileNumber
},
rules: [
"sms"
]
};
// Update UI
$("#target_url").text(comapiUrl);
$("#input").text(JSON.stringify(myRequest));
// Call Comapi "One" API
jQuery.ajax({
type: "POST",
url: comapiUrl,
data: JSON.stringify(myRequest),
contentType: "application/json; charset=utf-8",
dataType: "json",
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', 'Bearer ' + yourAccessToken);
},
success: function(data, status) {
// Succeeded
$("#output").text(JSON.stringify(data));
},
error: function(request, status) {
// error handler
$("#output").text("(" + request.status + ") - " + request.responseText);
}
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.