Add email patterns
Adds email patterns to an access policy.
POST /organizations/{organizationId}/contexts/sign-in/{contextId}/access-policies/{policyId}/email-patterns/add
Permission: Sign In › Access Policies (Write). See API permissions.
Adds up to 500 email patterns, each once. The response has one result per pattern, in the order sent, and all the patterns of the policy after the change. Repeating the call is safe.
Each pattern gets one of three outcomes. Patterns are compared
ignoring case: Alice@Example.com and alice@example.com are the
same pattern.
ADDED: the policy did not have the pattern and has it now.ALREADY_IN_POLICY: the policy had the pattern, in any case. Nothing changes.IN_OTHER_POLICY: another access policy of the context has the pattern, in any case, so it was not added.reasonsays so.
The fallback policy of the context, the one with "default": true, is
the exception. A pattern it holds does not stop you from adding the
pattern to another policy, and the pattern then stays in both.
Request
Section titled “Request”| Parameter | In | Type | Required | Description |
|---|---|---|---|---|
organizationId | Path | string | Yes | The Organization ID of the API key. Any other ID returns 404. |
contextId | Path | string | Yes | The ID of a Sign-In Context of the Organization. Any other ID returns 404. |
policyId | Path | string | Yes | The ID of the access policy, from List access policies. An unknown ID returns 404. |
emailPatterns | Body | string[] | Yes | The email addresses or domains to add, such as alice@example.com or @example.com. 1 to 500 patterns, each 1 to 254 characters, not blank, each once. Trimmed and stored in lower case. |
Request example
curl -X POST "$API_BASE_URL/organizations/$ORGANIZATION_ID/contexts/sign-in/$CONTEXT_ID/access-policies/66f2a1c4e8b0a93d5c1e7f20/email-patterns/add" \ -H "Authorization: Bearer $NCP_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "emailPatterns": ["Alice@Example.com", "@example.org", "bob@example.net"] }'Response
Section titled “Response”| Field | Type | Description |
|---|---|---|
results | object[] | One entry per pattern sent, in the order sent. |
results[].emailPattern | string | The pattern, trimmed and in lower case. |
results[].outcome | string | ADDED, ALREADY_IN_POLICY or IN_OTHER_POLICY. New values can be added within v2. |
results[].reason | object or null | Why the pattern was not added: the errorCode SIGN_IN_EMAIL_PATTERN_IN_OTHER_POLICY and a detail. null for ADDED and ALREADY_IN_POLICY. |
emailPatterns | string[] | All the patterns of the policy after the change, sorted. |
Response example
{ "results": [ { "emailPattern": "alice@example.com", "outcome": "ADDED", "reason": null }, { "emailPattern": "@example.org", "outcome": "ALREADY_IN_POLICY", "reason": null }, { "emailPattern": "bob@example.net", "outcome": "IN_OTHER_POLICY", "reason": { "errorCode": "SIGN_IN_EMAIL_PATTERN_IN_OTHER_POLICY", "detail": "Another access policy of the context has the pattern." } } ], "emailPatterns": ["@example.org", "alice@example.com", "carol@example.com"]}In this example the policy already had @example.org, and
bob@example.net belongs to another access policy of the context, so
only alice@example.com was added.
Errors
Section titled “Errors”| Status | errorCode | When |
|---|---|---|
400 | VALIDATION_FAILED | The list is empty or has more than 500 patterns, or a pattern is blank or longer than 254 characters. errors names each pattern. Nothing is added. |
400 | VALIDATION_FAILED | A pattern is sent twice, in any case: errors names the second one with the code DUPLICATE. Nothing is added. |
404 | RESOURCE_NOT_FOUND | The context has no access policy with this ID, organizationId is not the Organization of the API key, or contextId is not one of its Sign-In Contexts. |
Errors common to all operations are in Errors.