# Edge Platform Custom Context API

Use the Custom Context API to create, retrieve, update, and delete the [context](https://doc.sitecore.com/portal/en/developers/sitecore-cloud-portal/context-ids.html). A context ID is a unified identifier that grants access to specific resources in a Sitecore Cloud Portal organization and is helps determine the context for an organization. 

 To use this REST API, you must authenticate your API requests. Keep in mind: 

 - All API requests are made in your production environment.

 - The base URL is `https://edge-platform-context-api.sitecorecloud.io`.

<b>NOTE</b>: You must have an [*Organization Admin* or *Organization Owner* role](https://doc.sitecore.com/portal/en/developers/sitecore-cloud-portal/roles.html#organization-roles) in Sitecore Cloud Portal. 

## Authentication

The Edge Platform Context API uses [bearer](https://doc.sitecore.com/portal/en/developers/sitecore-cloud-portal/manage-api-tokens.html) authentication. Bearer tokens are generated in response to a login request.

To get a bearer token:

 1. Log in to the [Sitecore Cloud Portal](https://portal.sitecorecloud.io/).

 2. In the top-right corner of the menu bar, click your profile icon > **API tokens**.

 3. Click **Copy to clipboard**.

You can now start making REST API requests. You must include this token in the authorization header of every request you make.

Version: 1.0
License: Apache 2.0
Metadata:
  - product: Cloud Portal

## Servers

```
https://edge-platform-context-api.sitecorecloud.io
```

## Security

### BearerAuth

Type: http
Scheme: bearer
Bearer Format: JWT

## Download OpenAPI description

[Edge Platform Custom Context API](https://api-docs.sitecore.com/_bundle/portal/edge-platform-custom-context-api/index.yaml)

## Context

The Context API lets you [create and manage context IDs](https://doc.sitecore.com/portal/en/developers/sitecore-cloud-portal/context-ids.html) for your organization.

### Create context

 - [POST /api/context/user/v1/contexts](https://api-docs.sitecore.com/portal/edge-platform-custom-context-api/context/createusercontext.md): Create a context within your organization. Creating a context means issuing a new context ID and defining what it can access. 

 NOTE: products and resources cannot be present together.

### Retrieve a context by ID

 - [GET /api/context/user/v1/contexts/{sitecoreContextId}](https://api-docs.sitecore.com/portal/edge-platform-custom-context-api/context/getusercontextbyid.md): Get a context within your organization by specifying a sitecoreContextId . When you get a context, you retrieve the configuration and metadata of the context. This tells you what the context ID grants access to.

### Delete a context by ID

 - [DELETE /api/context/user/v1/contexts/{sitecoreContextId}](https://api-docs.sitecore.com/portal/edge-platform-custom-context-api/context/deleteusercontextbyid.md): Delete a context within an organization by specifying a sitecoreContextId . When you delete a context, the context no longer grants access.

### Update a context

 - [PATCH /api/context/user/v1/contexts/{sitecoreContextId}](https://api-docs.sitecore.com/portal/edge-platform-custom-context-api/context/updateusercontext.md): Update a context by specifying a sitecoreContextId. Updating a context, you update the context definition without creating a new context (for example, you can adjust the access time.

### Regenerate a custom context ID

 - [POST /api/context/user/v1/contexts/{sitecoreContextId}/regenerate](https://api-docs.sitecore.com/portal/edge-platform-custom-context-api/context/regenerateusercontextid.md): Update a custom context ID by specifying a sitecoreContextId. When you regenerate a custom context ID, this means replacing the SitecoreContextId value with a new one.

### List custom-context pagination

 - [GET /api/context/user/v2/contexts](https://api-docs.sitecore.com/portal/edge-platform-custom-context-api/context/listusercontextpagination.md): Retrieve a paginated list of contexts within an organization.

## Resources

The Resource API lets you create and manage context resources in your organization (for example, add a key, list keys, or fetch a key).

### Create resources

 - [POST /api/context/user/v1/contexts/{sitecoreContextId}/resources](https://api-docs.sitecore.com/portal/edge-platform-custom-context-api/resources/createuserresource.md): Create a context resource. This means adding a specific access target, such as Edge, Personalize, and so on, to an existing context ID.

### List resources

 - [GET /api/context/user/v1/contexts/{sitecoreContextId}/resources](https://api-docs.sitecore.com/portal/edge-platform-custom-context-api/resources/listuserresource.md): Lists all resources attached to a specific context. This is useful when you want to determine what that context can access.

### Retrieve a context resource

 - [GET /api/context/user/v1/contexts/{sitecoreContextId}/resources/{resourceId}](https://api-docs.sitecore.com/portal/edge-platform-custom-context-api/resources/getuserresource.md): Get a context' resource.

### List resources available in the organization

 - [GET /api/context/user/v1/available-resources](https://api-docs.sitecore.com/portal/edge-platform-custom-context-api/resources/listuseravailableresource.md): Lists all available resources of the user's organization that can be added to a context.

## Scoped context

The Scoped context API lets you create and manage the scoped context in your organization. Scoped contexts are tied to the specified parent.

### Create a scoped context

 - [POST /api/context/user/v1/contexts/{masterSitecoreContextId}/filtered](https://api-docs.sitecore.com/portal/edge-platform-custom-context-api/scoped-context/createuserfilteredcontext.md): Creates a scoped context for the masterSitecoreContextId within an organization. It defines subset access through the allowedResourceIds.

### List scoped contexts

 - [GET /api/context/user/v1/contexts/{masterSitecoreContextId}/filtered](https://api-docs.sitecore.com/portal/edge-platform-custom-context-api/scoped-context/listuserfilteredcontext.md): List all scoped contexts under a given parent (masterSitecoreContextId), including allowed resouces and metadata.

### Update a scoped context

 - [PATCH /api/context/user/v1/contexts/{masterSitecoreContextId}/filtered/{sitecoreContextId}](https://api-docs.sitecore.com/portal/edge-platform-custom-context-api/scoped-context/updateuserfilteredcontext.md): Updates a scoped context for a masterSitecoreContextId and sitecoreContextId within an organization.

### Delete scoped context

 - [DELETE /api/context/user/v1/contexts/{masterSitecoreContextId}/filtered/{sitecoreContextId}](https://api-docs.sitecore.com/portal/edge-platform-custom-context-api/scoped-context/deleteuserfilteredcontext.md): Deletes the scoped context identified by masterSitecoreContextId and sitecoreContextId when it's no longer needed. This revokes access granted through that scoped context to its allowed allowedResourceIds.

### Retrieve scoped context data

 - [GET /api/context/user/v1/contexts/{masterSitecoreContextId}/filtered/{sitecoreContextId}](https://api-docs.sitecore.com/portal/edge-platform-custom-context-api/scoped-context/getuserfilteredcontext.md): Gets scoped context data for a masterSitecoreContextId  and sitecoreContextId within an organization.

## Products

Product endpoints let you work at the product/tenant level instead of manually adding individual resources. You can retrieve all available product instances and attach a context to a product.

### List available products

 - [GET /api/context/user/v1/available-products](https://api-docs.sitecore.com/portal/edge-platform-custom-context-api/products/listuseravailableproducts.md): Lists products in your organization that can be added to a context.

### Add product resources to a context

 - [POST /api/context/user/v1/contexts/{sitecoreContextId}/products](https://api-docs.sitecore.com/portal/edge-platform-custom-context-api/products/createuserproduct.md): Adds product-based resources to a specific context.

