<@ULVA73B9P> in prefect 3.2.8 I have created a bl...
# ask-marvin
m
@Marvin in prefect 3.2.8 I have created a block Custom Webhook from GUI I have created an automation that when a flow goes in a particular stage sends a notification to that block with Subject: Prefect flow run notification Body: Flow run {{ flow.name }}/{{ flow_run.name }} observed in state
{{ flow_run.state.name }}
at {{ flow_run.state.timestamp }}. Flow ID: {{ flow_run.flow_id }} Flow run ID: {{ flow_run.id }} Flow run URL: {{ flow_run|ui_url }} State message: {{ flow_run.state.message }} now I want that my block forward this to the webhook to wich is linked, from the GUI how should I write the JSON data of the block?
m
To configure your Custom Webhook block in Prefect 3.2.8 to forward notifications to a specific webhook URL, you need to set up the JSON payload appropriately. Here's a general approach to setting up the JSON data for your block: 1. Webhook URL: Ensure that your block is linked to the correct webhook URL. This URL is typically assigned when you create the webhook in Prefect Cloud. 2. JSON Payload Configuration: The JSON data should be structured to include the fields that your webhook expects. Based on your notification template, you might want to format the JSON payload like this:
Copy code
json
   {
     "subject": "Prefect flow run notification",
     "body": "Flow run {{ flow.name }}/{{ flow_run.name }} observed in state `{{ flow_run.state.name }}` at {{ flow_run.state.timestamp }}. Flow ID: {{ flow_run.flow_id }} Flow run ID: {{ flow_run.id }} Flow run URL: {{ flow_run|ui_url }} State message: {{ flow_run.state.message }}"
   }
3. Dynamic Templating: Ensure that your JSON payload uses the templating syntax correctly to dynamically insert the flow and run details. Prefect will replace these placeholders with actual values at runtime. 4. HTTP Method: Your webhook likely expects a
POST
request with a JSON body. Make sure your block is configured to send data using the correct HTTP method. For more detailed guidance, you can refer to the Prefect documentation on webhook triggers and blocks. If you need further customization, consider any specific requirements of the webhook you're targeting, such as authentication headers or additional fields.
m
@Marvin 162308.727 | WARNING | prefect.server.events.actions - Action failed: 'The notification block was invalid: 1 validation error for CustomWebhookNotificationBlock\njson_data\n Input should be a valid dictionary [type=dict_type, input_value=\' {\\n "subject": "P...state.message }}"\\n
m
The error message you're encountering indicates that the JSON data for your
CustomWebhookNotificationBlock
is not being recognized as a valid dictionary. This typically happens when the JSON structure is not correctly formatted or when it's not being interpreted as a dictionary. Here are a few things to check and try: 1. Ensure Proper JSON Formatting: Make sure your JSON data is properly formatted. Every key-value pair should be enclosed in double quotes, and the overall structure should be a valid JSON dictionary. 2. Directly Input as a Dictionary: When configuring the block, ensure that the JSON is input as a dictionary. If you're pasting it as a string, it might not be parsed correctly. It should look like this:
Copy code
json
   {
     "subject": "Prefect flow run notification",
     "body": "Flow run {{ flow.name }}/{{ flow_run.name }} observed in state `{{ flow_run.state.name }}` at {{ flow_run.state.timestamp }}. Flow ID: {{ flow_run.flow_id }} Flow run ID: {{ flow_run.id }} Flow run URL: {{ flow_run|ui_url }} State message: {{ flow_run.state.message }}"
   }
3. Check for Hidden Characters: Sometimes, hidden characters or incorrect line breaks can cause JSON parsing issues. Make sure there are no extraneous characters. 4. Validate JSON: Use a JSON validator tool to ensure that your JSON structure is correct. 5. Review Documentation: You can refer to the Prefect documentation on blocks for more details on setting up and configuring blocks. If you continue to experience issues, consider checking if there are any specific requirements or examples provided by the webhook service you're integrating with, as they might have additional constraints or examples.
m
163022.990 | WARNING | prefect.server.events.actions - Action failed: 'The notification block was invalid: KeyError("params/Placeholder(full_match=\'{{ flow_run.state.name }}\', name=\'flow_run.state.name\', type=<PlaceholderType.STANDARD: \'standard\'>)")' @Marvin Query Params {"subject":"Prefect flow run notification","body":"Flow run {{ flow.name }}/{{ flow_run.name }} observed in state
{{ flow_run.state.name }}
at {{ flow_run.state.timestamp }}. Flow ID: {{ flow_run.flow_id }} Flow run ID: {{ flow_run.id }} Flow run URL: {{ flow_run|ui_url }} State message: {{ flow_run.state.message }}"}
m
The error message you're encountering suggests that there is an issue with the placeholder
{{ flow_run.state.name }}
in your JSON payload. This typically indicates that the placeholder isn't being resolved correctly, possibly due to a misconfiguration or a misunderstanding of the available placeholders in Prefect. Here's what you can check or do: 1. Verify Placeholder Usage: Ensure that the placeholders you're using are valid and available in the context of your automation or notification. Prefect uses Jinja templating for placeholders, and they should match the available attributes on the
flow_run
object. 2. Check Flow Run Attributes: Make sure that
flow_run.state.name
is a valid attribute path. You can verify this by checking the available attributes on the
flow_run
object in the Prefect documentation or by examining a flow run object in your environment. 3. Use Prefect Documentation: Refer to the Prefect documentation on templating options to ensure that your placeholders are correctly formatted and supported. 4. Debugging: If possible, log or print the
flow_run
object to inspect its attributes directly. This can help confirm whether
state.name
is the correct attribute to use. If you continue to encounter issues, consider simplifying the placeholders to isolate the problem, and ensure that the data you're trying to access is indeed available at the time of the notification.