A condition is a container action holding branches: one IF, any number of ELSE IF, at most one ELSE. The first branch that matches runs the actions nested in it. A template branch matches when its template calls $result->setMatching(true). An entityEvent branch matches when the record that started the run meets criteria; with no criteria, or on a record of another type than entity, it matches too.
Conditions
If, else if and else branches inside a job. They are created here and read, changed and deleted as actions.
About conditions
Create a condition#
/cdna-api/hooks/condition/{hook.id}
Creates a condition at the top level of a job, with its IF branch, in one call. name names the container; the other fields are the branch.
- Access
- Admin users and integrations, with an OAuth access token or an API key.
- Returns
- The container under
data.condition, its IF branch underdata.conditionIf, and amessage.
Parameters
hook.idpathrequired- integer
- The job id.
retrieveUnpublishedquery- 1
- Needed while the job is unpublished, unless the admin shows unpublished records: without it the job is not found.
namebody- string
- The container’s name: letters, digits,
_and-only. conditionTypebody- string
template(the default) orentityEvent.templateCodebody- string
- For
template: matches only when it calls$result->setMatching(true). What it prints is ignored. entitybody- string
- For
entityEvent: the record class, such asPages\Entities\Page. criteriabody- string
- For
entityEvent: filters as JSON, decoded as they are, so not wrapped in{literal}.
A template condition matches only when its template calls $result->setMatching(true). Printing something, such as 1, does not count: the branch never runs, and nothing reports an error.
Example
POST /cdna-api/hooks/condition/12 HTTP/1.1
Host: hub.coredna.com
Authorization: Bearer YOUR_ACCESS_TOKEN
Accept: application/json
Content-Type: application/json
{
"name": "has-an-email",
"conditionType": "template",
"templateCode": "{if !empty($event->getRecord()->data['email'])}{$result->setMatching(true)}{/if}"
}Create a condition inside another action#
/cdna-api/hooks/condition/{hook.id}/{parent.id}
Creates a condition inside a Loop or another branch, with its IF branch.
- Access
- Admin users and integrations, with an OAuth access token or an API key.
- Returns
- The container under
data.condition, its IF branch underdata.conditionIf, and amessage.
Parameters
hook.idpathrequired- integer
- The job id.
parent.idpathrequired- integer
- The Loop or branch to nest it in.
retrieveUnpublishedquery- 1
- Needed while the job is unpublished, unless the admin shows unpublished records: without it the job is not found.
namebody- string
- The container’s name: letters, digits,
_and-only. conditionTypebody- string
template(the default) orentityEvent.templateCodebody- string
- For
template: matches only when it calls$result->setMatching(true). What it prints is ignored. entitybody- string
- For
entityEvent: the record class, such asPages\Entities\Page. criteriabody- string
- For
entityEvent: filters as JSON, decoded as they are, so not wrapped in{literal}.
A template condition matches only when its template calls $result->setMatching(true). Printing something, such as 1, does not count: the branch never runs, and nothing reports an error.
Example
POST /cdna-api/hooks/condition/12/9 HTTP/1.1
Host: hub.coredna.com
Authorization: Bearer YOUR_ACCESS_TOKEN
Accept: application/json
Content-Type: application/json
{
"name": "owner-has-an-email",
"conditionType": "template",
"templateCode": "{if !empty($event->getRecord()->data['email'])}{$result->setMatching(true)}{/if}"
}Add an ELSE IF branch#
/cdna-api/hooks/condition-else-if/{condition.id}
Adds an ELSE IF branch to a condition. The path takes the condition’s id, not the job’s.
- Access
- Admin users and integrations, with an OAuth access token or an API key.
- Returns
- The condition under
data.condition, the new branch underdata.conditionElseIf, and amessage.
Parameters
condition.idpathrequired- integer
- The condition container’s id.
conditionTypebody- string
template(the default) orentityEvent.templateCodebody- string
- For
template: matches only when it calls$result->setMatching(true). What it prints is ignored. entitybody- string
- For
entityEvent: the record class, such asPages\Entities\Page. criteriabody- string
- For
entityEvent: filters as JSON, decoded as they are, so not wrapped in{literal}.
A template condition matches only when its template calls $result->setMatching(true). Printing something, such as 1, does not count: the branch never runs, and nothing reports an error.
Example
POST /cdna-api/hooks/condition-else-if/40 HTTP/1.1
Host: hub.coredna.com
Authorization: Bearer YOUR_ACCESS_TOKEN
Accept: application/json
Content-Type: application/json
{
"conditionType": "template",
"templateCode": "{if !empty($event->getRecord()->data['phone'])}{$result->setMatching(true)}{/if}"
}Add the ELSE branch#
/cdna-api/hooks/condition-else/{condition.id}
Adds the ELSE branch, which always matches, to a condition. There is no body. A condition has at most one: a second call answers 409.
- Access
- Admin users and integrations, with an OAuth access token or an API key.
- Returns
- The condition under
data.condition, the new branch underdata.conditionElse, and amessage.
Parameters
condition.idpathrequired- integer
- The condition container’s id.
Example
POST /cdna-api/hooks/condition-else/40 HTTP/1.1
Host: hub.coredna.com
Authorization: Bearer YOUR_ACCESS_TOKEN
Accept: application/json