<@ULVA73B9P> What's the correct format for the pay...
# ask-marvin
s
@Marvin What's the correct format for the payload to pass to the *Create Events: POST*'/api/events' endpoint in the REST API?
m
The payload for the Create Events: POST
/api/events
endpoint in the Prefect REST API typically includes an
event
and a
resource
definition. Prefect Cloud will populate default values for any missing fields, like
occurred
and
id
, so you don't need to include those in your payload. Here's a basic structure you might use:
Copy code
json
{
  "event": "your-event-name",
  "resource": {
    "prefect.resource.id": "your-resource-id",
    "prefect.resource.description": "your-resource-description"
  },
  "payload": {
    // Any additional data you want to include
  }
}
For more detailed information, you can refer to the Prefect documentation on webhook triggers.
s
@Marvin what should be the content of the 'resource' ? What is it referring to?
m
The
resource
field in the event payload refers to the primary resource that the event concerns. It typically includes an identifier and a description of the resource. In the context of Prefect, resources can be objects like flows, tasks, deployments, work queues, and logs. These resources are often prefixed with
prefect
or
prefect-cloud
. Here’s a brief overview of the
resource
field structure: -
prefect.resource.id
: A unique identifier for the resource. This is typically a string that you define to identify the resource related to the event. -
prefect.resource.description
: A description of the resource, providing context about what the resource is or the action that was taken. For example, if you are emitting an event related to a deployment request, your
resource
might look like this:
Copy code
json
"resource": {
  "prefect.resource.id": "deployment-request-123",
  "prefect.resource.description": "A deployment request was created"
}
This structure helps Prefect understand what the event is about and how it relates to your Prefect objects. More details can be found in the Prefect documentation on events.
s
@Marvin So if I'm targeting an automation resource when creating an event, should I call it as "prefect.resource.id": "my-automation-name" or "prefect.resource.id": "prefect.my-automation-name" ?
m
When targeting an automation resource while creating an event, you should use the
prefect
prefix to clearly identify it as a Prefect resource. Therefore, you should format it as
"prefect.resource.id": "prefect.my-automation-name"
. This ensures that the resource is recognized as part of the Prefect ecosystem and follows the structured specification for events.