Skip to main content

How to Use the FormMaker API

This guide provides detailed instructions on how to use the FormMaker API to manage your lead magnets programmatically.

Authorization

To interact with the API, you'll need to generate an API key.

Generating an API Key

  1. Sign in to Your FormMaker Account

    • Go to FormMaker and log in with your credentials.
  2. Gentrate Key on Dashoboard

    • You will find genrate key option in Dashbaord
  3. Create a New API Key

    • Click on Generate New Key.
    • Give your API key
    • Important: Copy the API key and store it securely.

Using the API Key

Include your API key in the Authorization header of your HTTP requests.

Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Example in JavaScript (using Fetch):

const headers = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${yourApiKey}`,
};

Making a Request

To use one of your lead magnets via the API, send a POST request to:

https://formmaker.co.in/api/app

Request Headers

Include the following headers in your request:

  • Content-Type: application/json
  • Authorization: Bearer YOUR_API_KEY

Request Body

In the request body, include:

  • id: The ID of the lead magnet you want to use.
  • Key-value pairs for each input field required by your lead magnet.

Obtaining the Lead Magnet ID and API Schema

  1. Go to Your Lead Magnets

  2. Get the Lead Magnet ID and Schema

    • Find the lead magnet you want to use.
    • Click on the Action menu (usually represented by three dots).
    • Select Get API Schema or View Details.
    • Note the id field in the schema; this is your lead magnet's unique ID.
    • Review the schema to understand the required input fields.

Example Request Body

Here's an example of what your JSON request body might look like:

{
"id": "6704013026e9b885593bfsss",
"text": "Sample Paragraph",
"email": "[email protected]"
}

Full Example Request

Here's how you might structure a full API request using fetch:

const apiUrl = 'https://formmaker.co.in/api/leadmagnet';
const apiKey = 'YOUR_API_KEY'; // Replace with your actual API key

const data = {
id: '6704013026e9b885593bfsss', // Replace with your lead magnet ID
text: 'Sample Paragraph',
color: '#000000',
email: '[email protected]',
};

fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`,
},
body: JSON.stringify(data),
})
.then((response) => response.json())
.then((data) => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error);
});

Note: Replace YOUR_API_KEY with the API key you generated and id with your actual lead magnet ID.

Handling the Response

Upon a successful request, the API will return a response containing:

  • Status Code: 200 OK
  • Data: Any data returned by the lead magnet, such as confirmation messages or lead details.

Example Response:

{
"success": true,
"message": "Lead magnet processed successfully.",
"data": {
"leadId": "abc123xyz",
"email": "[email protected]",
"status": "subscribed"
}
}

Error Handling

If there's an error with your request, the API will return an error response. Common errors include:

  • 401 Unauthorized: Your API key is missing or invalid.
  • 400 Bad Request: The request body is malformed or missing required fields.
  • 404 Not Found: The lead magnet ID does not exist.

Example Error Response:

{
"success": false,
"message": "Invalid API key."
}

Tips for Error Handling

  • Check Response Codes: Always check the HTTP status code of the response.
  • Validate Input Data: Ensure all required fields are included and correctly formatted.
  • Secure Storage: Keep your API key secure and do not expose it in client-side code.

Additional Resources