Webhooks: How to use them with Zapier and how to break out asset types

In this video, we show you how you can get separate data for each asset type and use that, for example, to automatically update clients in your CRM software. This can help you easily identify what assets were shared by your clients.

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


Below is the Script mentioned in the video above that you can simply copy/paste to your Code action in Zapier or any other automation tool.

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

And this is how you would use that data to update your CRM


Here's the Python code you need to use in Zapier / your automation tool to separate data for each asset (updated March 20, 2024):
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

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