How to Use the SmartLead Magnet API
This guide provides detailed instructions on how to use the SmartLead Magnet 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
-
Sign in to Your SmartLead Magnet Account
- Go to SmartLead Magnet and log in with your credentials.
-
Navigate to API Settings
- Click on your profile avatar or name to open the user menu.
- Select Settings or API Keys from the dropdown menu.
- Alternatively, go directly to API Key Management.
-
Create a New API Key
- Click on Generate New Key.
- Give your API key a descriptive name (e.g., "My App Integration").
- Click Create to generate the key.
- Important: Copy the API key and store it securely. You won't be able to view it again.
Using the API Key
Include your API key in the Authorization
header of your HTTP requests.
Example in JavaScript:
Making a Request
To use one of your lead magnets via the API, send a POST request to:
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
- Go to Your Lead Magnets
- Navigate to SmartLead Magnet Managed Keys.
- 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:
Full Example Request
Here's how you might structure a full API request using JavaScript (e.g., with fetch
or axios
):
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:
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:
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
- Support: If you need assistance, contact us at [email protected].