POST /content-graphs/{instance_id}/query
1 min
POST
https://api.cmp.optimizely.com/v3/content-graphs/{instance_id}/query
Path Parameters
- instance_idstringrequiredExampleDescription
Body Parameters
- bodyContentGraphQueryRequestrequiredDescription
- querystringrequiredExampleDescriptionMin Length1
- variablesmap<string, string>Example
{ "after": null }Description
Responses
200
- ContentGraphQueryResponseExample
{ "data": { "cmp_PublicImageAsset": { "cursor": "FGluY2x1", "total": 53, "items": [ { "Id": "03f47ac464bc11f18b0102420ac80022" } ] } }, "extensions": { "correlationId": "a18548eeeee29cba", "cost": 51 } }Description- datamap<string, string>Description
- errorsobject[]Description
- extensionsmap<string, string>Description
400
- ContentGraphQueryResponseExample
{ "errors": [ { "message": "Cannot query field \"Nope\" on type \"Query\"." } ] }Description- datamap<string, string>Description
- errorsobject[]Description
- extensionsmap<string, string>Description
401
- ErrorExample
{ "message": "Unauthorized" }Description- messagestringrequiredExampleDescription
- errorsmap<string, string>Description
403
- ErrorExample
{ "message": "You do not have the permission to perform this operation" }Description- messagestringrequiredExampleDescription
- errorsmap<string, string>Description
404
- ErrorExample
{ "message": "Resource not found" }Description- messagestringrequiredExampleDescription
- errorsmap<string, string>Description
429
- ContentGraphQueryResponseExample
{ "errors": [ { "message": "Too many requests." } ] }Description- datamap<string, string>Description
- errorsobject[]Description
- extensionsmap<string, string>Description
502
- ErrorExample
{ "message": "Content graph query failed upstream. Please retry." }Description- messagestringrequiredExampleDescription
- errorsmap<string, string>Description
504
- ErrorExample
{ "message": "Content graph is unreachable. Please retry." }Description- messagestringrequiredExampleDescription
- errorsmap<string, string>Description
curl
curl --request POST \
--url https://api.cmp.optimizely.com/v3/content-graphs/{instance_id}/query \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '{
"query": "query MyQuery($after: String) { cmp_PublicImageAsset(limit: 50, cursor: $after) { total items { Id } cursor } }"
}'javascript
var myHeaders = new Headers();
myHeaders.append("accept", "application/json");
myHeaders.append("content-type", "application/json");
var raw = JSON.stringify({
"query": "query MyQuery($after: String) { cmp_PublicImageAsset(limit: 50, cursor: $after) { total items { Id } cursor } }"
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://api.cmp.optimizely.com/v3/content-graphs/{instance_id}/query", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));ruby
require "uri"
require "json"
require "net/http"
url = URI("https://api.cmp.optimizely.com/v3/content-graphs/{instance_id}/query")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["accept"] = "application/json"
request["content-type"] = "application/json"
request.body = JSON.dump({
"query": "query MyQuery($after: String) { cmp_PublicImageAsset(limit: 50, cursor: $after) { total items { Id } cursor } }"
})
response = https.request(request)
puts response.read_body
python
import requests
import json
url = "https://api.cmp.optimizely.com/v3/content-graphs/{instance_id}/query"
payload = json.dumps({
"query": "query MyQuery($after: String) { cmp_PublicImageAsset(limit: 50, cursor: $after) { total items { Id } cursor } }"
})
headers = {
'accept': 'application/json',
'content-type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
200
// Query reached the content graph and succeeded. The body is the graph's JSON response, passed through unchanged.
{
"data": "",
"errors": [
{}
],
"extensions": ""
}400
// The request was invalid (for example a missing query), or the graph rejected a well-formed query. When it originates from the graph, the body is the graph's GraphQL errors payload.
{
"data": "",
"errors": [
{}
],
"extensions": ""
}401
// Authorization error
{
"message": "Not found",
"errors": ""
}403
// Permission error
{
"message": "Not found",
"errors": ""
}404
// Not found error
{
"message": "Not found",
"errors": ""
}429
// The content graph rate-limited the request. Passed through with the graph's status and body unchanged. Retry after a short delay.
{
"data": "",
"errors": [
{}
],
"extensions": ""
}502
// The content graph is unavailable or returned an error that could not be passed through to the caller. Transient — retry.
{
"message": "Not found",
"errors": ""
}504
// The content graph could not be reached within the timeout. Transient — retry.
{
"message": "Not found",
"errors": ""
}