/contexts

Overview

The contexts endpoint allows you to get active contexts, add new contexts, or delete active contexts for the specified session Id.

See Contexts for detailed information on contexts.

GET /contexts

Retrieves the list of all currently active contexts for the specified session.

Query Parameters

sessionId – session Id

Response

Array of context objects

GET /contexts Sample Request

This request retrieves all currently active contexts for the session with the Id 1234567890.

curl -i -X GET \
   -H "Accept: application/json" \
   -H "Content-Type: application/json" \
   -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
 'https://api.api.ai/v1/contexts?sessionId=1234567890'

GET /contexts/{context_name}

Retrieves the specified context for the specified session.

Query parameters

sessionId – session Id

Response

  • Context object if the specified context is currently active
  • Status object with "errorType": "not_found" if the specified context is not currently active

GET /contexts/{context_name} Sample Request

This request retrieves the context named "weather".

curl -i -X GET \
   -H "Accept: application/json" \
   -H "Content-Type: application/json" \
   -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
 'https://api.api.ai/v1/contexts/weather?sessionId=1234567890'

POST /contexts

Adds new active contexts to the specified session.

Query Parameters

sessionId – session Id

Response

Names of added contexts.

POST /contexts Sample Request

This request will add the context "greetings" with the lifespan equal to 3 and the parameter "name" with the value "Sam" to the session with the Id 1234567890.

curl -i -X POST \
   -H "Accept: application/json" \
   -H "Content-Type: application/json" \
   -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
   -d \
'[
   {
      "name": "greetings",
      "lifespan": 3,
      "parameters": {
         "name": "Sam"
      }
   }
]' \
 'https://api.api.ai/v1/contexts?sessionId=1234567890'

DELETE /contexts

Deletes all contexts from the specified session.

Query Parameters

sessionId – session Id

DELETE /contexts Sample Request

This request will delete all contexts from the session with the Id 1234567890.

curl -i -X DELETE \
   -H "Accept: application/json" \
   -H "Content-Type: application/json" \
   -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
 'https://api.api.ai/v1/contexts?sessionId=1234567890'

DELETE /contexts/{context_name}

Deletes the specified context from the specified session.

Query Parameters

sessionId – session Id

Response

Status object

DELETE /contexts/{context_name} Sample Request

This request will delete the context "weather" from the session with the Id 1234567890.

curl -i -X DELETE \
   -H "Accept: application/json" \
   -H "Content-Type: application/json" \
   -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
 'https://api.api.ai/v1/contexts/weather?sessionId=1234567890'

Context Object

Field Name Type Description
name Legal name Context name.
lifespan Number Number of requests after which the context will expire.
Optional field.
parameters Array of objects Array of parameters used with the action.
Optional field.
name Legal name Parameter name.
value String The value of the parameter.