> For the complete documentation index, see [llms.txt](https://docs.mediarithmics.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mediarithmics.io/api-reference/contextual-targeting/contextual-targeting-queries.md).

# Contextual Targeting Queries

Operations related to Contextual Targeting Queries for defining and managing contextual targeting rules based on keywords, entities, and IAB categories. Supports flexible keyword matching (comma-separated, case-insensitive, accent-sensitive) with up to 2,000 keywords per targeting list for precise content-based audience identification.

## GET /organisations/{organisation\_id}/contextual/queries/{query\_id}

> Get a semantic contextual targeting query

```json
{"openapi":"3.1.1","info":{"title":"mediarithmics openapi API","version":"1.0.0"},"tags":[{"name":"Contextual Targeting Queries","description":"Operations related to Contextual Targeting Queries for defining and managing contextual targeting rules based on keywords, entities, and IAB categories. Supports flexible keyword matching (comma-separated, case-insensitive, accent-sensitive) with up to 2,000 keywords per targeting list for precise content-based audience identification."}],"servers":[{"url":"http://api.mediarithmics.local/v1","description":"Development server"},{"url":"https://api.mediarithmics.com/v1","description":"Production server"}],"paths":{"/organisations/{organisation_id}/contextual/queries/{query_id}":{"get":{"summary":"Get a semantic contextual targeting query","description":"","responses":{"200":{"description":"Success !","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string","enum":["ok"]},"data":{"$ref":"#/components/schemas/SemanticContextualTargetingQueryResource"}},"required":["data","status"]}}}},"400":{"$ref":"#/components/responses/error"},"401":{"$ref":"#/components/responses/error"},"403":{"$ref":"#/components/responses/error"},"404":{"$ref":"#/components/responses/error"},"500":{"$ref":"#/components/responses/error"},"503":{"$ref":"#/components/responses/error"}},"operationId":"getSemanticContextualTargetingQuery","tags":["Contextual Targeting Queries"],"parameters":[{"name":"organisation_id","style":"simple","required":true,"in":"path","explode":false,"schema":{"type":"integer","format":"int64"}},{"explode":false,"required":true,"in":"path","style":"simple","name":"query_id","schema":{"type":"integer","format":"int64"}}]}}},"components":{"schemas":{"SemanticContextualTargetingQueryResource":{"type":"object","properties":{"last_modified_ts":{"type":"integer","format":"int64","default":0,"readOnly":true},"last_modified_by":{"type":"string","readOnly":true},"created_ts":{"type":"integer","format":"int64","default":0,"readOnly":true},"organisation_id":{"type":"string","readOnly":true},"id":{"type":"string","readOnly":true},"created_by":{"type":"string","readOnly":true},"query_data":{"$ref":"#/components/schemas/SemanticContextualTargetingQueryDataResource"}},"required":["created_by","created_ts","id","organisation_id","query_data"]},"SemanticContextualTargetingQueryDataResource":{"type":"object","properties":{"language_name":{"$ref":"#/components/schemas/SemanticQueryLanguage"},"language_version":{"$ref":"#/components/schemas/SemanticQueryLanguageVersion"},"query":{"$ref":"#/components/schemas/SemanticContextualTargetingQueryContentResource"}},"required":["language_name","language_version","query"]},"SemanticQueryLanguage":{"type":"string","enum":["JSON_SEMANTIC"],"readOnly":false},"SemanticQueryLanguageVersion":{"type":"string","enum":["V1"],"readOnly":false},"SemanticContextualTargetingQueryContentResource":{"type":"object"},"errorResponse":{"type":"object","properties":{"status":{"type":"string","enum":["error"]},"error_code":{"type":"string","enum":["AUTHENTICATION_ERROR","AUTHORIZATION_ERROR","BAD_REQUEST_DATA","BAD_REQUEST_FORMAT","CONSTRAINT_VIOLATION_EXCEPTION","EMAIL_ALREADY_EXISTS","MAC_ERROR","RESOURCE_NOT_FOUND","SERVICE_UNAVAILABLE","TOKEN_ERROR"]},"error_id":{"type":"string"},"error":{"type":"string"}},"required":["error","error_code","error_id","status"]}},"responses":{"error":{"description":"Error response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errorResponse"}}}}}}}
```

## PUT /organisations/{organisation\_id}/contextual/queries/{query\_id}

> Update a semantic contextual targeting query

```json
{"openapi":"3.1.1","info":{"title":"mediarithmics openapi API","version":"1.0.0"},"tags":[{"name":"Contextual Targeting Queries","description":"Operations related to Contextual Targeting Queries for defining and managing contextual targeting rules based on keywords, entities, and IAB categories. Supports flexible keyword matching (comma-separated, case-insensitive, accent-sensitive) with up to 2,000 keywords per targeting list for precise content-based audience identification."}],"servers":[{"url":"http://api.mediarithmics.local/v1","description":"Development server"},{"url":"https://api.mediarithmics.com/v1","description":"Production server"}],"paths":{"/organisations/{organisation_id}/contextual/queries/{query_id}":{"put":{"description":"","summary":"Update a semantic contextual targeting query","tags":["Contextual Targeting Queries"],"operationId":"updateSemanticContextualTargetingQuery","responses":{"200":{"description":"Success !","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string","enum":["ok"]},"data":{"$ref":"#/components/schemas/SemanticContextualTargetingQueryResource"}},"required":["data","status"]}}}},"400":{"$ref":"#/components/responses/error"},"401":{"$ref":"#/components/responses/error"},"403":{"$ref":"#/components/responses/error"},"404":{"$ref":"#/components/responses/error"},"500":{"$ref":"#/components/responses/error"},"503":{"$ref":"#/components/responses/error"}},"requestBody":{"description":"The JSON query as text and its version","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SemanticContextualTargetingQueryResource"}}},"required":true},"parameters":[{"schema":{"type":"integer","format":"int64"},"name":"organisation_id","explode":false,"in":"path","style":"simple","required":true},{"schema":{"type":"integer","format":"int64"},"required":true,"name":"query_id","explode":false,"in":"path","style":"simple"}]}}},"components":{"schemas":{"SemanticContextualTargetingQueryResource":{"type":"object","properties":{"last_modified_ts":{"type":"integer","format":"int64","default":0,"readOnly":true},"last_modified_by":{"type":"string","readOnly":true},"created_ts":{"type":"integer","format":"int64","default":0,"readOnly":true},"organisation_id":{"type":"string","readOnly":true},"id":{"type":"string","readOnly":true},"created_by":{"type":"string","readOnly":true},"query_data":{"$ref":"#/components/schemas/SemanticContextualTargetingQueryDataResource"}},"required":["created_by","created_ts","id","organisation_id","query_data"]},"SemanticContextualTargetingQueryDataResource":{"type":"object","properties":{"language_name":{"$ref":"#/components/schemas/SemanticQueryLanguage"},"language_version":{"$ref":"#/components/schemas/SemanticQueryLanguageVersion"},"query":{"$ref":"#/components/schemas/SemanticContextualTargetingQueryContentResource"}},"required":["language_name","language_version","query"]},"SemanticQueryLanguage":{"type":"string","enum":["JSON_SEMANTIC"],"readOnly":false},"SemanticQueryLanguageVersion":{"type":"string","enum":["V1"],"readOnly":false},"SemanticContextualTargetingQueryContentResource":{"type":"object"},"errorResponse":{"type":"object","properties":{"status":{"type":"string","enum":["error"]},"error_code":{"type":"string","enum":["AUTHENTICATION_ERROR","AUTHORIZATION_ERROR","BAD_REQUEST_DATA","BAD_REQUEST_FORMAT","CONSTRAINT_VIOLATION_EXCEPTION","EMAIL_ALREADY_EXISTS","MAC_ERROR","RESOURCE_NOT_FOUND","SERVICE_UNAVAILABLE","TOKEN_ERROR"]},"error_id":{"type":"string"},"error":{"type":"string"}},"required":["error","error_code","error_id","status"]}},"responses":{"error":{"description":"Error response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errorResponse"}}}}}}}
```

## POST /organisations/{organisation\_id}/contextual/queries

> Create a semantic contextual targeting query

```json
{"openapi":"3.1.1","info":{"title":"mediarithmics openapi API","version":"1.0.0"},"tags":[{"name":"Contextual Targeting Queries","description":"Operations related to Contextual Targeting Queries for defining and managing contextual targeting rules based on keywords, entities, and IAB categories. Supports flexible keyword matching (comma-separated, case-insensitive, accent-sensitive) with up to 2,000 keywords per targeting list for precise content-based audience identification."}],"servers":[{"url":"http://api.mediarithmics.local/v1","description":"Development server"},{"url":"https://api.mediarithmics.com/v1","description":"Production server"}],"paths":{"/organisations/{organisation_id}/contextual/queries":{"post":{"tags":["Contextual Targeting Queries"],"description":"","summary":"Create a semantic contextual targeting query","parameters":[{"style":"simple","in":"path","schema":{"type":"integer","format":"int64"},"name":"organisation_id","explode":false,"required":true}],"operationId":"createSemanticContextualTargetingQuery","responses":{"200":{"description":"Success !","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string","enum":["ok"]},"data":{"$ref":"#/components/schemas/SemanticContextualTargetingQueryResource"}},"required":["data","status"]}}}},"400":{"$ref":"#/components/responses/error"},"401":{"$ref":"#/components/responses/error"},"403":{"$ref":"#/components/responses/error"},"404":{"$ref":"#/components/responses/error"},"500":{"$ref":"#/components/responses/error"},"503":{"$ref":"#/components/responses/error"}},"requestBody":{"description":"The JSON query as text and its version","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SemanticContextualTargetingQueryResource"}}},"required":true}}}},"components":{"schemas":{"SemanticContextualTargetingQueryResource":{"type":"object","properties":{"last_modified_ts":{"type":"integer","format":"int64","default":0,"readOnly":true},"last_modified_by":{"type":"string","readOnly":true},"created_ts":{"type":"integer","format":"int64","default":0,"readOnly":true},"organisation_id":{"type":"string","readOnly":true},"id":{"type":"string","readOnly":true},"created_by":{"type":"string","readOnly":true},"query_data":{"$ref":"#/components/schemas/SemanticContextualTargetingQueryDataResource"}},"required":["created_by","created_ts","id","organisation_id","query_data"]},"SemanticContextualTargetingQueryDataResource":{"type":"object","properties":{"language_name":{"$ref":"#/components/schemas/SemanticQueryLanguage"},"language_version":{"$ref":"#/components/schemas/SemanticQueryLanguageVersion"},"query":{"$ref":"#/components/schemas/SemanticContextualTargetingQueryContentResource"}},"required":["language_name","language_version","query"]},"SemanticQueryLanguage":{"type":"string","enum":["JSON_SEMANTIC"],"readOnly":false},"SemanticQueryLanguageVersion":{"type":"string","enum":["V1"],"readOnly":false},"SemanticContextualTargetingQueryContentResource":{"type":"object"},"errorResponse":{"type":"object","properties":{"status":{"type":"string","enum":["error"]},"error_code":{"type":"string","enum":["AUTHENTICATION_ERROR","AUTHORIZATION_ERROR","BAD_REQUEST_DATA","BAD_REQUEST_FORMAT","CONSTRAINT_VIOLATION_EXCEPTION","EMAIL_ALREADY_EXISTS","MAC_ERROR","RESOURCE_NOT_FOUND","SERVICE_UNAVAILABLE","TOKEN_ERROR"]},"error_id":{"type":"string"},"error":{"type":"string"}},"required":["error","error_code","error_id","status"]}},"responses":{"error":{"description":"Error response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errorResponse"}}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.mediarithmics.io/api-reference/contextual-targeting/contextual-targeting-queries.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
