API Sample Code: Jquery
API submissions require very specific steps and language to send us data successfully.
Below is sample jQuery 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 () {
let authorizationString = "Basic XXXXXXXXXXXXXXX" //replace this with your Base64 encoded credentials
let 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);
jQuery.ajax({
type: "POST",
contentType: "application/json",
url: "https://app.ispolitical.com/api/PublicForms",
beforeSend: function (request) {
request.setRequestHeader("Authorization",authorizationString);
},
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>");
}
});
});