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

# Snyk Connection Instructions

> Instructions on how to onboard a Snyk Integration

## Snyk App

Leen supports Snyk integrations via OAuth2 and API Keys for both Snyk US, Snyk US-2, and Snyk EU. To integrate with Snyk, users will have to authorize Leen's Snyk app or provide a valid API key. This will allow Leen to access the appropriate Snyk resources in your account.
When using OAuth2, Leen takes care of the code-flow and access token management, so you don't have to worry about it.

<Warning>
  Snyk currently does not offer their V1 API in the EU region. If you are an EU customer, you may experience slight degradation in Leen's data mappings when compared to the US. Here are all the fields that Leen will not be able to map for EU customers:

  * `package_name`
  * `package_version`
  * `platform`
  * `publication_time`
  * `is_patchable`
  * `cvss_score`
  * `remediation`
</Warning>

## Onboarding

Follow the steps below to onboard a user to our Snyk Integration.

<Steps>
  <Step title="Create Snyk Connection using OAuth flow">
    With your Leen API Key and your Customer's Org ID, make an API request to create a new Snyk Connection.
    More information can be found on the [API Reference page.](/api-reference/provisioning/add-new-connection)

    <Accordion title="Example POST body and response">
      ```json theme={null}
          {
            "vendor": "SNYK",
            "credentials": {
                "base_url": "https://app.us.snyk.io", // OPTIONAL: only needed for US-2 and EU regions
            }
          }
      ```

      The response will look like this:

      ```json theme={null}
      {
        "id": "e73fd0f2-9c4a-4911-923a-c07a3a3fa414",
        "vendor": "SNYK",
        "refresh_interval_secs": 14400,
        "timeout_secs": 1800,
        "organization_id": "5718a24d-f9c8-4276-af80-088ac433e28f",
        "oauth2_authorize_url": "https://app.snyk.io/oauth2/authorize?....."
        }
      ```
    </Accordion>
  </Step>

  <Step title="Redirect User to Snyk">
    Redirect the user to the `oauth2_authorize_url` from the previous step in a new tab.
    This will prompt the user to authorize Leen's Snyk app to access their Snyk resources.

    <img src="https://mintcdn.com/leen/v5iddL0dhlngJwjt/images/snyk_auth_page.png?fit=max&auto=format&n=v5iddL0dhlngJwjt&q=85&s=2a47a855af87a468e1ac1502b3c8455a" alt="snyk-auth" width="1142" height="1398" data-path="images/snyk_auth_page.png" />

    Once the user has authorized the app, they will be redirected to Leen on a successful authorization.

    <img src="https://mintcdn.com/leen/vQ2Rhs44KY1LGMJC/images/leen_callback_success.png?fit=max&auto=format&n=vQ2Rhs44KY1LGMJC&q=85&s=355885a6b3c2e9907369a1ad2e974c56" alt="snyk-auth-success" width="990" height="1196" data-path="images/leen_callback_success.png" />
  </Step>

  <Step title="Pull Data">
    Now that the user has authorized the app, you can pull data from Snyk using the `connection_id` from the first step.
    More information can be found on the [API Reference page.](/api-reference/appsec/get-issues)
  </Step>
</Steps>

### API Key Authentication

<Steps>
  <Step title="Navigate to Organization Settings in Snyk">
    In the Snyk organization you want to connect, go to Settings and click "Manage Service Accounts".

    <img src="https://mintcdn.com/leen/1keOiZmITOkq8beG/images/snyk/manage-svc-account.png?fit=max&auto=format&n=1keOiZmITOkq8beG&q=85&s=c42c4106e1a408167dd87588a12dc121" alt="snyk-manage-svc-account" width="2660" height="1201" data-path="images/snyk/manage-svc-account.png" />
  </Step>

  <Step title="Create an API Key for the Snyk Organization">
    Under Service Accounts, enter a name, select **Org Admin** as the role, and choose **API Key (no expiry)**.
    Click "Create service account".

    <img src="https://mintcdn.com/leen/1keOiZmITOkq8beG/images/snyk/api-key-options.png?fit=max&auto=format&n=1keOiZmITOkq8beG&q=85&s=3843fb0b8b6439d1dcf785e9572aac6c" alt="snyk-manage-svc-account" width="3575" height="1324" data-path="images/snyk/api-key-options.png" />

    <Note>
      Repeat for each Snyk organization you want to include, or use a group-level service account if applicable.
    </Note>
  </Step>

  <Step title="Create Snyk Connection using API Key">
    With your Leen API Key and your Customer's Org ID, make an API request to create a new Snyk Connection with the API token created in the previous step.
    More information can be found on the [API Reference page.](/api-reference/provisioning/add-new-connection)

    <Accordion title="Example POST body and response">
      ```json theme={null}
      {
          "vendor": "SNYK",
          "credentials": {
              "base_url": "https://app.us.snyk.io", // OPTIONAL: only needed for US-2 and EU regions
              "api_token": "..."
          }
      }
      ```

      The response will look like this:

      ```json theme={null}
      {
          "id": "e73fd0f2-9c4a-4911-923a-c07a3a3fa414",
          "vendor": "SNYK",
          "refresh_interval_secs": 14400,
          "timeout_secs": 1800,
          "organization_id": "5718a24d-f9c8-4276-af80-088ac433e28f",
      }
      ```
    </Accordion>
  </Step>

  <Step title="Pull Data">
    Now that the connection has been created, you can pull data from Snyk using the `connection_id` from the previous step.
    More information can be found on the [API Reference page.](/api-reference/appsec/get-issues)
  </Step>
</Steps>
