Conditional logic (clauses)
Overview
Clauses return the logic rules within a questionnaire and the conditions that make up the clause. A clause applies logic to a question, an option, or a row.
CDP questionnaires show or hide questions depending on the answers provided. This endpoint provides the reasoning behind the behavior. It doesn't ask anyone anything or store answers, it just describes the rules so you can apply them yourself.
Three words to know:
- Clause: One rule attached to a question (or to a single row or answer option). In effect: "only show this question when such-and-such is true."
- Condition: A single check inside a rule, e.g. "Did they answer Yes to Question 1?"
- Logical operator (AND / OR): how multiple checks in the same rule are glued together.
The following example is for an environmental survey and explains how the conditional logic works:
Q1. Does your organization own vehicles? (Yes / No) Q2. What fuel do your vehicles use? (only relevant if Q1 = Yes)
The clause for Q2 holds one condition: "Q1 equals Yes." If someone answers No to Q1, the rule isn't satisfied and Q2 stays hidden. Consumers of this endpoint can take an organization's real answers, run them through these rules, and decide which questions belong on screen.
Pre-requisites: A valid subscription key and the organization UUID for the relevant Disclosure API environment.
Scope of the response: Unlike most endpoints, this response is not filtered by Tag Matching. The complete set of clauses and conditions for the entire questionnaire is returned on every call, whether or not each rule is relevant to the supplied organization.
Visibility vs. conditional logic: Conditional logic (clauses) controls the questionnaire based on answers given to earlier questions. Whether a question is actually shown to an organization is a separate, runtime concern handled by Tag Matching on the organization's tags — see the API Overview. This endpoint returns rule definitions only; it does not return a live "visible/hidden" flag.
Terminology: A condition that "checks the value of" a question / option / row is comparing the answer value of that item against the condition's rule.
Endpoints
| Environment | URL |
|---|---|
| Sandbox | https://api.pre.cdpgreenstar.net/asp/response/questionnaire/clauses |
| Production | https://api.cdp.net/response/questionnaire/clauses |
Parameters
| Name | Location | Description |
|---|---|---|
subscription-key | header | For authorized user, the subscription key. |
organization-id | header | Enter the UUID for the organization's response. |
Response
Clause (top level)
| Field | Description | Data Type |
|---|---|---|
id | The UUID for the clause/rule. | string |
message | Not in use. | string |
questionId | The ID of the question the clause/rule applies to. | string |
rowId | The ID of the row the clause/rule applies to. | string |
optionId | The ID of the option the clause/rule applies to. | string |
question | Additional question information if the question is within a matrix question. | array |
row | Additional row information if the clause/rule applies to a specific row. | array |
conditions | Array list of the rules applied to the question/row/option. | array |
leadingQuestionId | The parent question ID of the question the clause/rule applies to. | string |
A clause can target three levels of granularity:
- A whole question: "Show Q2 if Q1 = Yes."
- A single answer option (
optionId): "Show the 'other details' box only if the 'Other' option is chosen." - A single row of a matrix question (
rowId): "In the per-site emissions table, only show the 'flaring' row for sites that report oil & gas activity."
Question (matrix only)
Present only when the target question is part of a matrix question.
| Field | Description | Data Type |
|---|---|---|
parentQuestionId | The parent question for the matrix question the rule applies to. | string |
Row (matrix only)
Present only when the rule targets a specific row.
| Field | Description | Data Type |
|---|---|---|
id | The row ID. | string |
complexQuestionId | The question the row belongs to. | string |
Condition
| Field | Description | Data Type |
|---|---|---|
id | Identifier of this condition within the clause. | string |
rowId | The row whose value the condition checks. | string |
clauseId | The clause this condition belongs to. | string |
questionId | The question whose value the condition checks. | string |
value | The value the user's answer is compared against. May be an option ID rather than a literal value, and may be a JSON-encoded array string, e.g. "[\"bd1d8283-1b6d-4b6a-99eb-f944fcb81c24\"]". | string |
operand | The comparison operator (see Operand values). | string |
logicalOperator | AND / OR, used to combine multiple conditions in a clause (see How conditions combine). | string |
index | Position of the condition within the clause, starting at 0. | integer |
Operand values
| Code | Meaning | Example in a questionnaire |
|---|---|---|
eq | equal to | answer is "Yes" |
neq | not equal to | answer is "Not applicable" |
lt | less than | reported figure < 100 |
gt | greater than | number of employees > 500 |
lte | less than or equal to | revenue ≤ a threshold |
gte | greater than or equal to | emissions ≥ a threshold |
Tip – Value is usually an ID, not a label. For multiple-choice questions, the condition compares against the chosen option's ID, not its display text. So a rule meaning "if the respondent selected the EU region" stores the EU option's UUID in
value(often inside a JSON-encoded array), not the word "EU". When you replicate the logic, match on option IDs.
How conditions combine
When a clause has more than one condition, logicalOperator and index together determine the overall result. Conditions are evaluated in index order (ascending, starting at 0) and combined using this rule:
OR – starts a new group
Anything else — AND, null, or any value that is not exactly OR — folds the condition into the current group with logical AND.
The clause is satisfied if any group is satisfied.
In other words, runs of AND-connected conditions form groups, and those groups are OR'd together — groups of AND conditions, joined to one another by OR. The first condition (index: 0) always opens the first group; its logicalOperator is effectively ignored, which is why it is commonly null.
AND – every check must pass
Show Q2 (fuel type) only if the company owns vehicles and operates in the EU.
(Q1 = Yes) AND (Region = EU)
Both conditions sit in the same group, so the question appears only when both are true.
OR – any check can pass
Show Q5 (asset disclosures) if the company owns vehicles or owns buildings.
(Owns vehicles = Yes) OR (Owns buildings = Yes)
The two conditions are in separate groups, so the question appears if either is true.
Mixed – groups of ANDs joined by OR
The ANDs clump together first, then the ORs split things into separate "either/or" bundles. A clause whose conditions read (in index order):
| index | logicalOperator | check |
|---|---|---|
| 0 | null | Owns vehicles = Yes |
| 1 | AND | Region = EU |
| 2 | OR | Owns buildings = Yes |
| 3 | AND | Region = EU |
…evaluates as:
(Owns vehicles = Yes AND Region = EU) OR (Owns buildings = Yes AND Region = EU)
The question shows if either complete bundle is satisfied — i.e. an EU company that owns vehicles, or an EU company that owns buildings.
Note on implementation
- The OR match is exact and case-sensitive. Only the literal string
ORstarts a new group. Any other value —or,Or, surrounding whitespace,null, or a typo — is treated as AND. Validate operator values if you replicate the logic. - Order by index. Don't rely on array order; sort conditions by
indexbefore evaluating. - Treat a not-applicable question as false. A question that isn't shown to the organization can't satisfy a dependency. Whether a question is shown depends on runtime visibility (Tag Matching and the evaluated logic), not on any field in this payload.
Reading a clause end to end
Putting it together for the "EU companies that own vehicles" rule, a single clause might look like this (IDs shortened for readability):
{
"id": "clause-001",
"questionId": "q2-fuel-type",
"rowId": null,
"optionId": null,
"conditions": [
{
"id": "cond-a",
"questionId": "q1-owns-vehicles",
"value": "[\"opt-yes\"]",
"operand": "eq",
"logicalOperator": null,
"index": 0
},
{
"id": "cond-b",
"questionId": "q-region",
"value": "[\"opt-eu\"]",
"operand": "eq",
"logicalOperator": "AND",
"index": 0
}
],
"leadingQuestionId": "q1-owns-vehicles"
}
How to read it: "Show q2-fuel-type when the answer to q1-owns-vehicles is the option opt-yes and the answer to q-region is the option opt-eu." Note the comparison is against option IDs, not labels, and the conditions are read in index order.
JSON response example
Below is an example API response while calling the GET method for this endpoint. The data retrieved are the list of associated organizations. If organization ID is entered, the tagging information of that organization will also be displayed.
[
{
"id": "036c1b6c-8c22-49a1-99b1-e4dd60749540",
"message": null,
"questionId": "574e8ffa-4202-423e-a501-db1df4b6e188",
"rowId": "addfa0b0-4ef5-4599-86dd-9f2976c31f95",
"optionId": null,
"question": {
"parentQuestionId": "1491b888-7468-4c3a-a4bb-d09bd3a714b7"
},
"row": {
"id": "addfa0b0-4ef5-4599-86dd-9f2976c31f95",
"complexQuestionId": "1491b888-7468-4c3a-a4bb-d09bd3a714b7"
},
"conditions": [
{
"id": "c9bc6b9a-dd91-4c5c-a51c-c5a6ec316de7",
"rowId": null,
"clauseId": "036c1b6c-8c22-49a1-99b1-e4dd60749540",
"questionId": "string",
"value": "[\"bd1d8283-1b6d-4b6a-99eb-f944fcb81c24\"]",
"operand": "eq",
"logicalOperator": null,
"index": 1
}
],
"leadingQuestionId": "1491b888-7468-4c3a-a4bb-d09bd3a714b7"
}
]
Error handling
1. Invalid subscription key
{
"message": "Invalid subscription key",
"name": "Unauthorized",
"link": 401
}
2. Invalid organization ID
{
"message": "Invalid organization id",
"name": "Unauthorized",
"link": 401
}
Unsupported methods
POST, PUT, and DELETE are not implemented for this endpoint. A questionnaire's conditional logic cannot be modified through the API.