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

# Activation Integration

> Call the Research Defender Activation API with a POST request, authorized with your key in the x-api-key header.

## Overview

The Activation API switches the SEARCH duplicate check off or on for the traffic you specify. This guide shows how to send the request with `POST`, passing the parameters as a JSON body. Only `Type` is required.

Like the Activity API, the Activation API runs on `resdefio.com` and is authorized with an **authorization key** that you send in the `x-api-key` header. See [ACTIVATION](/research-defender/guides/activation/01-overview) for how the values combine and when a change takes effect.

## Authentication

Send your authorization key in the `x-api-key` header of every request.

<ParamField header="x-api-key" type="string" required>
  Your Research Defender authorization key.
</ParamField>

<Warning>
  Your authorization key is a secret. The sample on this page calls the API from the browser for demonstration, but anything in client-side code can be read. If you can, call the Activation API from your server and keep the key there.
</Warning>

## Endpoint

<ParamField path="Endpoint" type="string">
  `POST https://{environment}.resdefio.com/activation`
</ParamField>

| Environment | Endpoint |
| - | - |
| `prod` | `https://prod.resdefio.com/activation` |
| `stage` | `https://stage.resdefio.com/activation` |

In the sample, set `ENVIRONMENT` to `"prod"` or `"stage"`.

## Request body

Send the parameters as a JSON object. Separate several values in one parameter with commas.

<ParamField body="Type" type="string" required>
  `1` deactivates the matching traffic from the duplicate check. `2` activates it.
</ParamField>

<ParamField body="Route" type="string">
  The API the change applies to. `search` (SEARCH API) is the default.
</ParamField>

<ParamField body="Survey_Number" type="string">
  Survey numbers, separated by commas. For example `"111,222,333"`.
</ParamField>

<ParamField body="Session_Id" type="string">
  Session IDs. Optional.
</ParamField>

<ParamField body="IP_Address" type="string">
  IP address. Optional.
</ParamField>

<ParamField body="Cookie" type="string">
  Cookie value. Optional.
</ParamField>

<ParamField body="Panel_Id" type="string">
  Panel ID. Optional.
</ParamField>

<ParamField body="Hashed_Email" type="string">
  Hashed email address. Optional.
</ParamField>

<ParamField body="User_Agent" type="string">
  User agent. Optional.
</ParamField>

