API Sample Code: JavaScript

API submissions require very specific steps and language to send us data successfully. Using the correct framework is essential, especially for donations.

Below is specific Java Script language you can use to help make it easier to transmist data via 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>”);