API Sample Code: Javascript

API submissions require very specific steps and language to send us data successfully. .

Below is sample Java Script code you can use as a sample of transmitting data via the API. However, please be aware that client side JavaScript is a security risk, as your API credentials could be stolen. We strongly recommend that you use server side code instead.

JavaScript/jQuery Sample

jQuery(“#submitButton”).click(function () {
var authorizationString = “Basic XXXXXXXXXXXXXXX” //replace this with your Base64 encoded credentials
var submitData = new Object();
submitData.lastname = jQuery(“#LastName”).val();
submitData.firstname = jQuery(“#FirstName”).val();
submitData.notes = jQuery(“#Notes”).val();
submitData.source = window.location.href;
submitData[“Emails”] = [{
EmailAddress: jQuery(“#Email”).val();

data = JSON.stringify(submitData);
type: “POST”,
contentType: “application/json”,
url: “https://app.ispolitical.com/api/PublicForms“,
beforeSend: function (request) {
data: data,
dataType: “json”,
success: function (result) {
jQuery(“#SignupForm”).html(“<div class=’thankyou’>Thank you for your help on the campaign! We’ll be in touch shortly.</div>”);