> ## Documentation Index
> Fetch the complete documentation index at: https://developers.criteo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Negative Keyword Targeting

export const EndpointBadge = ({method = "GET", children}) => {
  const METHOD_STYLES = {
    GET: {
      bg: "mint-bg-[#2AB673]"
    },
    POST: {
      bg: "mint-bg-[#3064E3]"
    },
    PUT: {
      bg: "mint-bg-[#C28C30]"
    },
    PATCH: {
      bg: "mint-bg-[#DA622B]"
    },
    DELETE: {
      bg: "mint-bg-[#CB3A32]"
    },
    API: {
      bg: "mint-bg-black"
    }
  };
  const key = method.toUpperCase();
  const styles = METHOD_STYLES[key] ?? METHOD_STYLES.API;
  return <div className="relative mt-7">
      <span className={`absolute -top-2 -left-2 z-10 ${styles.bg} text-white px-2.5 py-0.5 rounded-full text-xs font-bold tracking-wide`}>
        {key}
      </span>
      {children}
    </div>;
};

<Note>
  **Getting Started**

  For an overview, read more about how [**Negative Keyword Targeting**](https://help.retailmedia.criteo.com/kb/guide/en/negative-keyword-targeting-zgMmEUbU8V/Steps/1208564) works in our Help Center
</Note>

 

## **Endpoints**

<table>
  <thead>
    <tr>
      <th>
        <p>
          Verb
        </p>
      </th>

      <th>
        <p>
          Endpoint
        </p>
      </th>

      <th>
        <p>
          Description
        </p>
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        <p>
          <b>
            GET
          </b>
        </p>
      </td>

      <td>
        <p>
          <code>
            /auction-line-items/\{line-item-id}/targeting/keywords
          </code>
        </p>
      </td>

      <td>
        <p>
          Get All Negated Keywords on a specific Line Item
        </p>
      </td>
    </tr>

    <tr>
      <td>
        <p>
          <b>
            POST
          </b>
        </p>
      </td>

      <td>
        <p>
          <code>
            /auction-line-items/\{line-item-id}/targeting/keywords/append
          </code>
        </p>
      </td>

      <td>
        <p>
          Add Negated Keywords to a Specific Line Item
        </p>
      </td>
    </tr>

    <tr>
      <td>
        <p>
          <b>
            POST
          </b>
        </p>
      </td>

      <td>
        <p>
          <code>
            /auction-line-items/\{line-item-id}/targeting/keywords/delete
          </code>
        </p>
      </td>

      <td>
        <p>
          Remove Negated Keywords from a Specific Line Item
        </p>
      </td>
    </tr>
  </tbody>
</table>

 

 

## **Negated Keyword Attributes**

<table>
  <thead>
    <tr>
      <th>
        <p>
          Attribute
        </p>
      </th>

      <th>
        <p>
          Data Type
        </p>
      </th>

      <th>
        <p>
          Description
        </p>
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        <p>
          <code>
            keywords
          </code>

          <span>\*</span>
        </p>
      </td>

      <td>
        <p>
          object
        </p>
      </td>

      <td>
        <p>
          Keywords structure, with dictionary of keywords and

          <code>
            matchType
          </code>

          pairs
        </p>

        <p>
          Possible match types for those endpoints:

          <code>
            negativeExact
          </code>

          and

          <code>
            negativeBroad
          </code>
        </p>
      </td>
    </tr>
  </tbody>
</table>

*\*Required*

<br />

## **Get all Negated Keywords on a Line item**

This endpoint list all negated keywords to an Onsite Sponsored Products Line item

<EndpointBadge method="get">
  ```http theme={null}
  https://api.criteo.com/{version}/retail-media/auction-line-items/{line-item-id}/targeting/keywords
  ```
</EndpointBadge>

**Sample Request**

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://api.criteo.com/{version}/retail-media/auction-line-items/2465695028166499188/targeting/keywords" \
      -H "Authorization: Bearer <MY_ACCESS_TOKEN>"
  ```

  ```php PHP theme={null}
  <?php
  require_once 'HTTP/Request2.php';
  $request = new HTTP_Request2();
  $request->setUrl('https://api.criteo.com/{version}/retail-media/auction-line-items/325713346766241792/targeting/keywords');
  $request->setMethod(HTTP_Request2::METHOD_GET);
  $request->setConfig(array(
    'follow_redirects' => TRUE
  ));
  $request->setHeader(array(
    'Accept' => 'application/json',
    'Authorization' => 'Bearer <MY_ACCESS_TOKEN>'
  ));
  try {
    $response = $request->send();
    if ($response->getStatus() == 200) {
      echo $response->getBody();
    }
    else {
      echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
      $response->getReasonPhrase();
    }
  }
  catch(HTTP_Request2_Exception $e) {
    echo 'Error: ' . $e->getMessage();
  }
  ```

  ```java Java theme={null}
  OkHttpClient client = new OkHttpClient().newBuilder()
    .build();

  MediaType mediaType = MediaType.parse("text/plain");

  RequestBody body = RequestBody.create(mediaType, "");

  Request request = new Request.Builder()
    .url("https://api.criteo.com/{version}/retail-media/auction-line-items/325713346766241792/targeting/keywords")
    .method("GET", body)
    .addHeader("Accept", "application/json")
    .addHeader("Authorization", "Bearer <MY_ACCESS_TOKEN>")
    .build();

  Response response = client.newCall(request).execute();
  ```

  ```python Python theme={null}
  import requests

  url = "https://api.criteo.com/{version}/retail-media/auction-line-items/325713346766241792/targeting/keywords"

  payload={}
  headers = {
    'Accept': 'application/json',
    'Authorization': 'Bearer <MY_ACCESS_TOKEN>'
  }

  response = requests.request("GET", url, headers=headers, data=payload)

  print(response.text)
  ```
</CodeGroup>

**Sample Response**

```json theme={null}
{
    "data": {
        "type": "RetailMediaKeywordTarget",
        "id": "2465695028166499188",
        "attributes": {
            "keywords": {
                "chips": "negativeExact",
                "soda": "negativeBroad"
            }
        }
    },
    /* omitted if no errors */
    "errors": [],
    /* omitted if no warnings */
    "warnings": []
}
```

<br />

## **Add Negated Keywords on a Line item**

This endpoint adds negated keywords to an Onsite Sponsored Products Line item

<EndpointBadge method="post">
  ```http theme={null}
  https://api.criteo.com/{version}/retail-media/auction-line-items/{line-item-id}/targeting/keywords/append
  ```
</EndpointBadge>

**Sample Request**

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://api.criteo.com/{version}/retail-media/auction-line-items/2465695028166499188/targeting/keywords/append" \
      -H "Authorization: Bearer <MY_ACCESS_TOKEN>" \
      -H "Content-Type: application/json" \
      -d '{
              "data": [
                  {
                      "type": "RetailMediaKeywordTarget",
                      "attributes": {
                          "keywords": {
                              "chips": "negativeExact",
                              "soda": "negativeBroad"
                          }
                      }
                  }
              ]
          }'
  ```

  ```python Python theme={null}
  import requests
  import json

  url = "https://api.criteo.com/{version}/retail-media/auction-line-items/325713346766241792/targeting/keywords/append"

  payload = json.dumps({
    "data": {
      "type": "<string>",
      "attributes": {
        "keywords": {
          "pasta": "NegativeExact",
          "juice": "NegativeBroad"
        }
      }
    }
  })
  headers = {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'Authorization': 'Bearer <MY_ACCESS_TOKEN>'
  }

  response = requests.request("POST", url, headers=headers, data=payload)

  print(response.text)
  ```

  ```java Java theme={null}
  OkHttpClient client = new OkHttpClient().newBuilder()
    .build();

  MediaType mediaType = MediaType.parse("application/json");

  RequestBody body = RequestBody.create(mediaType, "{\n  \"data\": {\n    \"type\": \"<string>\",\n    \"attributes\": {\n      \"keywords\": {\n        \"pasta\": \"NegativeExact\",\n        \"juice\": \"NegativeBroad\"\n      }\n    }\n  }\n}");

  Request request = new Request.Builder()
    .url("https://api.criteo.com/{version}/retail-media/auction-line-items/325713346766241792/targeting/keywords/append")
    .method("POST", body)
    .addHeader("Content-Type", "application/json")
    .addHeader("Accept", "application/json")
    .addHeader("Authorization", "Bearer <MY_ACCESS_TOKEN>")
    .build();

  Response response = client.newCall(request).execute();
  ```

  ```php PHP theme={null}
  <?php
  require_once 'HTTP/Request2.php';
  $request = new HTTP_Request2();
  $request->setUrl('https://api.criteo.com/{version}/retail-media/auction-line-items/325713346766241792/targeting/keywords/append');
  $request->setMethod(HTTP_Request2::METHOD_POST);
  $request->setConfig(array(
    'follow_redirects' => TRUE
  ));
  $request->setHeader(array(
    'Content-Type' => 'application/json',
    'Accept' => 'application/json',
    'Authorization' => 'Bearer <MY_ACCESS_TOKEN>'
  ));
  $request->setBody('{\n  "data": {\n    "type": "<string>",\n    "attributes": {\n      "keywords": {\n        "pasta": "NegativeExact",\n        "juice": "NegativeBroad"\n      }\n    }\n  }\n}');
  try {
    $response = $request->send();
    if ($response->getStatus() == 200) {
      echo $response->getBody();
    }
    else {
      echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
      $response->getReasonPhrase();
    }
  }
  catch(HTTP_Request2_Exception $e) {
    echo 'Error: ' . $e->getMessage();
  }
  ```
</CodeGroup>

**Sample Response**

```json theme={null}
{
    "data": {
        "type": "RetailMediaKeywordTarget",
        "id": "2465695028166499188",
        "attributes": {
            "keywords": {
                "chips": "negativeExact",
                "soda": "negativeBroad"
            }
        }
    },
    /* omitted if no errors */
    "errors": [],
    /* omitted if no warnings */
    "warnings": []
}
```

<br />

## **Remove Negated Keywords on a Line Item**

This endpoint removes previously negated keywords (as a result, these keywords might be targeted)

<EndpointBadge method="post">
  ```http theme={null}
  https://api.criteo.com/{version}/retail-media/auction-line-items/{line-item-id}/targeting/keywords/delete
  ```
</EndpointBadge>

**Sample Request**

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://api.criteo.com/{version}/retail-media/auction-line-items/2465695028166499188/targeting/keywords/delete" \
      -H "Authorization: Bearer <MY_ACCESS_TOKEN>" \
      -H "Content-Type: application/json" \
      -d '{
              "data": [
                  {
                      "type": "RetailMediaPromotedProduct",
                      "attributes": {
                          "keywords": {
                              "chips": "negativeExact"
                          }
                      }
                  }
              ]
          }'
  ```

  ```python Python theme={null}
  import requests
  import json

  url = "https://api.criteo.com/{version}/retail-media/auction-line-items/325713346766241792/targeting/keywords/delete"

  payload = json.dumps({
    "data": {
      "type": "<string>",
      "attributes": {
        "keywords": {
          "apple": "negativeBroad",
          "juice": "NegativeBroad"
        }
      }
    }
  })
  headers = {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'Authorization': 'Bearer <MY_ACCESS_TOKEN>'
  }

  response = requests.request("POST", url, headers=headers, data=payload)

  print(response.text)
  ```

  ```java Java theme={null}
  OkHttpClient client = new OkHttpClient().newBuilder()
    .build();

  MediaType mediaType = MediaType.parse("application/json");

  RequestBody body = RequestBody.create(mediaType, "{\n  \"data\": {\n    \"type\": \"<string>\",\n    \"attributes\": {\n      \"keywords\": {\n        \"apple\": \"negativeBroad\",\n        \"juice\": \"NegativeBroad\"\n      }\n    }\n  }\n}");

  Request request = new Request.Builder()
    .url("https://api.criteo.com/{version}/retail-media/auction-line-items/325713346766241792/targeting/keywords/delete")
    .method("POST", body)
    .addHeader("Content-Type", "application/json")
    .addHeader("Accept", "application/json")
    .addHeader("Authorization", "Bearer <MY_ACCESS_TOKEN>")
    .build();

  Response response = client.newCall(request).execute();
  ```

  ```php PHP expandable theme={null}
  <?php
  require_once 'HTTP/Request2.php';
  $request = new HTTP_Request2();
  $request->setUrl('https://api.criteo.com/{version}/retail-media/auction-line-items/325713346766241792/targeting/keywords/delete');
  $request->setMethod(HTTP_Request2::METHOD_POST);
  $request->setConfig(array(
    'follow_redirects' => TRUE
  ));

  $request->setHeader(array(
    'Content-Type' => 'application/json',
    'Accept' => 'application/json',
    'Authorization' => 'Bearer <MY_ACCESS_TOKEN>'
  ));

  $request->setBody('{\n  "data": {\n    "type": "<string>",\n    "attributes": {\n      "keywords": {\n        "apple": "negativeBroad",\n        "juice": "NegativeBroad"\n      }\n    }\n  }\n}');
  try {
    $response = $request->send();
    if ($response->getStatus() == 200) {
      echo $response->getBody();
    }
    
    else {
      echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
      $response->getReasonPhrase();
    }
  }

  catch(HTTP_Request2_Exception $e) {
    echo 'Error: ' . $e->getMessage();
  }
  ```
</CodeGroup>

**Sample Response**

```json theme={null}
{
    "data": [
        {
            "type": "RetailMediaPromotedProduct",
            "attributes": {
                "keywords": {
                    "chips": "negativeBroad"
                }
            }
        }
    ],
    "metadata": {
        "totalItemsAcrossAllPages": 4,
        "currentPageSize": 4,
        "currentPageIndex": 0,
        "totalPages": 1,
        "nextPage": null,
        "previousPage": null
    }
}
```

<br />

## **Responses**

<table>
  <thead>
    <tr>
      <th>
        <p>
          Response
        </p>
      </th>

      <th>
        <p>
          Description
        </p>
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        <p>
          🔵
        </p>

        <p>
          <code>
            200
          </code>
        </p>
      </td>

      <td>
        <p>
          Call completed with success
        </p>
      </td>
    </tr>

    <tr>
      <td>
        <p>
          🔴
        </p>

        <p>
          <code>
            400
          </code>
        </p>
      </td>

      <td>
        <p>
          Bad request, validation error
        </p>
      </td>
    </tr>
  </tbody>
</table>
