If you have an advanced form that cannot be captured using Autopilot's form capture or Zapier integration, you can capture it via the Autopilot API. Please note, however, that Autopilot's form capture is compatible with most forms, so before capturing the form via API we highly recommend reviewing the form troubleshooting guide.
Add the tracking code
Autopilot has two separate tracking codes, optimized for web pages and web apps. Both load the Autopilot library and can be used for user association.
If the form is on your website (for example, a newsletter subscription form) then use the website tracking code. If it is in your web app (for example, a user preferences tab) then use the app tracking code.
Paste the code into the <head> tag of your web page or app’s HTML (depending on the use case).
Create any custom fields
User association allows you to pass any standard or custom field to Autopilot. Before you implement user association, check if the fields you are capturing are already included in Autopilot’s standard fields. If they are not included, you will need to create new custom fields.
Implement user association
In your HTML, after the the form is submitted, pull the submitted fields and the visitor’s _autopilot_session_id and pass the data server-side to be transmitted securely via the encrypted Autopilot API calls.
If a form is submitted by a visitor who isn’t yet in Autopilot as a contact, we’ll automatically add them as a new contact. Existing users will have their data updated.
The call for pulling the session ID is:
var sessionId = AutopilotAnywhere.sessionId;
Call the add/update contact API call
Please note that:
- email address is required, as we use it as a unique identifier for contacts in Autopilot; and
- spaces in custom field names are represented as -- in the call; and
- adding a custom field with the form’s name or ID is recommended to help you track of the source of the contacts.
You will use the POST Add/Update Contact API call to send this. You will send over any standard fields and custom fields you want to update as part of the body of the call. For example:
autopilotapikey = <Your API Key>
Content-Type = application/json
"string--Form--Name": "Blog Subscriber",
If your call is accepted, you will receive a 200 response. A full list of other possible responses including errors and what they mean can be found in the API documentation.