Hi all I am trying to create a process that runs a...
# ask-community
j
Hi all I am trying to create a process that runs a deployment when a webhook is received. The process is that when a customer books a product, I want to run a code to extract all the booking information I need. The webhook delivers a confirmationCode which I want to pass into the deployement as a parameter. It seems that my automation isn't triggering even though I am receiveing the webhooks and I believe it is something regarding the "From the following resources" and "prefect.resource.id". Should I be creating a dynamic prefect.resource.id? if yes, then how should I parse it into the "From the following resources" in when creating the Automation? Also wondering, I get two prefect.resource.id, one inside the "related" and another inside "resource". Feel like I'm on track but not grasping how prefect uses the webhook event to run the deployment. Any help much appreciated
b
Hey Jakob! Instead of setting the resource as `booking-{{ body.bookingId }}`for the automation trigger, have you tried using an asterisk instead? Something like
booking-*
. This should allow you to look for matching resources that have the same
booking
prefix, but the trailing ID can still be dynamic.
j
Bianca, you're a genius. I now get an prefect cloud automation action failed event. When staring at this it looks like when I am trying to fish out the parameters in the 02 Actions (see screenshot) it returns "" instead of the confirmationCode. Not sure about the valid dictionary though. Can you assist me?
Copy code
"reason": "Unable to create flow run from deployment: 1 validation error for DeploymentFlowRunCreate\nparameters\n  Input should be a valid dictionary [type=dict_type, input_value='{\\n  \"company\": \"adventu...onfirmationCode\": \"\"\\n}', input_type=str]\n    For further information visit <https://errors.pydantic.dev/2.10/v/dict_type>"
1
b
Neat, a new error is indicative of progress. For the parameter you define in the automation action, can you try
Copy code
{
  "company": "adventures",
  "confirmationCode": "{{event.resource.confirmationCode}}"
}
To the right of your parameter on the "Action" form, there's another small hamburger menu. I believe you'll want to ensure "use Jinja input" is selected, too.
j
Allright allright! Now we are seeing my confirmationCode in the error... still failing though. I assume jinja is selected since I don't see it there. It shows up when I switch and I switched to jinja again.
Copy code
"reason": "Unable to create flow run from deployment: 1 validation error for DeploymentFlowRunCreate\nparameters\n  Input should be a valid dictionary [type=dict_type, input_value='{\\n  \"company\": \"adventu...ode\": \"ARC-58692857\"\\n}', input_type=str]\n    For further information visit <https://errors.pydantic.dev/2.10/v/dict_type>"
b
More progress! 💯 Hmm okay..the new lines in the error message are telling me that it's being parsed in a weird way. Can we try
Copy code
{
  "company": "adventures",
  "confirmationCode": "{{event.resource.confirmationCode}}"
}
all on one line ^
j
Looks more smooth now without the /n. Still getting the error though...
Copy code
"reason": "Unable to create flow run from deployment: 1 validation error for DeploymentFlowRunCreate\nparameters\n  Input should be a valid dictionary [type=dict_type, input_value='{\"company\": \"adventures\"...de\": \"ICEPRO-45381194\"}', input_type=str]\n    For further information visit <https://errors.pydantic.dev/2.10/v/dict_type>"
  },
Also tried: {"company": "adventures","confirmationCode": {{ event.resource.confirmationCode | default("") | tojson }}}
@Bianca Hoch any ideas?
b
Hey Jakob! It's still coming across as a weird string I see. Have you already tried adjusting the input types through the hamburger menu to see if that changes the outcome? 👀
j
HOWDY again. Tried them all. "Json" just failed, "Form" ran the deployment but with the parameters shown in the screenshot(assume jinja doesn't work in that case) and jinja gives me the same error. When I press show parameters here windows opens up and displays this. This looks kinda weird isn´t it?
Copy code
{
  "template": "{\"company\": \"adventures\",\"confirmationCode\": {{ event.resource.confirmationCode | default(\"\") }}}",
  "__prefect_kind": "jinja"
}
I still have it all in a one line.
Also tried removing the "" from the input in jinja
Copy code
"reason": "Unable to create flow run from deployment: 1 validation error for DeploymentFlowRunCreate\nparameters\n  Input should be a valid dictionary [type=dict_type, input_value='{company: adventures,con...tionCode: ARC-58835238}', input_type=str]\n    For further information visit <https://errors.pydantic.dev/2.10/v/dict_type>"
  },
How is prefect parsing extracted values? It looks like it is converting it to a stringified json.
b
Did some digging and you mayyy be running into the same issue that this user reported. Can you try Jean's suggestion to see if it works for you?
Looks like it will still return a json string, but you should be able to call
json.loads
on it
j
Hihi, yes tested many times. Seems to do absolutely nothing 😞 Any other suggestions? Might be bug?
😢 1
b
j
@Bianca Hoch saved me. We ended up with the definition in the image and the deployment runs now. Just remember to select jinja in the hamburger menu. The original issue still resides though regarding the json parsing and will be taken up internally at prefect
prefect build 1