-
Notifications
You must be signed in to change notification settings - Fork 10
docs: enhance webhook documentation with response structure details a… #635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
5ebb4ec
da9ccf4
83f83a5
248806b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,7 +63,7 @@ For example, if you send a response like a below object | |
| } | ||
| ``` | ||
|
|
||
| > Please note that your webhook should always return a JSON object (not an array). | ||
| > Your webhook should return JSON. A JSON object is the simplest to work with, but arrays are also supported — see [How the response should be structured](#how-the-response-should-be-structured) below. | ||
|
|
||
| Then you can use that response as **@results.mywebhook.success_message** Or if you want to use any other variable then it will be **@results.mywebhook.*YOUR_RESPONSE_OBJECT_KEY** | ||
|
|
||
|
|
@@ -73,6 +73,60 @@ Then you can use that response as **@results.mywebhook.success_message** Or if y | |
|
|
||
| Here my webhook is a custom name you defined on your webhook node and **success_message** is the key of the response object you send back in a webhook call. | ||
|
|
||
| ## How the response should be structured | ||
|
|
||
| When your external API replies to a webhook call, Glific reads the **JSON body** of the response and saves it under your webhook's result name. A few rules decide what you can read back: | ||
|
|
||
| - **Return JSON.** Glific only parses JSON response bodies. If the body is not valid JSON, nothing is saved to the result and the call is logged as an error. | ||
| - **A JSON object is the cleanest choice.** Every key in the object becomes a value you can read with **@results.YOUR_WEBHOOK_NAME.KEY**. | ||
| - **Arrays are supported too.** If your API returns a JSON array, Glific turns it into numbered keys starting at `0` — the first item is `0`, the second is `1`, and so on. You then read an item by its number. | ||
| - **There is no fixed nesting limit.** Glific keeps the full shape of your JSON — objects inside objects, arrays inside objects — so you can reach any value by following its path. | ||
|
|
||
| ## Accessing nested values | ||
|
|
||
| You reach a value by writing its path after the webhook name, separating each level with a dot: | ||
|
|
||
| **@results.YOUR_WEBHOOK_NAME.LEVEL1.LEVEL2...** | ||
|
|
||
| Say your webhook is named **mywebhook** and your API returns this: | ||
|
|
||
| ```json | ||
| { | ||
| "status": "success", | ||
| "user": { | ||
| "name": "Anita", | ||
| "address": { | ||
| "city": "Mumbai", | ||
| "pincode": "400001" | ||
| } | ||
| }, | ||
| "courses": [ | ||
| { "title": "Maths", "score": 88 }, | ||
| { "title": "Science", "score": 92 } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| Here is how to read each value: | ||
|
|
||
| | You want | Use this | | ||
| |---|---| | ||
| | The status | `@results.mywebhook.status` | | ||
| | The user's name | `@results.mywebhook.user.name` | | ||
| | The user's city (object inside an object) | `@results.mywebhook.user.address.city` | | ||
| | The first course title (array → item `0`) | `@results.mywebhook.courses.0.title` | | ||
| | The second course's score | `@results.mywebhook.courses.1.score` | | ||
|
|
||
| A few things to keep in mind: | ||
|
|
||
| - **Array items are numbered from `0`.** The first item is always `0`, not `1`. | ||
| - **Match the keys exactly**, including upper- and lower-case. `@results.mywebhook.User.name` will not find `user`. | ||
| - **Check a value exists before you use it.** If a key is missing from the response, its path returns nothing. Use a **Wait for result** or a split node to branch on whether the value came back. | ||
|
|
||
|
Comment on lines
+117
to
+120
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify exact node type names in Glific documentation or codebase
rg -n "Wait for result" docs/
rg -n "split node" docs/
rg -n "Split by" docs/ --type mdRepository: glific/docs Length of output: 9250 Update the specific node name for handling missing values. While "Wait for result" is the correct node name, "split node" is too generic and does not match the Glific UI. The precise node for branching based on workflow results is Split by a result in the flow. Replace "split node" with "Split by a result in the flow" in the guidance:
🤖 Prompt for AI Agents |
||
| :::note | ||
| Want to confirm the exact shape your API returned? Open **Webhook Logs** (below) and view the **Response JSON** for that call. Copy the key names straight from there to build your paths. | ||
| ::: | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| ___ | ||
| ## Checking Webhook Logs | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win
Clarify what "nothing is saved" means for flow authors.
Line 80 states that invalid JSON means "nothing is saved to the result and the call is logged as an error." Consider clarifying whether the flow can still continue (with an empty result) or if the webhook node itself errors and stops flow execution. This distinction matters for authors designing error-handling paths.
🤖 Prompt for AI Agents