Webhooks: How to send Slack notifications for new connections

In this tutorial, we demonstrate how to set up Slack notifications for new connections. This will keep you informed of any updates when clients grant you access.

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'],
        'clientName': actual_payload['clientName'],
        'clientSummaryUrl': actual_payload['clientSummaryUrl']
    }
    # 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

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.


If you are getting blank data on your Python step (shown in the image below), please retest your request link and grant access again. This will give you a new record on your Webhook step.


Any issues? Reach out to us, and we're happy to help.

Still need help? Contact Us Contact Us