Logic API
Access control
Decide who may call each action and query with roles, user properties, authorization policies and preconditions.
Every action and query has an Access Control step with two parts. The Authorization Policy decides who may call it: anyone, signed-in users, or callers with certain roles. The Precondition decides when it may run, for example only while a case is open, or only for the caller’s own records. Both build on the caller information you define under Context.
Context: roles and user properties
Section titled “Context: roles and user properties”Roles let actions and queries allow only some callers, for example a Partner role for a partner portal, or a SalesManager role for approvals. Add them under Context > Roles with Add role and a Role Name. Role names must be unique.
API roles are names that your API uses; they are not Dataverse security roles. Which roles a caller holds is decided by the API host when the caller signs in, so agree the role names with the team that runs the host. See Install and host Logic API.
User properties
Section titled “User properties”User properties describe the caller, for access checks and filters, for example the customer number or the contact id of the signed-in user. Add them under Context > User with Add user property.
| Column | Meaning |
|---|---|
| Name | How preconditions and queries refer to the property. |
| Type | The property’s data type. |
| Is List | The property holds several values, such as the ids of the accounts a partner manages. |
| Queryable | The property can be used in query conditions. |
| Nullable | The property may be empty. |
| Description | What the property holds. |
Like roles, the values come from the API host when the caller signs in: its user resolver supplies them. A role or user property that is used anywhere in the API shows Used and cannot be deleted.
Authorization policy
Section titled “Authorization policy”- Open the action or query and go to the Access Control step.
- Under Authorization Policy, open Select Authorization Policy and choose a type.
- For Demand User Role, pick the role. For Demand Any or Demand All, select Add Policy for each policy in the group.
- Save.
| Policy | Who may call |
|---|---|
| Demand User Role | Only callers that hold the role you pick. |
| Demand Authenticated User | Any signed-in caller. |
| Demand Anonymous User | Only callers that are not signed in. |
| Demand Any | A group of policies. The caller must satisfy at least one of them. |
| Demand All | A group of policies. The caller must satisfy each and every one of them. |
Demand Any and Demand All are groups of policies, not lists of roles. Each policy in a group is a Demand User Role, Demand Authenticated User or Demand Anonymous User. For example:
- Demand Any with Demand User Role
SalesManagerand Demand User RoleFinanceApprover: either role may approve. - Demand All with Demand User Role
Partnerand Demand User RoleCertifiedInstaller: the caller needs both roles.
Endpoints without a policy are public
Section titled “Endpoints without a policy are public”Incomplete policies are errors
Section titled “Incomplete policies are errors”An authorization policy that has no type, or a Demand Any / Demand All group with no policies in it, is an error:
- API Studio reports it as an issue on the Access Control step, so you can’t publish the draft until it is fixed.
Precondition
Section titled “Precondition”The precondition is a condition that must be true for the call to go ahead. It can combine several checks with and / or, and can use the caller’s inputs, the results of the action’s Data Fetcher queries, and the caller’s user properties.
| Field | What it does |
|---|---|
| Condition | The check. When it is false, the call is refused. |
| Error Code | A code that identifies the failure for the caller, for example CREDIT_LIMIT_EXCEEDED. Callers receive it with status 400. If you leave it empty, callers receive CONDITION_VIOLATION. |
| Error Message | A message that explains the failure. Callers receive it with your error code. |
A precondition works with or without an authorization policy.
How it behaves
Section titled “How it behaves”For every call, in this order:
- The inputs are validated.
- The Data Fetcher queries run.
- The authorization policy is checked. If it fails, the caller gets
401withUNAUTHORIZAD_ACCESS(spelled this way in the product). - The precondition is checked. If it is false, the call is refused with status
400and your Error Code and Error Message (CONDITION_VIOLATIONand “API condition is not satisfied.” when Error Code is empty). - Only then does the action or query run.
See Responses and errors for what callers receive.
Access column in lists
Section titled “Access column in lists”| Access shows | Policy |
|---|---|
| Role | Demand User Role |
| Signed-in users | Demand Authenticated User |
| Signed-out users only | Demand Anonymous User |
| Any of several | Demand Any |
| All of several | Demand All |
| Anyone | No policy, so the endpoint is public |
Example: partners update only their own opportunities
Section titled “Example: partners update only their own opportunities”A partner portal lets partners update the estimated close date of opportunities they manage.
| Part | Setting |
|---|---|
| Role | Partner |
| User property | accountId (Unique Identifier): the partner’s account, supplied by the host at sign-in |
| Data Fetcher | Look up the opportunity’s partner account and status. |
| Authorization Policy | Demand User Role Partner |
| Precondition | The opportunity is open and its partner account equals the caller’s accountId; Error Code NOT_YOUR_OPPORTUNITY; Error Message “You can only update open opportunities of your own account.” |
A caller without the Partner role gets 401; a partner who tries to change another partner’s opportunity is refused by the precondition.