Webhooks


Index

What can I do with Webhooks?

How Can I Use Webhooks?

Read-To-Use Script to break down assets by type

Automation Example 1: Using Webhooks to capture connection data in a spreadsheet (w/ Zapier)

Automation Example 2: Using Webhooks to update a CRM with connection data (w/ Zapier)

Automation Example 3: Using Webhooks to send notifications to Slack (w/ Zapier)


What can I do with Webhooks?

Webhooks can be used to trigger automation after you receive access to client assets.

Using our Webhook, you can connect Leadsie with automation tools such as Zapier, Pabbly Connect, Make (formerly Integromat) or your own application.

For example, you could send an email to a client that successfully connected their accounts with you or send an internal email to a team member.

Another example would be incorporating the accounts that your client has authorized you to access into a CRM.

How Can I Use Webhooks?

Once you have your Webhook URL, go to your Leadsie Dashboard > Settings > Webhooks & API

Here you can enter your Webhooks URL where a POST request will be sent every time one of your requests gets a new connection.

NOTE: You can specify the user Id by appending a parameter to the request URL ?customUserId=user123456

If this customUserId is left empty, then the response will not show a user Id.

Once a user completes a request, you will be sent a "post request" like the following to that webhook.

You can also set the userId by adding a customer parameter in the connection page URL:

?customUserId=SOME_UNIQUE_STRING

More specifically, it will have this structure:

{
    user: String, // this will be set as the customUserId that was passed through to the page in the parameters
    requestUrl: String, // the url of the request
    requestName: String, // the name of the request if there is one - or else a specific id tied to that request
    accessLevel: "view" | "admin",
    status: 'SUCCESS'|'PARTIAL_SUCCESS'|'FAILED',
    connectionAssets: [{
        type: "Ad Account" | "Page" | "Pixel" | "Instagram Account" | "Catalog",
        name: String,
        id: String,
        isSuccess: Boolean,
        message: String
        time: Date,
}

Script to use in Zapier (or other tools) to get separate data for each asset


The Python script included below allows you to break out each asset type you receive access to and its status, to update different values in your CRM for example.

Here's an example data that you can extract using the Python code:

Here's the Python code you need to use in Zapier / your automation tool to separate data for each asset:
import json
try:
    actual_payload = input.get('payload', {})
    if isinstance(actual_payload, str):
        actual_payload = json.loads(actual_payload)
    output = {
        'user_id': actual_payload.get('user', ''),  # Use get to avoid KeyError if 'user' is not set
        'requestUrl': actual_payload['requestUrl'],
        'requestName': actual_payload['requestName']
    }
    # Loop through each item in connectionAssets
    for item in actual_payload['connectionAssets']:
        prefix = item['type'].lower().replace(' ', '_')  # Create a prefix for output keys based on asset type
        # Add the relevant data to output with keys prefixed by asset type, aggregate if key already exists
        output[f"{prefix}_id"] = f"{output.get(f'{prefix}_id', '')}, {item['id']}".strip(', ')
        output[f"{prefix}_name"] = f"{output.get(f'{prefix}_name', '')}, {item['name']}".strip(', ')
        output[f"{prefix}_is_success"] = f"{output.get(f'{prefix}_is_success', '')}, {item['isSuccess']}".strip(', ')
        output[f"{prefix}_message"] = f"{output.get(f'{prefix}_message', '')}, {item.get('message', '')}".strip(', ')
except KeyError as e:
    output = {'error': f"KeyError: The key {str(e)} is not present in the input data.", 'available_keys': list(actual_payload.keys()) if 'actual_payload' in locals() else []}
except json.JSONDecodeError as e:
    output = {'error': f"JSONDecodeError: Could not decode the payload string. Error: {str(e)}", 'raw_payload': str(input.get('payload', ''))}

return output

Automation Example 1: Using Webhooks to capture connection data in a spreadsheet (w/ Zapier)



Automation Example 2: Using Webhooks to update a CRM with connection data (w/ Zapier)


Automation Example 3: Using Webhooks to send notifications to Slack (w/ Zapier)

Still need help? Contact Us Contact Us