Skip to content

Create Mapping Rule



POST /api/v1/saml/mapping/field/add

Overview

Creates an attribute-to-role mapping for a specified SSO provider.

Before You Call and Usage Steps

This is a legacy-address compatibility endpoint, and the current source code still actually registers it; the historical "retired on 2026-05-31" comment does not mean that requests are currently prohibited. For new integrations, prefer Create Mapping Rule. The legacy path uses the same controller/request fields/response and does not exclude OIDC because of the saml prefix.

This endpoint group maps login attributes from a specific SSO provider to roles in the current Workspace, which differs from custom_login_mapping and system mapping for LDAP/OIDC in the Deployment Plan. Creating a rule does not automatically enable mapping: you need to enable isOpenSAMLMapping for the corresponding SSO configuration (set_disable in this group), and the SSO configuration itself must also be enabled.

Attribute name matching is compared in lowercase, and values are not matched by regular expression or contains. String arrays are matched value by value; non-array objects/numbers/null, etc., are first converted to strings with json.dumps, while array elements are not uniformly converted to strings. Therefore, prefer stable string attributes and string arrays from the identity source. If multiple roles match, their union is used. After mapping is enabled for SSO, no rules/no matches can prevent accounts from entering this Workspace and remove old associations in subsequent logins/switches; this is not simply appending a default role. After writing, the Workspace and member caches are refreshed asynchronously, which may affect subsequent access by existing SSO sessions; it cannot be promised that changes will take effect only at the next login.

The field/value combination is unique within the same provider. Creation does not automatically enable the provider's mapping switch; configure and verify rules first, then enable it. Success only returns true; subsequently retrieve the new UUID from the list. Input roles are filtered; after saving, verify targetValues/roleInfos and ssoInfo. After submission, a cache refresh task is dispatched. If dispatch fails, a 500 may occur, but the rule has already been saved; do not blindly create it again. This endpoint group does not send SSO configuration change emails and does not apply the needNotify parameter of shared SSO create/modify to this page.

Request Headers

Parameter Name Type Required Description
DF-API-KEY string Y OpenAPI authentication credential for the Workspace.
Example: <DF-API-KEY>
How to obtain or enter: Obtain an OpenAPI Key with this operation permission from API Key Management in the target Workspace.

Request Body Parameters

Parameter Name Type Required Description
targetValues[*] string String, not a display name, do not submit nested objects; the current element shape is not uniformly strongly typed checked.
Example: general
How to obtain or enter: A single role UUID/system identifier visible in this Workspace.
ssoUUID string Y Required for creation; although declared optional for modification, the implementation overwrites the old ssoUUID with the omitted value None. A normal submission may cause a database 500, so you must explicitly populate the current/new target. Current create/modify does not enforce validation that the SSO exists or belongs to the Workspace; successful saving does not prove the target is valid; do not submit UUIDs from other Workspaces or fake UUIDs.
Allows null: False
Maximum length: 48
Example: sso_example
How to obtain or enter: Get the provider UUID of the current Workspace from the SSO Configuration List, and choose SAML or OIDC according to the actual configuration.
sourceField string Y Required; a non-empty value is recommended. Field names are case-insensitive during matching, but same-name checks are still determined by database equality semantics; dot paths are not supported. Creation has no unified declared maximum length, modification is ≤256, the storage column is 256, and it is recommended to keep all values ≤256.
Allows null: False
Example: groups
How to obtain or enter: Obtain the actual top-level attribute field name from the identity provider administrator.
sourceValue string Y Required; a non-empty value is recommended. This is not a wildcard/regular expression; creation does not declare a length, modification is ≤256, the storage column is 256, and all are recommended to be ≤256.
Allows null: False
Example: engineering
How to obtain or enter: Take the actual string of the attribute or a single element in a string array; do not enter the full array text.
targetValues array Y Required array; a non-empty array is recommended; some unknown/cross-Workspace roles are filtered out, and status 0/2 are retained; [] or no visible records at all reports NotFoundRole. Saving status 2 does not guarantee current availability, and roleInfos in the list only shows 0. When all targets are soft-deleted but records still exist, they may be filtered into an empty set and are not treated as a valid mapping.
Example: ["general"]
How to obtain or enter: Obtain visible role identifiers from the Role List in the current Workspace, such as general/readOnly/custom role_.

Request Example

curl --request POST 'https://openapi.truewatch.com/api/v1/saml/mapping/field/add' \
  -H 'DF-API-KEY: <DF-API-KEY>' \
  -H 'Content-Type: application/json' \
  --data-raw '{"ssoUUID":"sso_example","sourceField":"groups","sourceValue":"engineering","targetValues":["general"]}'

Response

HTTP 200, application/json. The example below shows the main fields that can be read directly.

Field Type Description
content boolean true on success; does not return the mapping entity or login result.
{
  "code": 200,
  "content": true,
  "errorCode": "",
  "message": "",
  "success": true,
  "traceId": "TRACE-EXAMPLE"
}

Error Responses

For authentication, rate limiting, and common request errors, see Common Error Definitions.

HTTP Status errorCode Trigger Condition Message or Response Description Resolution
406 ft.ParameterValidationFailed A request field is missing, or the field value violates the declared validation conditions Parameter parsing failed Verify the parameter location, field name, type, and value.
400 ft.RequestJsonFormatError Invalid request JSON syntax Request JSON format error Fix the JSON according to content.reason, line, and column.
400 ft.JsonFormatError The top level of the Body is not an object Partial JSON file format error Submit a complete ssoUUID/sourceField/sourceValue/targetValues object.
404 ft.SamlMappingFieldAlreadyExists A non-deleted mapping with the same ssoUUID+sourceField+sourceValue already exists in this Workspace (modification excludes itself) A mapping field name and field value that are the same already exist in the Workspace Use a new combination or update the existing UUID; note that the HTTP status is 404.
404 ft.NotFoundRole The input roles or the old mapping target set contain no role records visible in this Workspace, including []; modification/deletion audits may also trigger this The specified role was not found or has been deleted Verify the current input/old target from the Role List; do not treat an empty set as a successful clear; for historical bad rules, ask an administrator to repair them before processing.
500 ft.InternalServerError An uncaught exception occurs in the saved JSON shape, the database, or task dispatch after submission Internal error The database may have committed while cache task dispatch failed; first read back the rule/SSO switch from the list before processing, and retain the traceId.