<@U04UQ68083H> provide an example of hook, that pa...
# ory-copilot
s
@chilly-king-10285 provide an example of hook, that passes additional data when registration flow completed as described in https://www.ory.sh/docs/guides/integrate-with-ory-cloud-through-webhooks
c
A message from kapa.ai
Certainly! To pass additional data to a webhook when the registration flow is completed in Ory, you can use the
transient_payload
field. This field allows you to send extra, non-persisted data to your webhook, which can then be accessed in your webhook's Jsonnet template via the
ctx.transient_payload
object. Example: 1. Submitting the registration flow with additional data: When you submit the registration flow, include the
transient_payload
field in your request. For example, using cURL:
Copy code
bash curl -X POST \     -H 'Content-Type: application/json' \     -H 'Accept: application/json' \     -d '{       "method": "password",       "csrf_token": "your-csrf-token",       "traits.email": "<mailto:email@example.com|email@example.com>",       "password": "verystrongpassword",       "traits.tos": "true",       "transient_payload.consents": "newsletter,usage_stats"     }' \     -b cookies.txt \     -c cookies.txt \     "https://$<http://PROJECT_SLUG.projects.oryapis.com/self-service/registration?flow=<your-flow-id|PROJECT_SLUG.projects.oryapis.com/self-service/registration?flow=<your-flow-id>>"
This sends the
transient_payload.consents
value along with the registration request. This data will be forwarded to any configured webhooks but will not be persisted by Ory [Submit registration flow](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#submit-registration-flow). 2. Webhook configuration to receive the additional data: In your webhook's Jsonnet template, you can access the additional data via
ctx.transient_payload
. For example:
Copy code
jsonnet function(ctx) {   user_id: ctx.identity.id,   consents: ctx.transient_payload.consents }
This template will include both the user's ID and the additional
consents
data in the webhook request body [Define HTTP request](https://www.ory.sh/docs/guides/integrate-with-ory-cloud-through-webhooks#define-http-request). Summary: - Add your extra data to the
transient_payload
field when submitting the registration flow. - Access this data in your webhook using
ctx.transient_payload
in your Jsonnet template. This approach is documented and supported in Ory [Passing additional data on registration](https://www.ory.sh/docs/guides/integrate-with-ory-cloud-through-webhooks) and [transient_payload field usage](https://github.com/ory/network/issues/187).