https://prefect.io logo
#prefect-community
Title
# prefect-community
a

Alex Cannon

04/27/2022, 5:41 PM
Greetings all 👋 Is there a way to create a WebhookAction that includes a header in the payload via the Automations UI? If not would anyone be able to share a GraphQL query I could use to do this?
k

Kevin Kho

04/27/2022, 5:42 PM
I don’t think so. What header are you trying to add and what are you trying to achieve?
a

Alex Cannon

04/27/2022, 5:42 PM
I need to include an API key for the service I'm sending the webhook to
a

Anna Geller

04/27/2022, 5:42 PM
#1 run this mutation
Copy code
mutation {
  create_action(input: {config: {create_flow_run: {flow_group_id: "b097b505-f4b3-401d-9e69-87eccbcc0794"}}}) {
    id
  }
}
this returns action_id #2 Once you’ve got an action_id, you can create a hook to the relevant event with
create_flow_sla_failed_hook
or
create_flow_run_state_changed_hook
You can also set parameters for the action to template fields from the event, e.g.
{"foo": "foo-value", "failed_flow_run": "{flow_run_id}"}
and to validate that the action is working, you can click on the bug icon in the UI page here: https://cloud.prefect.io/team/actions
k

Kevin Kho

04/27/2022, 5:43 PM
But that’s not a way to inject an API token for the webhook right? Or can you?
a

Alex Cannon

04/27/2022, 5:45 PM
Is your question for me or Anna?
a

Anna Geller

04/27/2022, 5:46 PM
haha 😂 I'm sure you can pass the secret to your action when doing things programmatically Can you explain your use case a bit more? ideally on a business level. What type of action/webhook specifically do you try to create? what do you mean by API key - do you mean Prefect API key or some 3rd party system API key?
k

Kevin Kho

04/27/2022, 5:49 PM
My question was to Anna. Because you can programatically make the action, but I think it’s our request out that needs that header
z

Zanie

04/27/2022, 5:52 PM
You’re trying to customize the webhook action’s headers, yeah? I’ll see if this is possible
🙏 1
Yes this is possible
The GraphQL definition for configuring a webhook action looks like this:
Copy code
input webhook_action_config {
    "The webhook url to send the payload to"
    url: String!
    "An optional JSON payload, defaults to the event data"
    payload: JSON
    "Optional headers to send with the request, defaults to passing the event id"
    headers: JSON
}
You can use the
create_action
mutation as provided by Anna but instead of a
create_flow_run
action you want to use a
webhook_action
there.
👍 2
I am also curious what service you’re connecting to with this 🙂
a

Alex Cannon

04/27/2022, 6:41 PM
OpsGenie 🙂
Thanks all for the quick responses, sorry I had to step away for a bit
I'll try the GraphQL and circle back if I have any issues 🙏
👍 1
GraphQL worked, thanks all 🤘
👍 1
🙌 1
4 Views