Using the API to set up a GitHub connection

This page provides an example of using the API to set up a GitHub connection with the Universal Broker. Repeat connecting your Organization for as many integrations as needed.

Using the snyk-broker-config CLI tool is recommended for an easier experience. The API allows for automation and more control, and also requires a clear understanding of Broker deployments, credentials, connections, and integrations.

In any of the calls that follow, replace api.snyk.io with your regional equivalent if necessary, for example, api.eu.snyk.io. For a list of URLs, see API URLs.

Install the Broker app for your Organization

The Universal Broker App facilitates the secure connection and communication with the Broker server through OAuth.

Install the Broker app at the Organization level. Group-level installation is not supported. Use the endpoint Install a Snyk App to this Organization. Use the Snyk Broker App ID whenever you want to call the API. The Snyk Broker App ID differs for each region.

Create your deployment

Use the following call to create your deployment.

curl --location --request POST 'https://api.snyk.io/rest/tenants/TENANT_ID/brokers/installs/INSTALL_ID/deployments?version=2024-02-08~experimental' \
--header 'Content-Type: application/vnd.api+json' \
--header 'Authorization: token YOUR_SNYK_TOKEN' \
--data-raw '{
    "data": {
        "type": "broker_deployment",
        "attributes": {
            "broker_app_installed_in_org_id":"ORG_ID_WHERE_APP_WAS_INSTALLED",
            "metadata": {
                "deployment_name": "My Universal Broker Deployment",
                "cluster": "Cluster X Region Y or whatever you need to not lose your deployment."
            }
        }
    }
}'

This returns the DEPLOYMENT_ID (data.id), for example:

At this point, you can start running the Broker client.

Run your Broker deployment

Target your desired environment with the usual -e BROKER_SERVER_URL=https://broker.REGION.snyk.io \ if needed. For a list of URLs, see Broker server URLs.

When the command is running, you should get the following message in the output:

Create your credentials reference or references

This returns the credential reference id (data. id), for example:

You can create a maximum of ten credentials in one call by adding more objects in attributes. These objects can be of different types.

Create your connection or connections

This returns a Connection ID (data.id), as shown in the example. Note that this call returns the credential reference directly, ready for use, instead of the cred reference UUID.

If your credential reference is missing, you will get the following message:

When you update an environment variable you must restart your Broker. See Restart your Broker for a new environment variable.

You can now use the connection in an Organization integration.

Connect your Organization integration to use a connection

Repeat connecting your Organization for as many integrations as needed.

Last updated

Was this helpful?