Skip to content

Commit

Permalink
Merge pull request #198 from flotiq/23779-add-user-info-to-sync-webho…
Browse files Browse the repository at this point in the history
…oks-response

23779-add-user-info-to-sync-webhooks-response
  • Loading branch information
KarolNet authored Dec 5, 2023
2 parents e444292 + ef37a94 commit 0dae761
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions docs/panel/webhooks/sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: How to use synchronous webhooks in Flotiq
# Synchronous webhooks

!!! note
Flotiq synchronous webhooks can be customized in enterprise version only.
Flotiq synchronous webhooks can be customized in the enterprise version only.
Reach out to us to discuss possible implementation.

## What is a synchronous webhook?
Expand All @@ -15,15 +15,15 @@ Sync webhooks are executed in-band during Flotiq request processing on the follo
- PRE-UPDATE - before updating existing objects
- PRE-DELETE - before deleting existing objects.

When a sync webhook is registered - Flotiq backend will call out to an external service when you make an API call that would normally trigger a create, update or delete operation on your content. This external service can do one of 2 things:
When a sync webhook is registered - the Flotiq backend will call out to an external service when you make an API call that would normally trigger a create, update or delete operation on your content. This external service can do one of 2 things:

- modify the payload that was originally sent to Flotiq and pass it for further processing,
- stop the request from processing further.

We will call these 2 types of webhooks *mutating webhooks* and *validating webhooks* (after the [admission controller webhooks](https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/) in K8s which inspired this feature).

!!! Tip
From setup perspective both mutating and validating webhooks are handled exactly the same way. The only difference is in the response they return and the effect it has on further processing of the payload.
From a setup perspective both mutating and validating webhooks are handled exactly the same way. The only difference is in the response they return and the effect it has on further processing of the payload.

## Sync webhook payload

Expand All @@ -36,6 +36,12 @@ All sync webhooks generate a payload according to the following schema:
"event": "pre-create",
"sequenceNumber": 0,
"contentTypeName" : "ContentTypeName",
"userInfo": {
"id": "user's ID",
"firstName": "user's first name",
"lastName": "user's last name",
"apiKeyName": "name of the API key that triggered webhook (if there is one)"
},
"payload": {
... <-- this is the object that was originally sent to Flotiq
}
Expand All @@ -47,7 +53,7 @@ Flotiq backend will make sure to send this payload to the system you registered

There are many cases when the ability to modify data being received by Flotiq comes in handy, for example:

- generating slugs for webpages
- generating slugs for web pages
- calculating field values based on other fields
- populating object's fields with data from external sources

Expand All @@ -69,10 +75,10 @@ HTTP 200:

## Validating webhooks

Second use case for sync webhooks is external validation. In a similar way as with the mutating webhook - an external system receives payload from Flotiq. Once the system processes the object it can respond in 2 way:
The second use case for sync webhooks is external validation. In a similar way as with the mutating webhook - an external system receives payload from Flotiq. Once the system processes the object it can respond in 2 ways:

- with a `HTTP 200` response, without making changes to the object - this will result in processing the payload further in Flotiq,
- with a `HTTP 400` response, raising validation errors - this will stop processing in Flotiq.
- with an `HTTP 200` response, without making changes to the object - this will result in processing the payload further in Flotiq,
- with an `HTTP 400` response, raising validation errors - this will stop processing in Flotiq.

Example of a passed validation:

Expand Down Expand Up @@ -109,7 +115,7 @@ HTTP 400:
```

!!! Note
In case you register multiple webhooks for a single CTD - they will be process sequentially. There is no guarantee on the order of processing. All webhooks have to respond successfully in order for the object to be processed.
In case you register multiple webhooks for a single CTD - they will be processed sequentially. There is no guarantee on the order of processing. All webhooks have to respond successfully in order for the object to be processed.

![](../images/webhooks-lifecycle/WebhooksLifecycleDiagram.png){: .center .border}

Expand Down Expand Up @@ -137,4 +143,4 @@ In case the remote system fails to respond according to one of the formats descr
in such case please check the following:

1. Make sure the remote system is returning a proper `200` or `400` response, as described above.
2. Check remote system's logs to verify the cause of misbehaviour.
2. Check the remote system's logs to verify the cause of misbehavior.

0 comments on commit 0dae761

Please sign in to comment.