Write your first policy

Give a bookkeeper billing and nothing else, limit a shift to the morning, take one thing away with a deny, then ask why and preview a change first.

8 min readEdit this page
On this page

The policies Flowion provides cover the common cases. When they don't fit, write your own: a permission policy that allows exactly the permissions you name, for the hours you choose, and nothing else. Then give it to a member the way you would give them any policy, and ask the API why they can or can't do something.

This page makes three: a bookkeeper who sees and manages billing and nothing else, a morning shift that can send commands to chargers only on weekdays, and a deny that takes one thing away. For how policies, bindings and the provided policies fit together, read Permissions and policies first.

Before you start

  • You need identity.policy.manage. The Owner holds it. Nobody else does until an Owner gives it to them, and a deny can never take it away from an Owner.

  • A policy can only allow what you hold. To write a policy that allows billing.account.manage, you must hold it yourself, in this organization. A policy that goes further is refused with permission_policy.not_grantable. Every example below is for an Owner.

  • Permission names are exact. There are no wildcards, so a policy never gains a permission by accident when a new one is added. Read the names from List permissions.

  • $MEMBER is the membership id from GET /organizations/$ORG/members, not the user id.

Give a bookkeeper billing and nothing else

A policy is a name and a document. The document is version 1 and a list of statements. Each statement says allow or deny and names the permissions it covers.

POST/v1/organizations/$ORG/permission-policiesbash
curl -X POST "$API/organizations/$ORG/permission-policies" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Bookkeeper",
    "document": {
      "version": 1,
      "statements": [
        {
          "effect": "allow",
          "permissions": ["billing.account.read", "billing.account.manage"]
        }
      ]
    }
  }'
200Response
{
  "id": "5d0c8a62-1f3e-4b7a-9c41-2e8f6a0b7d13",
  "name": "Bookkeeper",
  "kind": "custom",
  "version": 1,
  "permissions": ["billing.account.manage", "billing.account.read"],
  "document": {
    "version": 1,
    "statements": [
      {
        "effect": "allow",
        "permissions": ["billing.account.read", "billing.account.manage"]
      }
    ]
  },
  "createdAt": "2026-10-04T08:12:31Z",
  "updatedAt": "2026-10-04T08:12:31Z"
}

Keep the id: it is the policyId you give to a member.

POST/v1/organizations/$ORG/members/$MEMBER/bindingsbash
curl -X POST "$API/organizations/$ORG/members/$MEMBER/bindings" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"policyId": "'"$BOOKKEEPER_POLICY"'"}'

Leaving out projectId gives the policy across the whole organization, which is where billing lives. The bookkeeper still holds what every member holds, and can now see and manage the organization's billing. They can't invite people, make API keys or touch a charger, because nothing allows it. Nothing is allowed unless a policy says so.

Change your mind later with Replace a permission policy. The version goes up and everyone who holds the policy holds the new document on their very next request.

If someone else may be editing the same policy, send the version you read as expectedVersion. When the policy has changed since, nothing is written and the answer is 409 with permission_policy.stale: read it again and retry. Without expectedVersion the write simply replaces what is there.

PUT/v1/organizations/$ORG/permission-policies/$BOOKKEEPER_POLICYbash
curl -X PUT "$API/organizations/$ORG/permission-policies/$BOOKKEEPER_POLICY" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Bookkeeper",
    "expectedVersion": 1,
    "document": {
      "version": 1,
      "statements": [
        {
          "effect": "allow",
          "permissions": ["billing.account.read"]
        }
      ]
    }
  }'

To see who holds a policy before you change it, read List who holds a permission policy. Each policy also carries a holders count by kind (members, apiKeys, invitations, other and their total), which counts people and keys once however many places they hold it. The holders list has a row for every place, so a member who holds the policy in two projects appears twice there.

Ask why: explain

Don't guess what a member can do. Ask. Explain runs the same code that answers every request, so it can't disagree with what really happens. It needs identity.policy.explain.

POST/v1/organizations/$ORG/permission-policies/explainbash
curl -X POST "$API/organizations/$ORG/permission-policies/explain" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"memberId": "'"$MEMBER"'", "permission": "billing.account.manage"}'
200Response
{
  "permission": "billing.account.manage",
  "resource": {
    "organizationId": "9b2e4c10-7a35-4d68-8f21-3c5d0e6a1b94",
    "mode": "live"
  },
  "verdict": "allow",
  "reason": "allowed",
  "decidedBy": {
    "policy": {
      "id": "5d0c8a62-1f3e-4b7a-9c41-2e8f6a0b7d13",
      "name": "Bookkeeper",
      "version": 1
    },
    "node": { "kind": "organization", "id": "9b2e4c10-7a35-4d68-8f21-3c5d0e6a1b94" },
    "statementIndex": 0,
    "effect": "allow"
  },
  "considered": [
    {
      "policy": {
        "id": "5d0c8a62-1f3e-4b7a-9c41-2e8f6a0b7d13",
        "name": "Bookkeeper",
        "version": 1
      },
      "node": { "kind": "organization", "id": "9b2e4c10-7a35-4d68-8f21-3c5d0e6a1b94" },
      "skippedForMode": false,
      "readable": true,
      "statements": [
        { "index": 0, "effect": "allow", "matched": true, "ignoredOwnerFloor": false }
      ],
      "warnings": [],
      "narrowsAssistant": false
    }
  ],
  "warnings": []
}

