Inject a Context - Cognigy Documentation
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Inject a Context
POST /v2.0/sessions/{sessionId}/context/inject
Example Request
cURL
curl --request POST \
--url https://api-trial.cognigy.ai/new/v2.0/sessions/{sessionId}/context/inject \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"userId": "user@example.com",
"context": {}
}'
Python
import requests
url = "https://api-trial.cognigy.ai/new/v2.0/sessions/{sessionId}/context/inject"
payload = {
"userId": "user@example.com",
"context": {}
}
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)
JavaScript (Fetch)
const options = {
method: 'POST',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({userId: 'user@example.com', context: {}})
};
fetch('https://api-trial.cognigy.ai/new/v2.0/sessions/{sessionId}/context/inject', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
PHP
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-trial.cognigy.ai/new/v2.0/sessions/{sessionId}/context/inject",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'userId' => 'user@example.com',
'context' => []
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
Example Responses
- 200: Returns the injected context.
- 400: Validation failed. Missing payload.
- 401: Unauthorized.
- 402: Payment required.
- 403: Forbidden.
- 404: Not Found.
- 500: Internal Server Error.
- 503: Service unavailable.
Authorizations
- X-API-Key (header) is required.
Headers
- Accept: Specifies the expected media type in the response. Default is
application/json.
Path Parameters
- sessionId (required): The Id of the Session.
Body
- userId (string, required): The user ID as an email.
- context (object, required): The context to inject.