API Explorer 936 endpoints

Explain Dynamic Query

POST /obp/v7.0.0/management/dynamic-resource-docs/explain

OBPv7.0.0-explainDynamicQuery Roles: CanCreateDynamicResourceDoc Dynamic-Resource-DocDynamic

Explains how a Dynamic Query (a Dynamic Resource Doc whose programming_lang is Query) would be answered, without reading any record, so its author can check that the SQL is sane and that the access rules are the ones they expect.

Send the URL-encoded declaration as method_body, as in a Dynamic Resource Doc. Optionally:

  • bank_id: the Dynamic Entity space to explain it in, a bank id or SYS. The system space when absent.
  • caller_parameters: the parameters a caller would add, as a query string, such as obp_sort_by=name&obp_limit=10.
  • as_anonymous_caller: true to explain it for a caller who is not logged in, rather than for you.

The answer has two parts.

steps are the reads the query would make, in order: the page, its count when the envelope names one, then each join. Each step says whether it goes through the query projection (with its SQL, every value shown as ?), through the Dynamic Entity record provider (described in words: OBP does not build that SQL), or reuses an earlier step's records. The SQL comes from the same code that builds the statements a call runs, so it cannot differ from them.

entities, restricted_fields, rules, caller_may_run and refusal describe access: every Dynamic Entity the query reads, with the Role that grants read access and whether the explained caller can read it; every read-restricted field it returns, copies, filters, sorts or picks by; the rules every Dynamic Query applies; and, when the caller could not run it, the exact refusal they would get (OBP-40066 or OBP-40065).

A declaration that is not valid is answered with OBP-40065, as Check would answer it. See the Glossary entry Dynamic Query.

User Authentication is Required. The User must be logged in. The Application must also be authenticated.

JSON request body fields (3)
method_body
method_body
as_anonymous_caller
as_anonymous_caller
caller_parameters
caller_parameters
JSON response body fields (20)
backend
backend
bank_id
gh.29.uk
caller_may_read
caller_may_read
caller_may_run
caller_may_run
entities
entities
entity
entity
explained_for
explained_for
notes
notes
public_access
public_access
purpose
DEVELOPER
read_role
read_role
restricted_fields
restricted_fields
row_level_access
row_level_access
rules
rules
space
space
step
step
steps
steps
parameter_count
parameter_count
refusal
refusal
sql
sql
Example request body
{
  "method_body": "%7B%22from%22%3A%22activity%22%2C%22where%22%3A%7B%22city%22%3A%22eq%3ABerlin%22%7D%2C%22join%22%3A%5B%7B%22entity%22%3A%22certificate%22%2C%22on%22%3A%22activity_id%22%2C%22cardinality%22%3A%22exists%22%2C%22as%22%3A%22certified%22%7D%5D%2C%22envelope%22%3A%7B%22rows%22%3A%22activities%22%2C%22count%22%3A%22count%22%7D%7D",
  "caller_parameters": "obp_sort_by=name&obp_limit=10",
  "as_anonymous_caller": false
}
Example success response
{
  "space": "SYS",
  "explained_for": "user 9ca9a7e4-6d02-40e3-a129-0b2bf89de9b1",
  "caller_may_run": false,
  "refusal": "OBP-40066: This Dynamic Query reads Dynamic Entities you may not read: certificate (needs CanGetDynamicEntityRecord_certificate at bank SYS).",
  "entities": [
    {
      "entity": "activity",
      "read_role": "CanGetDynamicEntityRecord_activity",
      "bank_id": "SYS",
      "public_access": true,
      "row_level_access": false,
      "caller_may_read": true
    },
    {
      "entity": "certificate",
      "read_role": "CanGetDynamicEntityRecord_certificate",
      "bank_id": "SYS",
      "public_access": false,
      "row_level_access": false,
      "caller_may_read": false
    }
  ],
  "restricted_fields": [],
  "rules": [
    "Only shared records are used, never a User's personal records, whoever owns them."
  ],
  "steps": [
    {
      "step": 1,
      "purpose": "Read the page of 'activity'",
      "backend": "projection",
      "sql": "SELECT d.datajson FROM de_activity_ad1db27dae39 p JOIN dynamicdata d ON d.dynamicdataid = p.data_id WHERE d.dynamicentityname = ? AND d.bankid = ? AND d.ispersonalentity = ? AND p.c_city_11a62c23412b = CAST( ? AS text ) ORDER BY p.c_name_82a3537ff0db ASC LIMIT ?",
      "parameter_count": 5,
      "notes": [
        "Filters and the sort run on the projection's indexed columns; only the records of the page are read."
      ]
    },
    {
      "step": 2,
      "purpose": "Join 1: 'certificate' records whose 'activity_id' names the 'activity' (reverse)",
      "backend": "record provider",
      "notes": [
        "Cardinality exists."
      ]
    }
  ]
}
Possible errors (5)
  • OBP-20001: User not logged in. Authentication is required!
  • OBP-10001: Incorrect json format.
  • OBP-20006: User is missing one or more roles:
  • OBP-40065: The Dynamic Query cannot be run as written.
  • OBP-50000: Unknown Error.
Implemented by OBPv7.0.0 explainDynamicQuery