(considered is shortened here: it also lists every other policy the member holds.) Read it in this order:

  • verdict is allow or refuse.

  • reason says why. allowed and denied name a statement. For a refusal, no-allow-found means no policy allows it. The others are listed in Errors, pagination and versioning.

  • decidedBy is the statement that decided: which policy, at which organization or project, and the statement's position (statementIndex counts from 0). It is absent when nothing decided, because nothing allowed it.

  • considered is every policy that applied, with each statement and, for one that didn't match, the condition that stopped it: permission, mode, timeWindow or attributes.

Ask about something the bookkeeper may not do and you get the other half:

POST/v1/organizations/$ORG/permission-policies/explainbash
curl -X POST "$API/organizations/$ORG/permission-policies/explain" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"memberId": "'"$MEMBER"'", "permission": "identity.apikey.manage"}'

The answer is "verdict": "refuse" and "reason": "no-allow-found", with no decidedBy. Add "projectId" to ask about one project, "mode": "sandbox" to ask about sandbox, and "actingAs": "assistant" to ask about the member's assistant, which can do no more than the member and no more than read.

Limit a policy to a time of day

Add conditions to a statement to say when it applies. This morning shift can read and send commands to chargers (which includes starting and stopping a charge) from 06:00 to 11:00 on weekdays, on Stockholm time:

POST/v1/organizations/$ORG/permission-policiesbash
curl -X POST "$API/organizations/$ORG/permission-policies" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Morning shift",
    "document": {
      "version": 1,
      "statements": [
        {
          "effect": "allow",
          "permissions": ["ocpp.command.read", "ocpp.command.send"],
          "conditions": {
            "time_window": {
              "days": ["mon", "tue", "wed", "thu", "fri"],
              "from": "06:00",
              "to": "11:00",
              "zone": "Europe/Stockholm"
            }
          }
        }
      ]
    }
  }'

Give it at one project, so the shift reaches that location and no other:

POST/v1/organizations/$ORG/members/$MEMBER/bindingsbash
curl -X POST "$API/organizations/$ORG/members/$MEMBER/bindings" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"policyId": "'"$SHIFT_POLICY"'", "projectId": "'"$PROJECT"'"}'

What a condition means:

ConditionRule
time_windowdays are mon to sun, from and to are HH:MM on a 24-hour clock, and zone is an IANA zone name and always required, so a window never depends on where Flowion's servers are. It is read on Flowion's clock at the moment of the request. A from later than to runs past midnight, and belongs to the day it starts on
modelive, sandbox or both. Without it a statement applies in live only: add "mode": ["live", "sandbox"] to cover your sandbox too
attributesLimits a statement to named project_id, location_id or charger_id values. Flowion fills these in from the resource the request is about; a request cannot supply them

Every condition in a statement must hold. There is no "or" inside a statement; write two statements instead.

Ask at 14:00 on a Tuesday and explain shows exactly what stopped it:

json
{
  "verdict": "refuse",
  "reason": "no-allow-found",
  "considered": [
    {
      "policy": { "name": "Morning shift", "version": 1 },
      "statements": [
        { "index": 0, "effect": "allow", "matched": false, "failedCondition": "timeWindow", "ignoredOwnerFloor": false }
      ]
    }
  ]
}

(Shortened to the relevant fields.)

Take something away with a deny

A deny beats any allow, from any policy, at the organization or in a project. Use one to keep a single permission away from someone who otherwise holds a lot:

POST/v1/organizations/$ORG/permission-policiesbash
curl -X POST "$API/organizations/$ORG/permission-policies" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "No key management",
    "document": {
      "version": 1,
      "statements": [
        { "effect": "deny", "permissions": ["identity.apikey.manage"] }
      ]
    }
  }'

Writing a policy that denies, and giving one, each needs identity.policy.deny as well, a separate right that only the Owner holds until they give it out. A deny can't name the few permissions only a transfer of ownership can move, such as identity.binding.manage: that is refused with permission_policy.deny_on_owner_floor, so an organization can't lock itself out of its own access.

Preview a change: simulate

Before you give or take a policy, see what it would change. Simulate decides every permission twice, under what the member holds now and under what they would hold, and returns the difference. It changes nothing.

