# Link counterparty

Associate a counterparty with a shared payment method.

Adds a counterparty to a shared catalog instrument. The payment method must already be in shared association_mode. Parked instruments cannot be shared. Linking an already-associated counterparty is idempotent.


- HTTP method: `POST`
- Path: `/api/v1/payment-methods/:code/counterparties`
- URL: `https://api.invunion.com/api/v1/payment-methods/:code/counterparties`
- Required scope: `payment_methods:write`
- HTML docs: https://www.invunion.com/knowledge-base/api/link-payment-method-counterparty/
- Markdown docs: https://www.invunion.com/knowledge-base/api/link-payment-method-counterparty.md

## Path parameters

| Name | Type | Required | Description | Allowed values | Example |
| --- | --- | --- | --- | --- | --- |
| `code` | string, max 50 | required | Payment method code (`code`). |  | `PM-001` |


## Body parameters

| Name | Type | Required | Description | Allowed values | Example |
| --- | --- | --- | --- | --- | --- |
| `counterparty_id` | string, no maximum | required | Counterparty code (`account_code`) to associate. |  | `CPT-042` |

## Errors

| Error | HTTP code | Description |
| --- | --- | --- |
| `Missing Bearer token` | `401` | The Authorization header is missing or is not a Bearer token. |
| `Invalid or revoked API key` | `401` | The API key is unknown, malformed, expired, or has been revoked. |
| `API key is missing scope payment_methods:write` | `403` | The key does not include payment_methods:write. A write scope does not imply the matching read scope. |
| `Too many requests, please try again later` | `429` | Wait and retry. The Retry-After header is the number of seconds to wait. |
| `counterparty_id is required` | `400` | The body does not include counterparty_id. |
| `Tenant ID required` | `400` | The authenticated credential is not bound to a tenant. |
| `Payment method is not shareable` | `409` | The instrument is exclusive, parked, or otherwise cannot accept another association. |
| `Internal server error` | `500` | Unexpected server error. The JSON body includes correlationId. Retry with backoff. |

## Request (curl)

```bash
curl --request POST \
  --url https://api.invunion.com/api/v1/payment-methods/PM-001/counterparties \
  --header 'accept: application/json' \
  --header 'authorization: Bearer uk_live_YOUR_API_KEY' \
  --header 'content-type: application/json' \
  --data '{
  "counterparty_id": "CPT-042"
}'
```

## Request (Python)

```python
import requests

url = "https://api.invunion.com/api/v1/payment-methods/PM-001/counterparties"
headers = {
    "Accept": "application/json",
    "Authorization": "Bearer uk_live_YOUR_API_KEY",
    "Content-Type": "application/json",
}
payload = {
    "counterparty_id": "CPT-042"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
```

## Request (Ruby)

```ruby
require 'net/http'
require 'json'
require 'uri'

uri = URI("https://api.invunion.com/api/v1/payment-methods/PM-001/counterparties")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri)
request['Accept'] = 'application/json'
request['Authorization'] = 'Bearer uk_live_YOUR_API_KEY'
request['Content-Type'] = 'application/json'
request.body = "{\n  \"counterparty_id\": \"CPT-042\"\n}"
response = http.request(request)
puts response.body
```

## Request (JavaScript)

```javascript
const response = await fetch("https://api.invunion.com/api/v1/payment-methods/PM-001/counterparties", {
  method: "POST",
  headers: {
    "Accept": "application/json",
    "Authorization": "Bearer uk_live_YOUR_API_KEY",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
  "counterparty_id": "CPT-042"
}),
});
const data = await response.json();
```

## Request (Go)

```go
package main

import (
	"bytes"
	"fmt"
	"io"
	"net/http"
)

func main() {
	payload := []byte(`{
  "counterparty_id": "CPT-042"
}`)
	req, err := http.NewRequest("POST", "https://api.invunion.com/api/v1/payment-methods/PM-001/counterparties", bytes.NewBuffer(payload))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Accept", "application/json")
	req.Header.Set("Authorization", "Bearer uk_live_YOUR_API_KEY")
	req.Header.Set("Content-Type", "application/json")
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	body, _ := io.ReadAll(resp.Body)
	fmt.Println(string(body))
}
```

## Request (Node)

```javascript
const response = await fetch("https://api.invunion.com/api/v1/payment-methods/PM-001/counterparties", {
  method: "POST",
  headers: {
    "Accept": "application/json",
    "Authorization": "Bearer uk_live_YOUR_API_KEY",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
  "counterparty_id": "CPT-042"
}),
});
console.log(await response.json());
```

## Success (201)

```json
{
  "success": true,
  "data": {
    "counterparty_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
  }
}
```
