fix(doc): update actions v2 examples (#11017)

# Which Problems Are Solved

This PR fixes the examples used in the actions v2 docs. 

# How the Problems Are Solved

* By fixing the actions v2 import path used in the example

# Additional Changes

* Use actions v2 instead of actions v2beta in the examples
* Use v2 `CreateUser` instead of v2beta `AddHumanUser` in
`request-manipulation` example

# Additional Context
- Follow up for https://github.com/zitadel/zitadel-go/issues/523
This commit is contained in:
Gayathri Vijayan
2025-11-04 15:18:30 +00:00
committed by GitHub
parent 66e04b1dad
commit 14038716e3
9 changed files with 152 additions and 125 deletions
@@ -74,7 +74,7 @@ target can be created as follows:
See [Create a target](/apis/resources/action_service_v2/action-service-create-target) for more detailed information.
```shell
curl -L -X POST 'https://$CUSTOM-DOMAIN/v2beta/actions/targets' \
curl -L -X POST 'https://$CUSTOM-DOMAIN/v2/actions/targets' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
@@ -98,7 +98,7 @@ condition.
See [Set an execution](/apis/resources/action_service_v2/action-service-set-execution) for more detailed information.
```shell
curl -L -X PUT 'https://$CUSTOM-DOMAIN/v2beta/actions/executions' \
curl -L -X PUT 'https://$CUSTOM-DOMAIN/v2/actions/executions' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
@@ -100,7 +100,7 @@ As you see in the example above the target is created with HTTP and port '8090'
See [Create a target](/apis/resources/action_service_v2/action-service-create-target) for more detailed information.
```shell
curl -L -X POST 'https://$CUSTOM-DOMAIN/v2beta/actions/targets' \
curl -L -X POST 'https://$CUSTOM-DOMAIN/v2/actions/targets' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
@@ -124,7 +124,7 @@ condition.
See [Set an execution](/apis/resources/action_service_v2/action-service-set-execution) for more detailed information.
```shell
curl -L -X PUT 'https://$CUSTOM-DOMAIN/v2beta/actions/executions' \
curl -L -X PUT 'https://$CUSTOM-DOMAIN/v2/actions/executions' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
@@ -78,7 +78,7 @@ As you see in the example above the target is created with HTTP and port '8090'
See [Create a target](/apis/resources/action_service_v2/action-service-create-target) for more detailed information.
```shell
curl -L -X POST 'https://$CUSTOM-DOMAIN/v2beta/actions/targets' \
curl -L -X POST 'https://$CUSTOM-DOMAIN/v2/actions/targets' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
@@ -102,7 +102,7 @@ condition.
See [Set an execution](/apis/resources/action_service_v2/action-service-set-execution) for more detailed information.
```shell
curl -L -X PUT 'https://$CUSTOM-DOMAIN/v2beta/actions/executions' \
curl -L -X PUT 'https://$CUSTOM-DOMAIN/v2/actions/executions' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
@@ -46,15 +46,15 @@ import (
)
type contextRequest struct {
Request *addHumanUserRequestWrapper `json:"request"`
Request *createUserRequestWrapper `json:"request"`
}
// addHumanUserRequestWrapper necessary to marshal and unmarshal the JSON into the proto message correctly
type addHumanUserRequestWrapper struct {
user.AddHumanUserRequest
// createUserRequestWrapper necessary to marshal and unmarshal the JSON into the proto message correctly
type createUserRequestWrapper struct {
user.CreateUserRequest
}
func (r *addHumanUserRequestWrapper) MarshalJSON() ([]byte, error) {
func (r *createUserRequestWrapper) MarshalJSON() ([]byte, error) {
data, err := protojson.Marshal(r)
if err != nil {
return nil, err
@@ -62,7 +62,7 @@ func (r *addHumanUserRequestWrapper) MarshalJSON() ([]byte, error) {
return data, nil
}
func (r *addHumanUserRequestWrapper) UnmarshalJSON(data []byte) error {
func (r *createUserRequestWrapper) UnmarshalJSON(data []byte) error {
return protojson.Unmarshal(data, r)
}
@@ -82,14 +82,17 @@ func call(w http.ResponseWriter, req *http.Request) {
if err := json.Unmarshal(sentBody, request); err != nil {
http.Error(w, "error", http.StatusInternalServerError)
}
// build the response from the received request
response := request.Request
// manipulate the request to send back as response
if response.Metadata == nil {
response.Metadata = make([]*user.SetMetadataEntry, 0)
metadata := response.GetHuman().GetMetadata()
if metadata == nil {
metadata = make([]*user.Metadata, 0)
}
response.Metadata = append(response.Metadata, &user.SetMetadataEntry{Key: "organization", Value: []byte("company")})
metadata = append(metadata, &user.Metadata{Key: "organization", Value: []byte("dunder mifflin")})
response.GetHuman().Metadata = metadata
// marshal the request into json
data, err := json.Marshal(response)
@@ -126,7 +129,7 @@ As you see in the example above the target is created with HTTP and port '8090'
See [Create a target](/apis/resources/action_service_v2/action-service-create-target) for more detailed information.
```shell
curl -L -X POST 'https://$CUSTOM-DOMAIN/v2beta/actions/targets' \
curl -L -X POST 'https://$CUSTOM-DOMAIN/v2/actions/targets' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
@@ -149,7 +152,7 @@ To call the target just created before, with the intention to manipulate the req
See [Set an execution](/apis/resources/action_service_v2/action-service-set-execution) for more detailed information.
```shell
curl -L -X PUT 'https://$CUSTOM-DOMAIN/v2beta/actions/executions' \
curl -L -X PUT 'https://$CUSTOM-DOMAIN/v2/actions/executions' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
@@ -176,7 +179,7 @@ curl -L -X POST 'https://$CUSTOM-DOMAIN/v2/users/new' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
--data-raw '{
"organizationId": "336392597046099971",
"organizationId": "344648897353810062",
"human":
{
"profile":
@@ -205,7 +208,7 @@ curl -L -X PUT 'https://$CUSTOM-DOMAIN/v2/users/new' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
--data-raw '{
"organizationId": "336392597046099971",
"organizationId": "344648897353810062",
"human":
{
"profile":
@@ -220,11 +223,15 @@ curl -L -X PUT 'https://$CUSTOM-DOMAIN/v2/users/new' \
"email":
{
"email": "[email protected]"
}
},
"metadata":
[
{
"key": "organization",
"value": "ZHVuZGVyIG1pZmZsaW4="
}
]
}
"metadata": [
{"key": "organization", "value": "Y29tcGFueQ=="}
]
}'
```
@@ -38,10 +38,10 @@ import (
"io"
"net/http"
"github.com/zitadel/zitadel/pkg/actions"
"github.com/zitadel/zitadel-go/v3/pkg/actions"
)
const signingKey = "somekey"
const signingKey = "somekey" // signing key received after creating the target
// webhook HandleFunc to read the request body and then print out the contents
func webhook(w http.ResponseWriter, req *http.Request) {
@@ -54,7 +54,7 @@ func webhook(w http.ResponseWriter, req *http.Request) {
}
defer req.Body.Close()
// validate signature
if err := actions.ValidatePayload(sentBody, req.Header.Get(actions.SigningHeader), signingKey); err != nil {
if err := actions.ValidateRequestPayload(sentBody, &req.Header, signingKey); err != nil {
// if the signed content is not equal the sent content return an error
http.Error(w, "error", http.StatusInternalServerError)
return
@@ -85,7 +85,7 @@ As you see in the example above the target is created with HTTP and port '8090'
See [Create a target](/apis/resources/action_service_v2/action-service-create-target) for more detailed information.
```shell
curl -L -X POST 'https://$CUSTOM-DOMAIN/v2beta/actions/targets' \
curl -L -X POST 'https://$CUSTOM-DOMAIN/v2/actions/targets' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
@@ -99,7 +99,15 @@ curl -L -X POST 'https://$CUSTOM-DOMAIN/v2beta/actions/targets' \
}'
```
Save the returned ID to set in the execution.
Example response after creating the target:
```json
{
"id": "344649040681500814",
"creationDate": "2025-10-31T15:00:36.432595dZ",
"signingKey": "somekey"
}
```
Save the returned ID to set in the execution. Use the `signingKey` to validate the request signature.
## Set execution
@@ -109,7 +117,7 @@ condition.
See [Set an execution](/apis/resources/action_service_v2/action-service-set-execution) for more detailed information.
```shell
curl -L -X PUT 'https://$CUSTOM-DOMAIN/v2beta/actions/executions' \
curl -L -X PUT 'https://$CUSTOM-DOMAIN/v2/actions/executions' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
@@ -131,12 +139,12 @@ Now that you have set up the target and execution, you can test it by creating a
by calling the ZITADEL API to create a human user.
```shell
curl -L -X PUT 'https://$CUSTOM-DOMAIN/v2/users/new' \
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": "336392597046099971",
"organizationId": "344648897353810062",
"human":
{
"profile":
@@ -150,7 +158,7 @@ curl -L -X PUT 'https://$CUSTOM-DOMAIN/v2/users/new' \
},
"email":
{
"email": "[email protected]"
"email": "mini+test@mouse.com"
}
}
}'
@@ -161,46 +169,50 @@ the [Sent information Request](./usage#sent-information-request) payload descrip
```json
{
"fullMethod": "/zitadel.user.v2.UserService/CreateUser",
"instanceID": "336392597046034435",
"orgID": "336392597046099971",
"projectID": "336392597046165507",
"userID": "336392597046755331",
"request":
"fullMethod": "/zitadel.user.v2.UserService/CreateUser",
"instanceID": "344648897353744526",
"orgID": "344648897353810062",
"projectID": "344648897353875598",
"userID": "344648897354465422",
"request":
{
"organizationId": "344648897353810062",
"human":
{
"organizationId": "336392597046099971",
"human":
{
"profile":
{
"givenName": "Minnie",
"familyName": "Mouse",
"nickName": "Mini",
"displayName": "Minnie Mouse",
"preferredLanguage": "en",
"gender": "GENDER_FEMALE"
},
"email":
{
"email": "[email protected]"
}
}
},
"headers":
{
"Content-Type":
[
"application/grpc"
],
"Host":
[
"localhost:8080"
],
"X-Forwarded-Host":
[
"localhost:8080"
]
"profile":
{
"givenName": "Minnie",
"familyName": "Mouse",
"nickName": "Mini",
"displayName": "Minnie Mouse",
"preferredLanguage": "en",
"gender": "GENDER_FEMALE"
},
"email":
{
"email": "[email protected]"
}
}
},
"headers":
{
"Content-Type":
[
"application/grpc"
],
"Host":
[
"localhost:8080"
],
"X-Forwarded-For":
[
"::1"
],
"X-Forwarded-Host":
[
"localhost:8080"
]
}
}
```
@@ -78,7 +78,7 @@ As you see in the example above the target is created with HTTP and port '8090'
See [Create a target](/apis/resources/action_service_v2/action-service-create-target) for more detailed information.
```shell
curl -L -X POST 'https://$CUSTOM-DOMAIN/v2beta/actions/targets' \
curl -L -X POST 'https://$CUSTOM-DOMAIN/v2/actions/targets' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
@@ -102,7 +102,7 @@ condition.
See [Set an execution](/apis/resources/action_service_v2/action-service-set-execution) for more detailed information.
```shell
curl -L -X PUT 'https://$CUSTOM-DOMAIN/v2beta/actions/executions' \
curl -L -X PUT 'https://$CUSTOM-DOMAIN/v2/actions/executions' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
@@ -129,7 +129,7 @@ curl -L -X POST 'https://$CUSTOM-DOMAIN/v2/users/new' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
--data-raw '{
"organizationId": "336392597046099971",
"organizationId": "344648897353810062",
"human":
{
"profile":
@@ -143,7 +143,7 @@ curl -L -X POST 'https://$CUSTOM-DOMAIN/v2/users/new' \
},
"email":
{
"email": "[email protected]"
"email": "mini+test@mouse.com"
}
}
}'
@@ -155,46 +155,50 @@ The incoming request headers to the Execution are propagated via the request pay
```json
{
"fullMethod": "/zitadel.user.v2.UserService/CreateUser",
"instanceID": "336392597046034435",
"orgID": "336392597046099971",
"projectID": "336392597046165507",
"userID": "336392597046755331",
"request":
"fullMethod": "/zitadel.user.v2.UserService/CreateUser",
"instanceID": "344648897353744526",
"orgID": "344648897353810062",
"projectID": "344648897353875598",
"userID": "344648897354465422",
"request":
{
"organizationId": "344648897353810062",
"human":
{
"organizationId": "336392597046099971",
"human":
{
"profile":
{
"givenName": "Minnie",
"familyName": "Mouse",
"nickName": "Mini",
"displayName": "Minnie Mouse",
"preferredLanguage": "en",
"gender": "GENDER_FEMALE"
},
"email":
{
"email": "[email protected]"
}
}
},
"headers":
{
"Content-Type":
[
"application/grpc"
],
"Host":
[
"localhost:8080"
],
"X-Forwarded-Host":
[
"localhost:8080"
]
"profile":
{
"givenName": "Minnie",
"familyName": "Mouse",
"nickName": "Mini",
"displayName": "Minnie Mouse",
"preferredLanguage": "en",
"gender": "GENDER_FEMALE"
},
"email":
{
"email": "[email protected]"
}
}
},
"headers":
{
"Content-Type":
[
"application/grpc"
],
"Host":
[
"localhost:8080"
],
"X-Forwarded-For":
[
"::1"
],
"X-Forwarded-Host":
[
"localhost:8080"
]
}
}
```
@@ -144,7 +144,7 @@ target can be created as follows:
See [Create a target](/apis/resources/action_service_v2/action-service-create-target) for more detailed information.
```shell
curl -L -X POST 'https://$CUSTOM-DOMAIN/v2beta/actions/targets' \
curl -L -X POST 'https://$CUSTOM-DOMAIN/v2/actions/targets' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
@@ -168,7 +168,7 @@ we define an execution with a response condition.
See [Set an execution](/apis/resources/action_service_v2/action-service-set-execution) for more detailed information.
```shell
curl -L -X PUT 'https://$CUSTOM-DOMAIN/v2beta/actions/executions' \
curl -L -X PUT 'https://$CUSTOM-DOMAIN/v2/actions/executions' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
@@ -78,7 +78,7 @@ As you see in the example above the target is created with HTTP and port '8090'
See [Create a target](/apis/resources/action_service_v2/action-service-create-target) for more detailed information.
```shell
curl -L -X POST 'https://$CUSTOM-DOMAIN/v2beta/actions/targets' \
curl -L -X POST 'https://$CUSTOM-DOMAIN/v2/actions/targets' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
@@ -102,7 +102,7 @@ condition.
See [Set an execution](/apis/resources/action_service_v2/action-service-set-execution) for more detailed information.
```shell
curl -L -X PUT 'https://$CUSTOM-DOMAIN/v2beta/actions/executions' \
curl -L -X PUT 'https://$CUSTOM-DOMAIN/v2/actions/executions' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
@@ -129,7 +129,7 @@ curl -L -X POST 'https://$CUSTOM-DOMAIN/v2/users/new' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
--data-raw '{
"organizationId": "336392597046099971",
"organizationId": "344648897353810062",
"human":
{
"profile":
@@ -156,13 +156,13 @@ The incoming request headers to the Execution are propagated via the request pay
```json
{
"fullMethod": "/zitadel.user.v2.UserService/CreateUser",
"instanceID": "336392597046034435",
"orgID": "336392597046099971",
"projectID": "336392597046165507",
"userID": "336392597046755331",
"instanceID": "344648897353744526",
"orgID": "344648897353810062",
"projectID": "344648897353875598",
"userID": "344648897354465422",
"request":
{
"organizationId": "336392597046099971",
"organizationId": "344648897353810062",
"human":
{
"profile":
@@ -195,6 +195,10 @@ The incoming request headers to the Execution are propagated via the request pay
[
"localhost:8080"
],
"X-Forwarded-For":
[
"::1"
],
"X-Forwarded-Host":
[
"localhost:8080"
@@ -80,7 +80,7 @@ As shown in the example above, the target is created with HTTP and port '8090'.
See [Create a target](/apis/resources/action_service_v2/action-service-create-target) for more detailed information. Notice that the `endpoint` is your Webhook.site URL.
```shell
curl -L -X POST 'https://$CUSTOM-DOMAIN/v2beta/actions/targets' \
curl -L -X POST 'https://$CUSTOM-DOMAIN/v2/actions/targets' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
@@ -117,7 +117,7 @@ See [Set an execution](/apis/resources/action_service_v2/action-service-set-exec
Here, `<TargetID returned>` is the `id` from the previous step.
```shell
curl -L -X PUT 'https://$CUSTOM-DOMAIN/v2beta/actions/executions' \
curl -L -X PUT 'https://$CUSTOM-DOMAIN/v2/actions/executions' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \