Skip to main content

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​

EnvironmentURL
Sandboxhttps://api.pre.cdpgreenstar.net/asp/response/questionnaire/clauses
Productionhttps://api.cdp.net/response/questionnaire/clauses

Parameters​

NameLocationDescription
subscription-keyheaderFor authorized user, the subscription key.
organization-idheaderEnter the UUID for the organization's response.

Response​

Clause (top level)​

FieldDescriptionData Type
idThe UUID for the clause/rule.string
messageNot in use.string
questionIdThe ID of the question the clause/rule applies to.string
rowIdThe ID of the row the clause/rule applies to.string
optionIdThe ID of the option the clause/rule applies to.string
questionAdditional question information if the question is within a matrix question.array
rowAdditional row information if the clause/rule applies to a specific row.array
conditionsArray list of the rules applied to the question/row/option.array
leadingQuestionIdThe 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.

FieldDescriptionData Type
parentQuestionIdThe parent question for the matrix question the rule applies to.string

Row (matrix only)​

Present only when the rule targets a specific row.

FieldDescriptionData Type
idThe row ID.string
complexQuestionIdThe question the row belongs to.string

Condition​

FieldDescriptionData Type
idIdentifier of this condition within the clause.string
rowIdThe row whose value the condition checks.string
clauseIdThe clause this condition belongs to.string
questionIdThe question whose value the condition checks.string
valueThe 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
operandThe comparison operator (see Operand values).string
logicalOperatorAND / OR, used to combine multiple conditions in a clause (see How conditions combine).string
indexPosition of the condition within the clause, starting at 0.integer

Operand values​

CodeMeaningExample in a questionnaire
eqequal toanswer is "Yes"
neqnot equal toanswer is "Not applicable"
ltless thanreported figure < 100
gtgreater thannumber of employees > 500
lteless than or equal torevenue ≤ a threshold
gtegreater than or equal toemissions ≥ 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):

indexlogicalOperatorcheck
0nullOwns vehicles = Yes
1ANDRegion = EU
2OROwns buildings = Yes
3ANDRegion = 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 OR starts 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 index before 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.