> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/web-application-and-api-protection/integrations/ci-cd/harness-code-integration.md). Agents can also search and read this documentation through its [MCP server](https://developer.harness.io/~gitbook/mcp).

# Harness Code Integration

Connect the Harness Run-time Protection Agent with Harness Code repositories using an API key to scan code repositories

Your repositories show how your APIs are built, which endpoints exist, and how they handle data. The Harness Code integration connects Harness Run-time Protection Agent (RPA) with your Harness Code repositories so that Harness RPA can scan and analyze that code for API security testing.

{% hint style="info" %}

* You can configure one or more Harness Code integrations in your Harness account.
* You can optionally limit each integration to a specific organization or project.
  {% endhint %}

***

## What you will learn from this topic

By the end of this topic, you will be able to understand:

* The purpose of the Harness Code integration and what it enables in your API security workflow.
* The information you need to retrieve from Harness before you begin, including how to generate an API token.
* The steps to add and validate the Harness Code integration in Harness RPA.
* How to verify that the integration is connected.
* How to use the integration to scan your repositories.

***

## Before you begin

Before you proceed to configure Harness Code, make a note of the following:

* Make sure you have the *Settings* RBAC permissions under **Administration** → **Integrations** to configure the integration. For more information, go to [Team and roles - RBAC](https://developer.harness.io/web-application-and-api-protection/settings/configuration/teams/role-based-access-control-rbac.md).
* Make sure you can access the Harness Code repositories that you want to scan. Harness RPA can only see the repositories that your API token can access.
* Retrieve the following information from Harness, as you will require it later when you configure the integration:
  * **Harness base URL**: The address of your Harness instance in the browser, for example `https://app.harness.io`. Harness RPA uses it to find the Harness environment that hosts your repositories.
  * **Harness account ID**: Log in to Harness and open the accounts page. Your account ID appears in the page URL. It identifies the account whose repositories Harness RPA connects to.\ <img src="https://1414883571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fdr7UJpJrdGkkSGT6AFTu%2Fuploads%2FZZYjhlFgmriqqlRXa756%2FHarness_account_id.png?alt=media&amp;token=435b751b-cbd6-4f67-a06a-5cfff43122e4" alt="" data-size="original">
  * **API token**: Harness RPA uses the token to authenticate and read your repositories. To generate an API token:
    1. Log in to your Harness account and click your user icon at the bottom left of the page.
    2. Create an API key and generate a token.
    3. Copy the token and store it in a secure place.\
       ![](https://1414883571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fdr7UJpJrdGkkSGT6AFTu%2Fuploads%2FdwKI91YnX2fcEgldfOIQ%2FHarness_code_api_key_generation.png?alt=media\&token=1b55837d-8024-49d9-b49f-ccf587698f60)
  * **Organization ID and Project ID** (optional): The identifiers of the organization or project that you want to limit access to.

{% hint style="info" %}
Make sure you securely save your API token, as you will need it to configure the integration.
{% endhint %}

***

## Configuration

You can configure the Harness Code integration by completing the following steps in Harness RPA:

### Step 1: Navigation

To navigate to Harness Code Integration, complete the following steps:

<figure><img src="https://1414883571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fdr7UJpJrdGkkSGT6AFTu%2Fuploads%2FmmrGQTVH6J6y6wMJZ0Fr%2FRPA_CICD_integration_harness_code-nav.png?alt=media&amp;token=7400bd3c-a27b-45d7-8d67-895aa4c0ff7e" alt="" width="563"><figcaption><p>Navigation</p></figcaption></figure>

1. Log in to your Harness RPA account and navigate to **Settings** → **Integrations** → **CI/CD Integrations**.
2. On the **Harness Code Integration** widget, click **Configure**.

### Step 2: Add a new integration

This opens an **Add New Harness Code Integration** slide-out panel. Specify the details you retrieved in <a href="#before-you-begin" target="_self">Before you begin</a>.

<figure><img src="https://1414883571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fdr7UJpJrdGkkSGT6AFTu%2Fuploads%2Febk5bd0k1h5jX91urDOf%2FHarness_code_integration.png?alt=media&amp;token=77285909-eacb-4e1a-8ec9-14dbd28190b4" alt="" width="563"><figcaption><p>Harness Code Integration</p></figcaption></figure>

The following table describes the fields and their descriptions:

| Field                          | Description                                                                               |
| ------------------------------ | ----------------------------------------------------------------------------------------- |
| **Harness base URL**           | The base URL of your Harness instance.                                                    |
| **Harness account ID**         | Your Harness account ID. For more information, see [Before you begin](#before-you-begin). |
| **API key**                    | The API token you generated from the harness account                                      |
| **Organization ID** (optional) | The ID of a specific Harness organization.                                                |
| **Project ID** (optional)      | The ID of a specific Harness project.                                                     |

### Step 3: Validate and save the integration

To validate the details, complete the following:

1. Click **Validate**.
2. Click **Save** to complete the integration setup.

***

## Verification

After you complete the integration setup, verify that Harness RPA successfully connects to Harness Code. To verify, complete the following steps:

1. In your Harness RPA account, navigate to **Settings** → **Integrations** → **Repositories**.
2. Locate your Harness Code integration in the list.
3. Confirm that the integration status displays **Connected** or **Active**.

If validation or the integration status shows an error, check the items in the following table:

| Validation Error                   | Troubleshooting                                                              | Why it matters                                                        |
| ---------------------------------- | ---------------------------------------------------------------------------- | --------------------------------------------------------------------- |
| **Base URL and account ID**        | No typos or extra spaces, and the values match the ones you retrieved.       | A small mismatch prevents Harness RPA from finding your account.      |
| **API token**                      | The token is complete, has not expired, and has access to your repositories. | An expired or incomplete token cannot authenticate.                   |
| **Organization ID and Project ID** | The values match your Harness setup exactly.                                 | An incorrect scope can hide your repositories or fail the connection. |

***

## Use your Harness Code Integration

After your Harness Code integration is active, you reference it when creating API security scans or configuring repository-based workflows. For more information, go to <a href="https://developer.harness.io/web-application-and-api-protection-waap-discovery-discovery-discovery-discovery/discovery/discovery-1/inventory/beta-api-discovery-from-code.md" target="_blank">API Discovery from code</a>.

When you create a scan or configure a workflow that requires repository access:

1. Select the repository source option or integration configuration field.
2. Choose your Harness Code integration from the list of available integrations.
3. Select the repository and branch you want to scan.

{% hint style="info" %}

* Only repositories that your API token can access appear in the repository list.
* If you set an organization or project scope, only repositories within that scope appear.
  {% endhint %}

***

## Demo

The following interactive demo walks you through the steps to navigate and integrate Harness Code:

{% @arcade/embed url="<https://app.arcade.software/share/dSvcudcvCeqeLH0pPXjK>" flowId="dSvcudcvCeqeLH0pPXjK" %}

***

## Next steps

After integrating Harness Code Integration, you can:

* Navigate to the scan repository and perform testing. For more information, see [API Discovery from code.](https://developer.harness.io/web-application-and-api-protection/discovery/discovery-1/inventory/beta-api-discovery-from-code.md)
* You can begin creating a scan. For more information, see [Creating a scan](https://developer.harness.io/web-application-and-api-protection/api-security-testing/ast-basics-and-workflow/creating-a-scan.md).

{% @harness-feedback/feedback module="web-application-and-api-protection" pagePath="web-application-and-api-protection/integrations/ci-cd/harness-code-integration" %}
