mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-18 05:52:51 +00:00
# Which Problems Are Solved Naming inconsistencies - User (Human) # How the Problems Are Solved Most of the occurrences have not been changed. `User (Human)` was mostly changed when talking about code objects and where I felt it was necessary to distinguish them from machine users. When both human and machine user occurrences were found, the machine user has been changed to service account (see https://github.com/zitadel/zitadel/issues/11285) # Additional Context - Closes #11284 --------- Co-authored-by: Wim Van Laer <[email protected]>
215 lines
6.3 KiB
Plaintext
215 lines
6.3 KiB
Plaintext
---
|
|
title: Test Actions Response
|
|
---
|
|
|
|
This guide shows you how to leverage the ZITADEL actions feature to react to API responses in your ZITADEL instance.
|
|
You can use the actions feature to create a target that will be called when a specific API response occurs.
|
|
This is useful for information provisioning in between systems or for triggering workflows based on API responses in ZITADEL.
|
|
|
|
## Prerequisites
|
|
|
|
Before you start, make sure you have everything set up correctly.
|
|
|
|
- You need to be at least a ZITADEL [_IAM_OWNER_](/guides/manage/console/managers)
|
|
- Your ZITADEL instance needs to have the actions feature enabled.
|
|
|
|
<Callout>
|
|
Note that this guide assumes that ZITADEL is running on the same machine as the target and can be reached via `localhost`.
|
|
In case you are using a different setup, you need to adjust the target URL accordingly and will need to make sure that the target is reachable from ZITADEL.
|
|
</Callout>
|
|
|
|
<Callout>
|
|
To marshal and unmarshal the request and response please use a package like [protojson](https://pkg.go.dev/google.golang.org/protobuf/encoding/protojson),
|
|
as the request and response are protocol buffer messages, to avoid potential problems with the attribute names.
|
|
</Callout>
|
|
|
|
## Start example target
|
|
|
|
To test the actions feature, you need to create a target that will be called when an API endpoint is called.
|
|
You will need to implement a listener that can receive HTTP requests and process the request.
|
|
For this example, we will use a simple Go HTTP server that will print the received request to standard output.
|
|
|
|
<Callout>
|
|
The signature of the received request can be checked, [please refer to the example for more information on how to](/guides/integrate/actions/testing-request-signature).
|
|
</Callout>
|
|
|
|
```go
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
)
|
|
|
|
// webhook HandleFunc to read the request body and then print out the contents
|
|
func webhook(w http.ResponseWriter, req *http.Request) {
|
|
// read the body content
|
|
sentBody, err := io.ReadAll(req.Body)
|
|
if err != nil {
|
|
// if there was an error while reading the body return an error
|
|
http.Error(w, "error", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
defer req.Body.Close()
|
|
// print out the read content
|
|
fmt.Println(string(sentBody))
|
|
}
|
|
|
|
func main() {
|
|
// handle the HTTP call under "/webhook"
|
|
http.HandleFunc("/webhook", webhook)
|
|
|
|
// start an HTTP server with the before defined function to handle the endpoint under "http://localhost:8090"
|
|
http.ListenAndServe(":8090", nil)
|
|
}
|
|
```
|
|
|
|
<Callout title="">
|
|
The example above runs only on your local machine (`localhost`).
|
|
To test it with Zitadel, you must make your listener reachable from the internet.
|
|
You can do this by using **Webhook.site** (see [Creating a Listener with Webhook.site](./webhook-site-setup)).
|
|
</Callout>
|
|
|
|
## Create target
|
|
|
|
As you see in the example above the target is created with HTTP and port '8090' and if we want to use it as webhook, the target can be created as follows:
|
|
|
|
See [Create a target](/reference/api/action/zitadel.action.v2.ActionService.CreateTarget) for more detailed information.
|
|
|
|
```shell
|
|
curl -L -X POST 'https://${CUSTOM_DOMAIN}/v2/actions/targets' \
|
|
-H 'Content-Type: application/json' \
|
|
-H 'Accept: application/json' \
|
|
-H 'Authorization: Bearer <TOKEN>' \
|
|
--data-raw '{
|
|
"name": "local webhook",
|
|
"restWebhook": {
|
|
"interruptOnError": true
|
|
},
|
|
"endpoint": "http://localhost:8090/webhook",
|
|
"timeout": "10s"
|
|
}'
|
|
```
|
|
|
|
Save the returned ID to set in the execution.
|
|
|
|
## Set execution
|
|
|
|
To configure Zitadel to call the target when an API endpoint is called, you need to set an execution and define the response
|
|
condition.
|
|
|
|
See [Set an execution](/reference/api/action/zitadel.action.v2.ActionService.SetExecution) for more detailed information.
|
|
|
|
```shell
|
|
curl -L -X PUT 'https://${CUSTOM_DOMAIN}/v2/actions/executions' \
|
|
-H 'Content-Type: application/json' \
|
|
-H 'Accept: application/json' \
|
|
-H 'Authorization: Bearer <TOKEN>' \
|
|
--data-raw '{
|
|
"condition": {
|
|
"response": {
|
|
"method": "/zitadel.user.v2.UserService/CreateUser"
|
|
}
|
|
},
|
|
"targets": [
|
|
"<TargetID returned>"
|
|
]
|
|
}'
|
|
```
|
|
|
|
## Example call
|
|
|
|
Now that you have set up the target and execution, you can test it by creating a user through the Management Console UI or
|
|
by calling the ZITADEL API to create a user.
|
|
|
|
```shell
|
|
curl -L -X POST 'https://${CUSTOM_DOMAIN}/v2/users/new' \
|
|
-H 'Content-Type: application/json' \
|
|
-H 'Accept: application/json' \
|
|
-H 'Authorization: Bearer <TOKEN>' \
|
|
--data-raw '{
|
|
"organizationId": "344648897353810062",
|
|
"human":
|
|
{
|
|
"profile":
|
|
{
|
|
"givenName": "Minnie",
|
|
"familyName": "Mouse",
|
|
"nickName": "Mini",
|
|
"displayName": "Minnie Mouse",
|
|
"preferredLanguage": "en",
|
|
"gender": "GENDER_FEMALE"
|
|
},
|
|
"email":
|
|
{
|
|
"email": "[email protected]"
|
|
}
|
|
}
|
|
}'
|
|
```
|
|
|
|
Your server should now print out something like the following. Check out
|
|
the [Sent information Response](./usage#sent-information-response) payload description.
|
|
The incoming request headers to the Execution are propagated via the request payload to the target.
|
|
|
|
```json
|
|
{
|
|
"fullMethod": "/zitadel.user.v2.UserService/CreateUser",
|
|
"instanceID": "344648897353744526",
|
|
"orgID": "344648897353810062",
|
|
"projectID": "344648897353875598",
|
|
"userID": "344648897354465422",
|
|
"request":
|
|
{
|
|
"organizationId": "344648897353810062",
|
|
"human":
|
|
{
|
|
"profile":
|
|
{
|
|
"givenName": "Minnie",
|
|
"familyName": "Mouse",
|
|
"nickName": "Mini",
|
|
"displayName": "Minnie Mouse",
|
|
"preferredLanguage": "en",
|
|
"gender": "GENDER_FEMALE"
|
|
},
|
|
"email":
|
|
{
|
|
"email": "[email protected]"
|
|
}
|
|
}
|
|
},
|
|
"response":
|
|
{
|
|
"id": "336494809936035843",
|
|
"creationDate": "2025-09-05T08:55:36.156333Z"
|
|
},
|
|
"headers":
|
|
{
|
|
"Content-Type":
|
|
[
|
|
"application/grpc"
|
|
],
|
|
"Host":
|
|
[
|
|
"localhost:8080"
|
|
],
|
|
"X-Forwarded-For":
|
|
[
|
|
"::1"
|
|
],
|
|
"X-Forwarded-Host":
|
|
[
|
|
"localhost:8080"
|
|
]
|
|
}
|
|
}
|
|
```
|
|
|
|
## Conclusion
|
|
|
|
You have successfully set up a target and execution to react to API responses in your ZITADEL instance.
|
|
This feature can now be used to provision information in between systems or for triggering workflows based on API responses in ZITADEL.
|
|
Find more information about the actions feature in the [API documentation](/concepts/features/actions_v2).
|