Skip to content
Access policies

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. reason says 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.

ParameterInTypeRequiredDescription
organizationIdPathstringYesThe Organization ID of the API key. Any other ID returns 404.
contextIdPathstringYesThe ID of a Sign-In Context of the Organization. Any other ID returns 404.
policyIdPathstringYesThe ID of the access policy, from List access policies. An unknown ID returns 404.
emailPatternsBodystring[]YesThe 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
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"]
}'
FieldTypeDescription
resultsobject[]One entry per pattern sent, in the order sent.
results[].emailPatternstringThe pattern, trimmed and in lower case.
results[].outcomestringADDED, ALREADY_IN_POLICY or IN_OTHER_POLICY. New values can be added within v2.
results[].reasonobject or nullWhy the pattern was not added: the errorCode SIGN_IN_EMAIL_PATTERN_IN_OTHER_POLICY and a detail. null for ADDED and ALREADY_IN_POLICY.
emailPatternsstring[]All the patterns of the policy after the change, sorted.

Response example

200
{
"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.

StatuserrorCodeWhen
400VALIDATION_FAILEDThe 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.
400VALIDATION_FAILEDA pattern is sent twice, in any case: errors names the second one with the code DUPLICATE. Nothing is added.
404RESOURCE_NOT_FOUNDThe 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.

Next