<Note>
  When you send more than one parameter, the values are combined and a record must match all of them. A request processes at most 500 combined records. To check values independently, send them in separate requests. See [How the values combine](/research-defender/guides/activation/01-overview#how-the-values-combine).
</Note>

### Sending more parameters

The sample sends `Route`, `Type`, and `Survey_Number`. To match on sessions or other values, set them at the top of the script and add them to the object in `buildPayload()`. For example, this body deactivates three sessions on any survey:

```json theme={null}
{
  "Route": "search",
  "Type": "1",
  "Session_Id": "0001,0002,0003"
}
```

## Response

```json theme={null}
{
  "Action": "DeActivated Successfully!",
  "Message": "Records Processed:4"
}
```

`Action` reports what was done, and `Message` reports how many records were processed.

## Example

<Tabs>
  <Tab title="JavaScript">
    ```javascript activation-post.js theme={null}
    // ---------------------------------------------------------------
    // Configuration
    // ---------------------------------------------------------------
    const ENVIRONMENT = "prod"; // "stage" or "prod"

    // Your authorization key, sent in the x-api-key header. Keep it secret.
    // This sample calls the API from the browser for demonstration only. Anything
    // in client-side code can be read, so call the API from your server if you can.
    const API_KEY = "YOUR_API_KEY";

    // 1 = deactivate from the duplicate check, 2 = activate.
    const TYPE = "1";

    // Values to match. Separate several values with commas.
    // Set a value to "" to leave it out of the request.
    const SURVEY_NUMBERS = "YOUR_SURVEY_NUMBER_1,YOUR_SURVEY_NUMBER_2"; // Survey_Number
    const SESSION_IDS = "";                                             // Session_Id

    const ACTIVATION_ENDPOINT = `https://${ENVIRONMENT}.resdefio.com/activation`;

    // ---------------------------------------------------------------
    // Helpers
    // ---------------------------------------------------------------

    /** Builds the request body. Empty values are left out. */
    function buildPayload() {
      const payload = {
        Route: "search",
        Type: TYPE,
        Survey_Number: SURVEY_NUMBERS,
        Session_Id: SESSION_IDS,
      };

      return Object.fromEntries(
        Object.entries(payload).filter(([, value]) => value !== "" && value != null)
      );
    }

    /** Parses a response body as JSON, or returns the raw text if it is not JSON. */
    function parseResponse(text) {
      try {
        return JSON.parse(text);
      } catch {
        return text;
      }
    }

    /** Sends the POST request and returns the parsed result. */
    async function setActivation(payload) {
      const response = await fetch(ACTIVATION_ENDPOINT, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "x-api-key": API_KEY, // authorization key
        },
        body: JSON.stringify(payload),
      });

      const text = await response.text();

      if (!response.ok) {
        throw new Error(`Activation request failed with status ${response.status}: ${text.slice(0, 300)}`);
      }

      return parseResponse(text);
    }

    // ---------------------------------------------------------------
    // Usage
    // ---------------------------------------------------------------
    const result = await setActivation(buildPayload());
    console.log("Activation result:", result);
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl -X POST "https://prod.resdefio.com/activation" \
      -H "Content-Type: application/json" \
      -H "x-api-key: YOUR_API_KEY" \
      -d '{
        "Route": "search",
        "Type": "1",
        "Survey_Number": "YOUR_SURVEY_NUMBER_1,YOUR_SURVEY_NUMBER_2"
      }'
    ```
  </Tab>
</Tabs>

The JavaScript example builds the body with `buildPayload()`, which leaves out empty values. `setActivation()` sends the request with the `Content-Type` and `x-api-key` headers and shows the API's message if the request fails.

## Full HTML page

If you want a complete page you can open in a browser, use the sample below. Replace the placeholder values at the top of the script.

<Accordion title="Activation integration with POST (HTML)">
  ```html activation-post-integration.html theme={null}
  <!DOCTYPE html>
  <html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Research Defender – Activation Integration (POST)</title>
  </head>
  <body>
    <h1>Research Defender – Activation Integration (POST)</h1>
    <pre id="output">Loading…</pre>

    <script>
      // ---------------------------------------------------------------
      // Configuration
      // ---------------------------------------------------------------
      const ENVIRONMENT = "prod"; // "stage" or "prod"

      // Your authorization key, sent in the x-api-key header. Keep it secret.
      // This sample calls the API from the browser for demonstration only. Anything
      // in client-side code can be read, so call the API from your server if you can.
      const API_KEY = "YOUR_API_KEY";

      // 1 = deactivate from the duplicate check, 2 = activate.
      const TYPE = "1";

      // Values to match. Separate several values with commas.
      // Set a value to "" to leave it out of the request.
      const SURVEY_NUMBERS = "YOUR_SURVEY_NUMBER_1,YOUR_SURVEY_NUMBER_2"; // Survey_Number
      const SESSION_IDS = "";                                             // Session_Id

      const ACTIVATION_ENDPOINT = `https://${ENVIRONMENT}.resdefio.com/activation`;

      // ---------------------------------------------------------------
      // Helpers
      // ---------------------------------------------------------------

      /** Builds the request body. Empty values are left out. */
      function buildPayload() {
        const payload = {
          Route: "search",
          Type: TYPE,
          Survey_Number: SURVEY_NUMBERS,
          Session_Id: SESSION_IDS,
        };

        return Object.fromEntries(
          Object.entries(payload).filter(([, value]) => value !== "" && value != null)
        );
      }

      /** Parses a response body as JSON, or returns the raw text if it is not JSON. */
      function parseResponse(text) {
        try {
          return JSON.parse(text);
        } catch {
          return text;
        }
      }

      /** Sends the POST request and returns the parsed result. */
      async function setActivation(payload) {
        const response = await fetch(ACTIVATION_ENDPOINT, {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
            "x-api-key": API_KEY, // authorization key
          },
          body: JSON.stringify(payload),
        });

        const text = await response.text();

        if (!response.ok) {
          throw new Error(`Activation request failed with status ${response.status}: ${text.slice(0, 300)}`);
        }

        return parseResponse(text);
      }

      // ---------------------------------------------------------------
      // Run
      // ---------------------------------------------------------------
      window.addEventListener("load", async () => {
        const output = document.getElementById("output");

        try {
          const result = await setActivation(buildPayload());

          console.log("Activation result:", result);
          output.textContent =
            typeof result === "string" ? result : JSON.stringify(result, null, 2);
        } catch (error) {
          console.error(error);
          output.textContent = `Error: ${error.message}`;
        }
      });
    </script>
  </body>
  </html>
  ```
</Accordion>

## Troubleshooting

| Symptom | Likely cause |
| - | - |
| The request is rejected with an authorization error | The `x-api-key` header is missing or the key is wrong. |
| A survey is still termed as a duplicate after deactivating it | SEARCH caches a respondent's first result for 3 hours. The change applies to transactions older than that. |
| Respondents are still checked after sending both `Survey_Number` and `Session_Id` | Both must match together. Send them in separate requests to check each independently. |
| The request is rejected for too many records | A request processes at most 500 combined records. Send fewer values per request. |
| The request is blocked in the browser | The browser could not complete the request to `resdefio.com`. Check the browser console, and consider calling the API from your server. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.