Form Response API
The Form Response API allows you to retrieve an individual form response programmatically in JSON format or as a PDF document.
The API returns the same information you can get with a webhook.
The Form Response API
To look up a form response 1, insert its Reference Number into the URL below and submit a GET
request:
API Endpoint | ||
---|---|---|
https://formsmarts.com/api/v1/entries/Ref_Number | ||
HTTP Method | ||
GET | ||
Parameter | Description | Notes |
structure | Set to true to include the form structure (list of input fields with their name, ID and data type) and metadata (form ID) in the API response. | Optional, true or false, defaults to false. |
presigned_urls | Set to true to include pre-signed URLs in the API response so you can automatically retrieve the form uploads and eSignatures associated with the form submission. Pre-signed URLs are only valid for a few minutes. | Optional, true or false, defaults to false. |
timezone | Timezone used for dates in the API response, for example America/Los_Angeles. Timezones are listed here. | Optional. If missing, we use the timezone of your account or UTC if no timezone is set. |
API Response
If the request is successful, the API returns an HTTP 200 status and a JSON object with the form entry.
- If the structure parameter is true, the API response has a form (form metadata) and a fields attribute
- The form response is accessible at
api_response["entries"][0]
. This is for consistency with APIs returning multiple form submissions. - If the form entry has a form context value, it is included in
api_response["entries"][0]["context"]["value"]
- If the form submission involved a payment, the amount, currency, processor name and transaction ID of the payment are available in a
api_response["entries"][0]["payment"]
object, for example:{'amount': '380.00', 'currency': 'USD', 'processor_name': 'paypal', 'transaction_id': '4XW287768B821925'}
- As shown below, the value of upload and signature fields are JSON object. All other values are scalars.
Example
This is the API response for this form demo:
{ "form": { "id": "lqh" }, "fields": [ { "name": "Full Name", "id": 122619, "type": "name" }, { "name": "Email", "id": 122620, "type": "email" }, { "name": "Upload Your Picture", "id": 122621, "type": "upload" }, { "name": "Comments", "id": 123744, "type": "text" } ], "entries": [ { "entry": [ "Jane Doe", "jane@example.com", { "type": "upload", "attachment_id": "f8ud", "filename": "Capture.PNG", "presigned_url": "..." }, "Hello, this is the picture for the project." ], "metadata": { "reference_number": "A3PG3EUJV27KZXJHC5TNK2CQI", "date_submitted": "2022-04-25T02:20:53-07:00", "ip_address": "1.1.1.1" } } ] }
If the request fails, the API returns a non-success HTTP status with a JSON object specifying the error:
Authentication
FormSmarts verifies API requests with a JWT token in the Authorization header. You can sign requests with the FormSmarts API Client or a JWT library in your favorite programming language. You'll need to know your FormSmarts Account ID and secret FormSmarts API Key.
You'll find your Account ID in the Account Overview section of your account and your API Key in the Security Settings.
Python Example
Let's wrap this up with an example showing how to get a form entry in Python.
#!/usr/bin/env python3 import json import requests import config from formsmarts_api import APIAuthenticator REF_NUM = 'A3PG3EUJV27KZXJHC5TNK2CQI' ENTRY_API_URL = 'https://formsmarts.com/api/v1/entries/{}'.format(REF_NUM) class APITest: def __init__(self): self._au = APIAuthenticator(config.FORMSMARTS_ACCOUNT_ID, config.FORMSMARTS_API_KEY) def get_headers(self): return {APIAuthenticator.AUTH_HEADER: self._au.get_authorization_header()} def send_api_request(self, endpoint, **params): resp = requests.get(endpoint, params=params, headers=self.get_headers()) try: body = json.loads(resp.text) # Response should be JSON except json.JSONDecodeError: body = resp.text if resp.status_code == 200: print(body) print('{} result(s)'.format(len(body['entries']))) else: print('Error {}: {}'.format(resp.status_code, resp.text)) if __name__ == '__main__': APITest().send_api_request(ENTRY_API_URL, structure='true', presigned_urls='true')
The code above imports your account credentials from a config file, a Python module called config.py:
# You'll find your Account ID at: https://formsmarts.com/account/view FORMSMARTS_ACCOUNT_ID = 'FSA-999999' # You'll find your API Key at: https://formsmarts.com/account/view#security-settings FORMSMARTS_API_KEY = 'TqE35BBzxfmxC74YQ4jQCPFx1oKvFhECOfWrbTh8fVMG6viZWiTfvh4dOZSSK71v'
Node.js Example
The Form Submission API has a Node.js example.
The Form Response PDF API
The Form Response PDF API allows you to export a form submission as a PDF document. The PDF generated is the same as the one you can get online and via the Download PDF link in email notifications.
To export up a form response as a PDF document 1, insert its Reference Number into the URL below and submit a GET
request:
API Endpoint | ||
---|---|---|
https://formsmarts.com/api/v1/entries/Ref_Number .pdf | ||
HTTP Method | ||
GET | ||
Parameter | Description | Notes |
timezone | Timezone used for dates in the API response, for example America/Los_Angeles. Timezones are listed here. | Optional. If missing, we use the timezone of your account or UTC if no timezone is set. |
- Not available with Business Starter and Plus accounts.