Logo

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

  1. Sign in to Your SmartLead Magnet Account

  2. 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.
  3. 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.

Authorization: Bearer YOUR_API_KEY Content-Type: application/json

Example in JavaScript:

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://smartleadmagnet.com/api/leadmagnet

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
  1. 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", "color": "#000000", "email": "[email protected]" }

Full Example Request

Here's how you might structure a full API request using JavaScript (e.g., with fetch or axios):

const axios = require('axios'); const apiUrl = 'https://smartleadmagnet.com/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]', }; axios .post(apiUrl, data, { headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${apiKey}`, }, }) .then((response) => { console.log('Success:', response.data); }) .catch((error) => { console.error('Error:', error.response ? error.response.data : error.message); });

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