Is there a way to add all states to a cloud hook v...
# prefect-community
m
Is there a way to add all states to a cloud hook via the graphql api? Right now, I'm having to provide a list of all possible states and would like to not have to maintain this if states get introduced/deprecated in the future. so instead of this
Copy code
create_cloud_hook = f"""
mutation {{
  create_cloud_hook(input: {{
    type: WEBHOOK,
    name: "{cloud_hook_name}",
    version_group_id: "{version_group_id}",
    states: ["Cached", "Cancelled", "Failed", "Finished", "Looped", "Mapped", "Paused", "Pending", "Queued", "Resume", "Retrying", "Running", "Scheduled", "Skipped", "Submitted", "Success", "Timedout", "Triggerfailed"],
    config: {{
      url: "{web_hook_url}"
    }}
  }}) {{
    id
  }}
}}
"""
something like this:
Copy code
create_cloud_hook = f"""
mutation {{
  create_cloud_hook(input: {{
    type: WEBHOOK,
    name: "{cloud_hook_name}",
    version_group_id: "{version_group_id}",
    states: ["All"],
    config: {{
      url: "{web_hook_url}"
    }}
  }}) {{
    id
  }}
}}
"""
n
Hi @Mark McDonald! This is available in the UI but iirc you want to do this on flow registration, correct?
j
I think we don’t advertise this well — I think if you pass no states it means “all states”
upvote 1
I think we should revisit how we allow specification of matching states; for example maybe you supply a state and optionally whether all subclasses should be included
states: ['State'], include_subclasses: true
c
As a workaround for now:
Copy code
from prefect.engine.state import State

[s.__name__ for s in State.children()]
should give you a complete list!
👍 1
upvote 1
j
Good news, as I check my own code (😬), I believe we already match on subclasses, so if you pass ‘STATE’ as the sole state, I’m pretty sure it would actually already work — i need to double check this though! Making a reminder for myself to confirm later today
m
Thanks for the response @Jeremiah. I tried passing in "STATE". The webhook was successfully created. However, it didn't actually add any states to the configuration
Chris's work around is working for me. Thanks all!
😄 3
j
Got it! I think that might just be some crossed wire between the UI and the logic in the API — if no states are specified, internally we trigger on all states. But I think we can be better about that!