# Connect to Partners

Source: https://developers.bitgo.com/docs/oes-client-connect

## Overview

Create a connection to a partner platform, so you can trade assets, custodied at BitGo Bank & Trust, on their platform. In order to activate the partner in your Go Network, you must first have an account on the partner's platform. You can connect with multiple partners and you can also have multiple connections to the same partner.

You can [download](https://assets.bitgo.com/downloads/bitgo-oes-client.json) the BitGo OES Client Postman Collection and import it into [Postman](https://www.postman.com/) to quickly explore and test the OES client APIs.

## Prerequisites

* [Get Started](/docs/get-started-intro)
* Generate an access token and a read-only API key from your account on the partner platform

## Cookbook

Need just the steps? Expand the cookbook below to get started:

<Cookbook slug="oes-client-connect" title="Connect to Partners" />

## Steps

>Endpoint: [Connect to Partner](/reference/v1clientconnectionspostroute)


```shell cURL
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"
export ENTERPRISE_ID="<YOUR_ENTERPRISE_ID>"

curl -X POST \
  https://app.bitgo-test.com/api/network/v1/enterprises/$ENTERPRISE_ID/clients/connections \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer $ACCESS_TOKEN' \
  -d '{
    "payload": "string",
    "signature": "string",
    "nonce": "string",
    "partnerId": "string",
    "name": "string",
    "connectionKey": {
      "schema": "token",
      "connectionToken": "string"
    }
  }'
```
```js JavaScript
import { BitGoAPI } from '@bitgo/sdk-api';
import { Ecdsa } from '@bitgo/sdk-core/dist/src/bitgo/ecdsa';
import { createHash } from 'crypto';
import * as dotenv from 'dotenv';

const {
  ACCESS_TOKEN,
  ENTERPRISE_ID,
  PARTNER_ID,
  PARTNER_ACCESS_TOKEN,
  PARTNER_SIGNING_SECRET,
} = process.env;

const bitgo = new BitGoAPI({
  accessToken: ACCESS_TOKEN,
  env: 'test', // Use 'prod' for the production environment
  customRootURI: 'https://app.bitgo-test.com',
});

async function createClientConnection() {
  if (!ENTERPRISE_ID || !PARTNER_ID || !PARTNER_ACCESS_TOKEN || !PARTNER_SIGNING_SECRET) {
    console.error('Error: Missing required environment variables.');
    return;
  }

  try {
    console.log(`Fetching enterprise: ${ENTERPRISE_ID}`);
    const enterprise = await bitgo.enterprises().get({ id: ENTERPRISE_ID });

    console.log('Fetching signing payload from BitGo...');
    const { payload, nonce } = await enterprise.clientConnections().getSigningPayload({ partnerId: PARTNER_ID });
    console.log(`Received payload to sign: "${payload}"`);


    console.log('Signing the payload locally...');
    const ecdsa = new Ecdsa(PARTNER_SIGNING_SECRET);
    const payloadHash = createHash('sha256').update(payload).digest();
    const partnerSignature = ecdsa.sign(payloadHash).toString('hex');
    console.log('Generated Signature:', partnerSignature);
    
    
    const connectionParams = {
      payload: payload,        // The payload received from BitGo
      signature: partnerSignature, // Your generated signature of that payload
      nonce: nonce,          // The nonce received from BitGo

      partnerId: PARTNER_ID,
      name: 'My New API Connection', // A friendly name for the connection
      connectionKey: {
        schema: 'token',
        connectionToken: PARTNER_ACCESS_TOKEN,
      },
    };

    console.log('Sending signed request to create connection...');
    const connection = await enterprise.clientConnections().create(connectionParams);

    console.log('Connection created successfully!');
    console.dir(connection, { depth: null });

  } catch (error) {
    console.error('Failed to create connection:', error);
  }
}

createClientConnection();
```

#### Step Result

```json JSON
{
  "connection": {
    "createdAt": "2019-08-24",
    "updatedAt": "2019-08-24",
    "partnersConnectionId": "string",
    "partnersClientId": "string",
    "initialized": true,
    "id": "string",
    "name": "string",
    "clientId": "string",
    "partnerId": "string",
    "networkAccountId": "string",
    "active": true,
    "proof": "string",
    "nonce": "string"
  }
}
```

## Next

[Allocate Assets](/docs/oes-client-allocate)

## See Also

[API Reference: Connect to Partner](/reference/v1clientconnectionspostroute)