POST/v1/organizations/$ORG/permission-policies/simulatebash
curl -X POST "$API/organizations/$ORG/permission-policies/simulate" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "memberId": "'"$MEMBER"'",
    "add": [{"policyId": "'"$BOOKKEEPER_POLICY"'"}]
  }'
200Response
{
  "gained": ["billing.account.manage", "billing.account.read"],
  "lost": []
}

To preview taking something away, send the removeBindingIds you read from GET /organizations/$ORG/members/$MEMBER/bindings. Add projectId to evaluate at a project, and mode for sandbox. Conditions are weighed at the moment you ask, so a window that is closed now gains nothing yet.

To preview an edit before you save it, send replace, a list of { "policyId": ..., "document": ... } drafts of your own policies. Wherever the member holds that policy, the draft is used in place of the stored document. A draft is checked as a write would be and refused with the same codes, and nothing is stored.

POST/v1/organizations/$ORG/permission-policies/simulatebash
curl -X POST "$API/organizations/$ORG/permission-policies/simulate" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "memberId": "'"$MEMBER"'",
    "replace": [
      {
        "policyId": "'"$BOOKKEEPER_POLICY"'",
        "document": {
          "version": 1,
          "statements": [
            { "effect": "allow", "permissions": ["billing.account.read"] }
          ]
        }
      }
    ]
  }'

The answer is the same gained and lost. Here it lists billing.account.manage under lost, which is what saving the draft would take from a bookkeeper who holds the policy now.

Do the same in the console

Everything above is also a page. In the console, open the organization's settings, then Access, then the Policies tab. You need identity.policy.read to see it and identity.policy.manage to change anything on it; without the second the editor opens read-only.

The list shows every policy with who holds it, as counts from holders, and marks the ones that contain a deny. A policy Flowion provides can be read and used as a starting point but not edited. A policy nobody holds can be deleted; one that is held cannot, and the list shows how many hold it.

New policy opens the editor. It is made of a few pieces:

  • Name, and Start from to copy a provided policy or one of your own.

  • Statements. Each has an allow or deny switch, a permission picker and conditions. The picker is a searchable list grouped by area. Every permission shows its description, the lowest provided policy that includes it (lowestBundle), and a mark when holding it makes an account need extra sign-in protection (privileged). A permission you don't hold yourself can't be ticked, and the picker says why.

  • Conditions are rows you add: mode, days and hours in a time zone, or a project, location or charger. Every row in a statement must hold, and the rows are joined by the word "and". For an "or", add a second statement.

  • In plain words is the policy read back as sentences, so you can check it says what you meant.

  • Checks are the rules the server would apply, shown before you send anything, in the server's own words.

A new policy is saved from the editor. A change to an existing one goes through a review first, because everyone who holds it has the new version on their very next request:

  • What changes lists the lines added and removed, compared with the version stored now. A draft is compared with the current version only: there is no history of earlier versions to compare with or go back to.

  • Who this applies to lists the holders and, for each, what they would gain and lose. That is simulate with replace, so it is the server's own decision and cannot disagree with what happens after you save.

  • Save sends the version you read as expectedVersion. If someone else saved first, nothing is written, your draft is kept and the review is shown again against the new current version.

Give a policy to someone

On the Access page, Change on a member or key row (or Invite member) opens the grant panel: who, which policies, and where, either across the organization or in one project. As you choose, the panel shows what the grant would add or take away. Again that is simulate, so it is the server's answer for exactly the choice on screen. For an invitation, which holds nothing yet, it lists what they will hold once they accept. Nothing changes until you press Grant.

Ask why: the troubleshooter

The Troubleshoot tab is explain with a form: pick a member or key and a permission, and optionally a project, a mode, or the member's assistant. It shows the verdict, then every policy that was weighed and the statement that decided, and for a statement that didn't match, the condition that stopped it. Where it can, it links to the closest fix, such as the policy to edit or a grant to make. It never changes anything itself.

You don't have to start from the tab. A refused action in the console offers Why was this refused?, and each member row offers Why can't they…; both open the troubleshooter with the question filled in. It needs identity.policy.explain.

When a policy is refused

A write that breaks a rule is refused with a code you can switch on, and the message says which statement:

CodeStatusMeaning
permission_policy.invalid_document422The document is not valid: no statements, more than 50, a bad time window or an empty condition
permission_policy.unknown_permission422A statement names something that is not in the catalogue
permission_policy.name_taken409Another of your policies, or one Flowion provides, already has this name
permission_policy.not_grantable403The policy allows something you don't hold
permission_policy.stale409The expectedVersion you sent is no longer the policy's version

The full list, with statuses, is in Errors, pagination and versioning.

Next: Errors, pagination and versioning.

In the API reference