We’ve changed our name! API.AI is now Dialogflow. Learn more here.

/contexts

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.

BaseURL

https://api.dialogflow.com/v1/

Context JSON object

Name Type Description
lifespan Number The number of queries this context will remain active after being invoked.
name String The name of the context.
parameters Array of key/value pairs These are the parameters being passed through the context.
- ENTITY_NAME Array of strings This is the name of the entity object.
-- ENTITY_VALUE String This is the value of the entitiy.
- ENTITY.original String This represents what was included in the request.
- intent_action String This is

GET /contexts

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

GET /contexts sample

HTTP

GET 'https://api.dialogflow.com/v1/contexts?v=20150910&sessionId=12345'

Headers:
Authorization: Bearer YOUR_CLIENT_ACCESS_TOKEN
Content-Type: application/json
    

cURL

curl -X GET \
'https://api.dialogflow.com/v1/contexts?v=20150910&sessionId=12345' \
-H "Authorization: Bearer YOUR_CLIENT_ACCESS_TOKEN" \
-H "Content-Type: application/json"
    

GET /contexts/{context_name}

Retrieves the specified context for the specified session.

GET /contexts/{context_name} sample

HTTP

GET 'https://api.dialogflow.com/v1/contexts/shop?v=20150910&sessionId=12345'

Headers:
Authorization: Bearer YOUR_CLIENT_ACCESS_TOKEN
Content-Type: application/json
    

cURL

curl -X GET \
'https://api.dialogflow.com/v1/contexts/shop?v=20150910&sessionId=12345' \
-H "Authorization: Bearer YOUR_CLIENT_ACCESS_TOKEN" \
-H "Content-Type: application/json"
    

GET responses

POST /contexts

Adds new active contexts to the specified session.

POST /contexts sample

HTTP

GET 'https://api.dialogflow.com/v1/contexts?sessionId=12345'

Headers:
Authorization: Bearer YOUR_CLIENT_ACCESS_TOKEN
Content-Type: application/json

POST body:
[
  {
    "lifespan": 3,
    "name": "pick-fruit",
    "parameters": {
      "fruit": "Kiwi"
    }
  }
]
    

cURL

curl -X POST \
'https://api.dialogflow.com/v1/contexts?sessionId=12345' \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d "[
  {
    "lifespan": 3,
    "name": "pick-fruit",
    "parameters": {
      "fruit": "Kiwi"
    }
  }
]"
    

DELETE /contexts

Deletes all contexts from the specified session.

DELETE /contexts sample

HTTP

DELETE 'https://api.dialogflow.com/v1/contexts?sessionId=12345'

Headers:
Authorization: Bearer YOUR_CLIENT_ACCESS_TOKEN
Content-Type: application/json
    

cURL

curl -X DELETE \
'https://api.dialogflow.com/v1/contexts?sessionId=12345' \
-H "Authorization: Bearer YOUR_CLIENT_ACCESS_TOKEN" \
-H "Content-Type: application/json"
    

DELETE /contexts/{context_name}

Deletes the specified context from the specified session.

DELETE /contaxts/{context_name} sample

HTTP

DELETE 'https://api.dialogflow.com/v1/contexts/shop?sessionId=12345'

Headers:
Authorization: Bearer YOUR_CLIENT_ACCESS_TOKEN
Content-Type: application/json
    

cURL

curl -X DELETE \
'https://api.dialogflow.com/v1/contexts/shop?sessionId=12345' \
-H "Authorization: Bearer YOUR_CLIENT_ACCESS_TOKEN" \
-H "Content-Type: application/json"
    

POST, PUT and DELETE responses