{"_id":"5845a4a89f6fbb1b004307d0","category":{"_id":"5845a4a89f6fbb1b004307ba","__v":0,"version":"5845a4a89f6fbb1b004307b7","project":"54d3007669578e0d002730c9","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-07-30T06:53:33.020Z","from_sync":false,"order":2,"slug":"api-reference","title":"API reference"},"version":{"_id":"5845a4a89f6fbb1b004307b7","project":"54d3007669578e0d002730c9","__v":2,"createdAt":"2016-12-05T17:32:24.708Z","releaseDate":"2016-12-05T17:32:24.708Z","categories":["5845a4a89f6fbb1b004307b8","5845a4a89f6fbb1b004307b9","5845a4a89f6fbb1b004307ba","5845a4a89f6fbb1b004307bb","5845a4a89f6fbb1b004307bc","5845a4a89f6fbb1b004307bd","5845a4a89f6fbb1b004307be","5845a4a89f6fbb1b004307bf","5845a4a89f6fbb1b004307c0","592deb23644f060f008e5aa6"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"25.0.0","version":"25"},"parentDoc":null,"project":"54d3007669578e0d002730c9","__v":0,"user":"55bf6cdcad601c2b00762d13","updates":["57ea6d571780cd170064f264"],"next":{"pages":[],"description":""},"createdAt":"2016-04-27T21:49:10.422Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":9,"body":"* [Overview](#overview)\n* [GET /contexts](#get-contexts)\n* [GET /contexts/{context_name}](#get-contextscontext_name)\n* [POST /contexts](#post-contexts)\n* [DELETE /contexts](#delete-contexts)\n* [DELETE /contexts/{context_name}](#delete-contextscontext_name)\n* [Context Object](#context-object)\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Overview\"\n}\n[/block]\nThe **contexts** endpoint allows you to get active contexts, add new contexts, or delete active contexts for the specified session Id. \n\nSee  <a href=\"https://docs.api.ai/docs/concept-contexts\" target=\"_blank\">Contexts</a> for detailed information on contexts.\n[block:api-header]\n{\n  \"type\": \"get\",\n  \"title\": \"GET /contexts\"\n}\n[/block]\nRetrieves the list of all currently active contexts for the specified session.\n\n**Query Parameters**\n`sessionId` – session Id\n\n**Response**\nArray of [context objects](#context-object)\n\n### GET  /contexts Sample Request\n\nThis request retrieves all currently active contexts for the session with the Id `1234567890`.\n\n```\ncurl -i -X GET \\\n   -H \"Accept: application/json\" \\\n   -H \"Content-Type: application/json\" \\\n   -H \"Authorization: Bearer YOUR_ACCESS_TOKEN\" \\\n 'https://api.api.ai/v1/contexts?sessionId=1234567890'\n```\n[block:api-header]\n{\n  \"type\": \"get\",\n  \"title\": \"GET /contexts/{context_name}\"\n}\n[/block]\nRetrieves the specified context for the specified session.\n\n**Query parameters**\n`sessionId` – session Id\n\n**Response**\n- [Context object](#context-object) if the specified context is currently active\n- Status object with `\"errorType\": \"not_found\"` if the specified context is not currently active\n\n### GET /contexts/{context_name}  Sample Request\n\nThis request retrieves the context named \"weather\".\n\n```\ncurl -i -X GET \\\n   -H \"Accept: application/json\" \\\n   -H \"Content-Type: application/json\" \\\n   -H \"Authorization: Bearer YOUR_ACCESS_TOKEN\" \\\n 'https://api.api.ai/v1/contexts/weather?sessionId=1234567890'\n```\n[block:api-header]\n{\n  \"type\": \"post\",\n  \"title\": \"POST /contexts\"\n}\n[/block]\nAdds new active contexts to the specified session.\n\n**Query Parameters**\n`sessionId` – session Id\n\n**Response**\nNames of added contexts.\n\n\n### POST /contexts Sample Request\n\nThis 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`.\n```\ncurl -i -X POST \\\n   -H \"Accept: application/json\" \\\n   -H \"Content-Type: application/json\" \\\n   -H \"Authorization: Bearer YOUR_ACCESS_TOKEN\" \\\n   -d \\\n'[\n   {\n      \"name\": \"greetings\",\n      \"lifespan\": 3,\n      \"parameters\": {\n         \"name\": \"Sam\"\n      }\n   }\n]' \\\n 'https://api.api.ai/v1/contexts?sessionId=1234567890'\n```\n[block:api-header]\n{\n  \"type\": \"delete\",\n  \"title\": \"DELETE /contexts\"\n}\n[/block]\nDeletes all contexts from the specified session.\n\n**Query Parameters**\n`sessionId` – session Id\n\n### DELETE /contexts Sample Request\n\nThis request will delete all contexts from the session with the Id `1234567890`.\n```\ncurl -i -X DELETE \\\n   -H \"Accept: application/json\" \\\n   -H \"Content-Type: application/json\" \\\n   -H \"Authorization: Bearer YOUR_ACCESS_TOKEN\" \\\n 'https://api.api.ai/v1/contexts?sessionId=1234567890'\n```\n[block:api-header]\n{\n  \"type\": \"delete\",\n  \"title\": \"DELETE /contexts/{context_name}\"\n}\n[/block]\nDeletes the specified context from the specified session.\n\n**Query Parameters**\n`sessionId` – session Id\n\n**Response**\nStatus object\n\n### DELETE /contexts/{context_name} Sample Request\n\nThis request will delete the context \"weather\" from the session with the Id `1234567890`.\n```\ncurl -i -X DELETE \\\n   -H \"Accept: application/json\" \\\n   -H \"Content-Type: application/json\" \\\n   -H \"Authorization: Bearer YOUR_ACCESS_TOKEN\" \\\n 'https://api.api.ai/v1/contexts/weather?sessionId=1234567890'\n```\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Context Object\"\n}\n[/block]\n\n[block:html]\n{\n  \"html\": \"<table>\\n<tr>\\n  <th colspan=\\\"2\\\">Field Name</th>\\n  <th>Type</th> \\n  <th>Description</th>\\n</tr>\\n<tr>\\n  <td colspan=\\\"2\\\">name</td>\\n  <td>Legal name</td> \\n  <td>Context name.</td>\\n</tr>\\n<tr>\\n  <td colspan=\\\"2\\\">lifespan</td>\\n  <td>Number</td> \\n  <td>Number of requests after which the context will expire.<br>Optional field.</td>\\n</tr>\\n<tr>\\n  <td colspan=\\\"2\\\">parameters</td>\\n  <td>Array of objects</td> \\n  <td>Array of parameters used with the action.<br>Optional field.</td>\\n</tr>\\n<tr>\\n  <td></td>\\n  <td>name</td>\\n  <td>Legal name</td> \\n  <td>Parameter name.</td>\\n</tr>\\n<tr>\\n  <td></td>\\n  <td>value</td>\\n  <td>String</td> \\n  <td>The value of the parameter.</td>\\n</tr>\\n</table>\"\n}\n[/block]","excerpt":"","slug":"contexts","type":"basic","title":"/contexts"}
* [Overview](#overview) * [GET /contexts](#get-contexts) * [GET /contexts/{context_name}](#get-contextscontext_name) * [POST /contexts](#post-contexts) * [DELETE /contexts](#delete-contexts) * [DELETE /contexts/{context_name}](#delete-contextscontext_name) * [Context Object](#context-object) [block:api-header] { "type": "basic", "title": "Overview" } [/block] The **contexts** endpoint allows you to get active contexts, add new contexts, or delete active contexts for the specified session Id. See <a href="https://docs.api.ai/docs/concept-contexts" target="_blank">Contexts</a> for detailed information on contexts. [block:api-header] { "type": "get", "title": "GET /contexts" } [/block] Retrieves the list of all currently active contexts for the specified session. **Query Parameters** `sessionId` – session Id **Response** Array of [context objects](#context-object) ### 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' ``` [block:api-header] { "type": "get", "title": "GET /contexts/{context_name}" } [/block] Retrieves the specified context for the specified session. **Query parameters** `sessionId` – session Id **Response** - [Context object](#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' ``` [block:api-header] { "type": "post", "title": "POST /contexts" } [/block] 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' ``` [block:api-header] { "type": "delete", "title": "DELETE /contexts" } [/block] 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' ``` [block:api-header] { "type": "delete", "title": "DELETE /contexts/{context_name}" } [/block] 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' ``` [block:api-header] { "type": "basic", "title": "Context Object" } [/block] [block:html] { "html": "<table>\n<tr>\n <th colspan=\"2\">Field Name</th>\n <th>Type</th> \n <th>Description</th>\n</tr>\n<tr>\n <td colspan=\"2\">name</td>\n <td>Legal name</td> \n <td>Context name.</td>\n</tr>\n<tr>\n <td colspan=\"2\">lifespan</td>\n <td>Number</td> \n <td>Number of requests after which the context will expire.<br>Optional field.</td>\n</tr>\n<tr>\n <td colspan=\"2\">parameters</td>\n <td>Array of objects</td> \n <td>Array of parameters used with the action.<br>Optional field.</td>\n</tr>\n<tr>\n <td></td>\n <td>name</td>\n <td>Legal name</td> \n <td>Parameter name.</td>\n</tr>\n<tr>\n <td></td>\n <td>value</td>\n <td>String</td> \n <td>The value of the parameter.</td>\n</tr>\n</table>" } [/block]