// **** 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); } });
<div class="container"> <h1>"One" API basic send</h1> <hr/>HTTPS POST to: <b><span id="target_url"></span></b> <hr/> <h2> Input JSON </h2> <div id="input" style="background-color: white;">   </div> <hr/> <h2> Output JSON </h2> <div id="output" style="background-color: white;">   </div> </div>