> ## Documentation Index
> Fetch the complete documentation index at: https://developers.telnyx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Simulate IAM decisions

> Decides a list of requests for a user or a service account as if it held exactly the given roles instead of its current grants, whether or not the organization has enabled IAM. Nothing is changed, so this is how a role is tested before it is granted. One decision comes back per request, in the same order.

A simulate names 1 to 10 roles of the organization and 1 to 50 requests, each an exact action ID. A role of another organization, a wildcard, or an unknown action answers `422`. Simulate decides from the given roles only, so it applies neither an API key's scope nor the actions a signed-in user always keeps. The organization owner holds no roles, so the given roles do not change the owner's decisions.

Only the organization owner can call this endpoint. Its action is `iam.simulate`. Other users and service account tokens get `403`.



## OpenAPI

````yaml /openapi/source/external/iam/iam.json post /iam/simulate
openapi: 3.1.0
info:
  title: Telnyx API
  version: 1.0.0
  description: >-
    Identity and Access Management (IAM) decides what the users and service
    accounts of an organization may do. The organization writes roles of allow
    and deny statements over actions, gives the roles to users and service
    accounts with grants, and enables IAM so that the grants decide. This API
    manages roles and their statements, grants, the IAM setting, service
    accounts and their tokens, and the organization's API keys and their scopes.
    It also reads the action catalog, explains and simulates decisions, and
    lists access logs.


    Only the organization owner can call these endpoints. Any other user, and
    any service account token, gets `403`. Each endpoint declares an action,
    named in its description. Once IAM is enabled, a scope on one of the owner's
    API keys narrows that key, so the key can call an endpoint only when its
    scope allows the endpoint's action.


    See [IAM](https://developers.telnyx.com/docs/iam) for how decisions are
    made.
  contact:
    email: support@telnyx.com
  x-latency-category: interactive
  x-endpoint-cost: light
servers:
  - url: https://api.telnyx.com/v2
    description: Telnyx API v2
security:
  - bearerAuth: []
tags:
  - name: IAM Roles
    description: >-
      Named sets of statements that the organization gives to users and service
      accounts with grants.
  - name: IAM Role Statements
    description: The statements of a role, each allowing or denying a list of actions.
  - name: IAM Grants
    description: Which users and service accounts hold which roles.
  - name: IAM Actions
    description: The catalog of actions that routes declare and statements allow or deny.
  - name: IAM Settings
    description: Whether the organization has enabled IAM.
  - name: IAM Service Accounts
    description: Principals for workloads, such as servers, pipelines, and integrations.
  - name: IAM Service Account Tokens
    description: The credentials a service account authenticates with.
  - name: IAM API Keys
    description: The API keys of every user of the organization, the owner's included.
  - name: IAM API Key Scopes
    description: Statements on one API key that narrow what it may do.
  - name: IAM Decisions
    description: >-
      What IAM decides for a principal, explained or simulated without changing
      anything.
  - name: IAM Access Logs
    description: >-
      The requests IAM allowed or denied, with the reasons and the roles behind
      them.
paths:
  /iam/simulate:
    post:
      tags:
        - IAM Decisions
      summary: Simulate IAM decisions
      description: >-
        Decides a list of requests for a user or a service account as if it held
        exactly the given roles instead of its current grants, whether or not
        the organization has enabled IAM. Nothing is changed, so this is how a
        role is tested before it is granted. One decision comes back per
        request, in the same order.


        A simulate names 1 to 10 roles of the organization and 1 to 50 requests,
        each an exact action ID. A role of another organization, a wildcard, or
        an unknown action answers `422`. Simulate decides from the given roles
        only, so it applies neither an API key's scope nor the actions a
        signed-in user always keeps. The organization owner holds no roles, so
        the given roles do not change the owner's decisions.


        Only the organization owner can call this endpoint. Its action is
        `iam.simulate`. Other users and service account tokens get `403`.
      operationId: SimulateIamDecisions
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/IamSimulateRequest'
            examples:
              user:
                summary: Test a role for a user
                value:
                  principal_type: user
                  principal_id: b1d7e2c4-9a3f-4e58-8c61-0f2a7d5e9b13
                  with_role_ids:
                    - 8c4a9715-0246-4c6f-9eca-390e13bd8af0
                  requests:
                    - action: number_order.create
                    - action: number.delete
      responses:
        '200':
          description: One decision per request, in the order of the requests.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/IamDecisionsResponse'
              example:
                data:
                  - action: number_order.create
                    decision: allow
                    reason: action_allowed
                    detail: a role allows number_order.create
                    allowed_role_ids:
                      - 8c4a9715-0246-4c6f-9eca-390e13bd8af0
                    denied_role_ids: []
                    record_type: iam_decision
                  - action: number.delete
                    decision: deny
                    reason: action_denied
                    detail: a role denies number.delete
                    allowed_role_ids: []
                    denied_role_ids:
                      - 8c4a9715-0246-4c6f-9eca-390e13bd8af0
                    record_type: iam_decision
        '401':
          $ref: '#/components/responses/IamUnauthorized'
        '403':
          description: >-
            The caller is not the organization owner, or the scope of the
            owner's API key does not allow `iam.simulate`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/IamErrors'
              examples:
                not_owner:
                  summary: The caller is not the organization owner
                  value:
                    errors:
                      - code: '10010'
                        title: Authorization failed
                        detail: >-
                          You do not have permission to perform the requested
                          action on the specified resource or resources.
                        source:
                          pointer: /
                        meta:
                          url: >-
                            https://developers.telnyx.com/docs/overview/errors/10010
                key_scope:
                  summary: The scope of the owner's API key does not allow the action
                  value:
                    errors:
                      - code: '10010'
                        title: Authorization failed
                        detail: the credential's scope does not allow iam.simulate
                        source:
                          pointer: /
                        meta:
                          url: >-
                            https://developers.telnyx.com/docs/overview/errors/10010
        '422':
          description: >-
            A field is missing, a role does not exist in the organization, or a
            request names an unknown action.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/IamErrors'
              examples:
                unknown_role:
                  summary: A role does not exist in the organization
                  value:
                    errors:
                      - code: '10027'
                        title: Unprocessable Entity
                        detail: >-
                          with_role_ids names roles that do not exist:
                          0d6f3b2a-8e41-4c97-b5a0-7e2c9d1f4a68
                        source:
                          pointer: /with_role_ids
                        meta:
                          url: >-
                            https://developers.telnyx.com/docs/overview/errors/10027
                unknown_action:
                  summary: A request names an unknown action
                  value:
                    errors:
                      - code: '10027'
                        title: Unprocessable Entity
                        detail: 'requests names unknown actions: number.remove'
                        source:
                          pointer: /requests
                        meta:
                          url: >-
                            https://developers.telnyx.com/docs/overview/errors/10027
components:
  schemas:
    IamSimulateRequest:
      type: object
      additionalProperties: false
      required:
        - principal_type
        - principal_id
        - with_role_ids
        - requests
      properties:
        principal_type:
          type: string
          enum:
            - user
            - service_account
          description: Whether the principal is a user or a service account.
        principal_id:
          type: string
          description: The ID of the user or service account to decide for.
        with_role_ids:
          type: array
          minItems: 1
          maxItems: 10
          items:
            type: string
            format: uuid
          description: >-
            The roles of the organization to decide with, in place of the
            principal's grants. Duplicates are removed.
        requests:
          type: array
          minItems: 1
          maxItems: 50
          description: The requests to decide.
          items:
            type: object
            additionalProperties: false
            required:
              - action
            properties:
              action:
                type: string
                description: An exact action ID from the catalog. A wildcard is refused.
    IamDecisionsResponse:
      type: object
      required:
        - data
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/IamDecision'
          description: One decision per request, in the order of the requests.
    IamErrors:
      type: object
      required:
        - errors
      properties:
        errors:
          type: array
          items:
            $ref: '#/components/schemas/IamError'
    IamDecision:
      type: object
      required:
        - action
        - decision
        - reason
        - detail
        - allowed_role_ids
        - denied_role_ids
        - record_type
      properties:
        action:
          type: string
          description: The action decided.
        decision:
          type: string
          enum:
            - allow
            - deny
            - not_iam_managed
          description: >-
            `allow` or `deny`, or `not_iam_managed` when IAM does not decide the
            request: the organization has not enabled IAM, or the principal is
            the organization owner.
        reason:
          type: string
          description: >-
            Why, as a code. `action_allowed` when the action is allowed,
            `action_denied` when a role denies it, and `action_not_granted` when
            no role allows it. `iam_disabled` when the organization has not
            enabled IAM, and `organization_owner` when the principal is the
            organization owner, who holds no roles.
        detail:
          type: string
          description: The reason, in words.
        allowed_role_ids:
          type: array
          items:
            type: string
            format: uuid
          description: The roles with an allow statement for the action.
        denied_role_ids:
          type: array
          items:
            type: string
            format: uuid
          description: >-
            The roles with a deny statement for the action. A deny wins, so both
            lists are filled when roles conflict.
        record_type:
          type: string
          enum:
            - iam_decision
          description: Identifies the type of the resource.
    IamError:
      type: object
      required:
        - code
        - title
      properties:
        code:
          type: string
          description: The Telnyx error code.
        title:
          type: string
          description: A short summary of the error.
        detail:
          type: string
          description: What went wrong.
        source:
          type: object
          description: The part of the request that caused the error.
          properties:
            pointer:
              type: string
              description: A JSON pointer to the field that caused the error.
            value:
              description: The value that caused the error.
        meta:
          type: object
          properties:
            url:
              type: string
              format: uri
              description: The documentation page for the error code.
            denied_role_ids:
              type: array
              items:
                type: string
                format: uuid
              description: >-
                The granted roles whose deny statements refused the request,
                when a role refused it.
  responses:
    IamUnauthorized:
      description: The request has no valid credential.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/IamErrors'
          example:
            errors:
              - code: '10009'
                title: Authentication failed
                detail: Could not find any usable credentials in the request.
                source:
                  pointer: /
                meta:
                  url: https://developers.telnyx.com/docs/overview/errors/10009
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````