-
Notifications
You must be signed in to change notification settings - Fork 427
Improve resultSelector documentation for Data Source Bindings #1348
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: master
Are you sure you want to change the base?
Changes from all commits
ac0650a
a437d51
77dc40f
0dd7b9d
52416b0
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 |
|---|---|---|
|
|
@@ -56,18 +56,119 @@ URL can also include variables that correspond to other task inputs. Variable va | |
| } | ||
| ``` | ||
|
|
||
| In addition to defining the URL for the data source, a `resultSelector` can also be defined. In the example above, result selector is a JSON PATH query which gets applied on each of the elements in the the REST API response data. | ||
| In addition to defining the URL for the data source, a `resultSelector` can also be defined. The result selector tells the system how to extract the required data from the API response. | ||
|
|
||
| Result selector can also be an XPATH query. For e.g. *Azure Classic* endpoint type supports data sources that use XPATH query. | ||
| ### resultSelector Reference | ||
|
|
||
| The `resultSelector` value must start with one of the following prefixes : | ||
|
|
||
| | Prefix | Description | | ||
| |--------|-------------| | ||
| | `jsonpath:` | Used to extract data from JSON responses | | ||
| | `xpath:` | Used to extract data from XML responses | | ||
| | `none` | Returns no data | | ||
| | `plaintext` | Returns the full response as plain text | | ||
|
|
||
| #### JSONPath (`jsonpath:`) | ||
|
|
||
| Use `jsonpath:` when the API response is in JSON format. | ||
|
|
||
| **Common syntax :** | ||
|
|
||
| | Pattern | Description | Example | | ||
| |---------|-------------|---------| | ||
| | `$` | Root object | `jsonpath:$` | | ||
| | `.property` | Access a property | `jsonpath:$.value` | | ||
| | `..property` | Search recursively | `jsonpath:$..name` | | ||
| | `[*]` | All items in an array | `jsonpath:$.value[*].id` | | ||
| | `[n]` | Specific item in array | `jsonpath:$.value[0]` | | ||
| | `[n,m]` | Multiple items | `jsonpath:$.value[0,1]` | | ||
| | `[start:end]` | Range of items | `jsonpath:$.value[0:3]` | | ||
| | `[?()]` | Filter condition | `jsonpath:$.value[?(@.properties.isEnabled == true)]` | | ||
|
|
||
| **Examples :** | ||
|
|
||
| Gets all `id` values from the array : | ||
| ``` | ||
| "resultSelector": "jsonpath:$.value[*].id" | ||
| ``` | ||
|
|
||
| Gets all `name` fields from anywhere in the response : | ||
| ``` | ||
| "resultSelector": "jsonpath:$..name" | ||
| ``` | ||
|
|
||
| Gets only items where `isEnabled` is `true` : | ||
| ``` | ||
| "resultSelector": "jsonpath:$.value[?(@.properties.isEnabled == true)]" | ||
| ``` | ||
|
|
||
| Returns the full JSON response : | ||
| ``` | ||
| "resultSelector": "jsonpath:$" | ||
| ``` | ||
|
|
||
| **Notes :** | ||
| - Keep JSONPath expressions simple and easy to understand. | ||
|
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. Vague notes section — These three bullet points under JSONPath Notes are low-signal: Maybe we should do it more like this: "The implementation uses Newtonsoft.Json JToken.SelectTokens, which supports most standard JSONPath operators but not script expressions ([?(@.length-1)])." |
||
| - If something doesn't work, check the API response structure. | ||
| - Some advanced JSONPath features may not be supported. | ||
|
|
||
| **Common limitation :** | ||
|
|
||
| Sometimes the API response uses property names as keys rather than returning an array. For e.g. the Variable Groups API returns variables in this format : | ||
|
|
||
| ``` | ||
| { | ||
| "name": "AzureWebSiteNames", | ||
| "endpointUrl": "$(endpoint.url)/$(endpoint.subscriptionId)/services/webspaces/$(WebSiteLocation)Webspace/sites", | ||
| "resultSelector": "xpath://Site/Name" | ||
| "variables": { | ||
| "MyVar1": { "value": "hello" }, | ||
| "MyVar2": { "value": "world" } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| In this case : | ||
| - You cannot directly extract the keys like `MyVar1`, `MyVar2` using `resultSelector`. | ||
| - You can only extract the property values. | ||
| - Enter values manually, or use `resultTemplate` to format the output. | ||
|
|
||
| #### XPath (`xpath:`) | ||
|
|
||
| Use `xpath:` when the API response is in XML format. Standard XPath syntax is supported. | ||
|
|
||
| **Examples :** | ||
|
|
||
| Selects all `Name` elements under `Site` : | ||
| ``` | ||
| "resultSelector": "xpath://Site/Name" | ||
| ``` | ||
|
|
||
| Selects multiple element types : | ||
| ``` | ||
| "resultSelector": "xpath://Blobs/Blob | //Blobs/BlobPrefix" | ||
| ``` | ||
|
|
||
| **Notes :** | ||
| - Standard XPath syntax is supported. | ||
| - You usually don't need to worry about XML namespaces — they are automatically handled. | ||
|
|
||
| #### Other selector types | ||
|
|
||
| **`none` :** | ||
| ``` | ||
| "resultSelector": "none" | ||
| ``` | ||
| Use when you don't need any data from the response (e.g., for write-only REST calls). | ||
|
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. instead of write-only rest calls - maybe would be better ""(e.g., for POST/PUT calls where only the status code matters)." |
||
|
|
||
| **`plaintext` :** | ||
| ``` | ||
| "resultSelector": "plaintext" | ||
| ``` | ||
| Returns the full response as plain text. | ||
|
|
||
| ### Response size limits | ||
|
|
||
| The API response should be less than **2 MB**. If it is too large, the request will fail. Use filtering or pagination in your API calls to reduce the response size. | ||
|
|
||
| ## Data source bindings | ||
|
|
||
| In order to refer to data sources defined by endpoint type in tasks, data source bindings are used. For e.g. *AzureRmWebAppDeployment* task defines data source binding referring to the above data source : | ||
|
|
||
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.
replace with "Returns no data from the response"