> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://developers.upwardli.com/llms.txt.

# Create a Consumer Relationship

POST https://api.upwardli.com/v2/consumers/{consumer_external_id}/relationships/
Content-Type: application/json

Attaches one of your consumers to another consumer's account as an authorized user. The consumer in the path is the account holder. Sending a pairing that already exists updates that relationship instead of creating a new one: it is set back to `active`, its `relationship_type` is replaced and `200 OK` is returned. Requires the `api:write` scope.

Reference: https://developers.upwardli.com/api-access/api-reference/consumers/relationships/create-consumer-relationship

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Servers

- `https://api.upwardli.com` (Production, default)
- `https://api-sandbox.upwardli.com` (Sandbox)

## Request

### Path parameters

- `consumer_external_id` (string, required) — The `id` of the account holder.

### Body (application/json)

This endpoint expects a CreateConsumerRelationship.

- `related_consumer_id` (string, required) — The `id` of the consumer to add as an authorized user. It must be one of your consumers and can't be the account holder.
- `role` (enum, required) — Always `authorized_user`.
  - Allowed values: `authorized_user`
- `relationship_type` (enum, required) — What the account holder is to the authorized user.
  - Allowed values: `parent`, `guardian`, `spouse`, `other`

## Response

### 200

The relationship already existed. It is now `active` and carries the `relationship_type` you sent.

- `id` (string, required) — The `id` of the relationship.
- `principal_id` (string, required) — The `id` of the business, or of the consumer who holds the account, that the relationship belongs to.
- `principal_type` (enum, required) — Whether the principal is a `business` or a `consumer`.
  - Allowed values: `consumer`, `business`
- `related_consumer_id` (string, required) — The `id` of the consumer attached to the principal.
- `ownership_percentage` (double, required, nullable) — Share of the business the attached consumer owns, from 0 to 100 with two decimal places. Set for business relationships, `null` otherwise.
- `relationship_type` (enum, required, nullable) — What the account holder is to the authorized user. Set for consumer relationships, `null` otherwise.
  - Allowed values: `parent`, `guardian`, `spouse`, `other`
- `role` (enum, optional) — What the attached consumer is to the principal. A business grants `beneficial_owner` or `control_person`; a consumer grants `authorized_user`.
  - Allowed values: `beneficial_owner`, `control_person`, `authorized_user`
- `status` (enum, optional) — `active` while the relationship is in effect. Removed relationships stay readable with the status `removed`.
  - Allowed values: `active`, `removed`
- `created_at` (string, optional)

### 201

- `id` (string, required) — The `id` of the relationship.
- `principal_id` (string, required) — The `id` of the business, or of the consumer who holds the account, that the relationship belongs to.
- `principal_type` (enum, required) — Whether the principal is a `business` or a `consumer`.
  - Allowed values: `consumer`, `business`
- `related_consumer_id` (string, required) — The `id` of the consumer attached to the principal.
- `ownership_percentage` (double, required, nullable) — Share of the business the attached consumer owns, from 0 to 100 with two decimal places. Set for business relationships, `null` otherwise.
- `relationship_type` (enum, required, nullable) — What the account holder is to the authorized user. Set for consumer relationships, `null` otherwise.
  - Allowed values: `parent`, `guardian`, `spouse`, `other`
- `role` (enum, optional) — What the attached consumer is to the principal. A business grants `beneficial_owner` or `control_person`; a consumer grants `authorized_user`.
  - Allowed values: `beneficial_owner`, `control_person`, `authorized_user`
- `status` (enum, optional) — `active` while the relationship is in effect. Removed relationships stay readable with the status `removed`.
  - Allowed values: `active`, `removed`
- `created_at` (string, optional)

## Errors

### 400 Bad Request Error

The request body is invalid: a required field is missing, `ownership_percentage` was sent, the related consumer is the account holder, or the related entity is not a consumer.

- `detail` (V2ConsumersConsumerExternalIdRelationshipsPostResponsesContentApplicationJsonSchemaDetail, optional)
- `code` (integer, optional)
- `messages` (list of string, optional)

### 404 Not Found Error

The related consumer does not exist or belongs to another partner.

- `detail` (V2ConsumersConsumerExternalIdRelationshipsPostResponsesContentApplicationJsonSchemaDetail, optional)
- `code` (integer, optional)
- `messages` (list of string, optional)

### 422 Unprocessable Entity Error

The account holder does not exist, belongs to another partner, or is not the consumer of a user-scoped token.

- `error` (string, optional)
- `error_code` (string, optional)
- `message` (list of string, optional)

## Types

### V2ConsumersConsumerExternalIdRelationshipsPostResponsesContentApplicationJsonSchemaDetail

## Examples

### Example 1

**Request**

```json
{
  "related_consumer_id": "string",
  "role": "authorized_user",
  "relationship_type": "parent"
}
```

**Response**

```json
{
  "id": "string",
  "principal_id": "string",
  "principal_type": "consumer",
  "related_consumer_id": "string",
  "ownership_percentage": 1.1,
  "relationship_type": "parent",
  "role": "beneficial_owner",
  "status": "active",
  "created_at": "2024-01-15T09:30:00Z"
}
```

**SDK Code**

```python
import requests

url = "https://api.upwardli.com/v2/consumers/consumer_external_id/relationships/"

payload = {
    "related_consumer_id": "string",
    "role": "authorized_user",
    "relationship_type": "parent"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.upwardli.com/v2/consumers/consumer_external_id/relationships/';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"related_consumer_id":"string","role":"authorized_user","relationship_type":"parent"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

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

func main() {

	url := "https://api.upwardli.com/v2/consumers/consumer_external_id/relationships/"

	payload := strings.NewReader("{\n  \"related_consumer_id\": \"string\",\n  \"role\": \"authorized_user\",\n  \"relationship_type\": \"parent\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

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

url = URI("https://api.upwardli.com/v2/consumers/consumer_external_id/relationships/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"related_consumer_id\": \"string\",\n  \"role\": \"authorized_user\",\n  \"relationship_type\": \"parent\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.upwardli.com/v2/consumers/consumer_external_id/relationships/")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"related_consumer_id\": \"string\",\n  \"role\": \"authorized_user\",\n  \"relationship_type\": \"parent\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.upwardli.com/v2/consumers/consumer_external_id/relationships/', [
  'body' => '{
  "related_consumer_id": "string",
  "role": "authorized_user",
  "relationship_type": "parent"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.upwardli.com/v2/consumers/consumer_external_id/relationships/");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"related_consumer_id\": \"string\",\n  \"role\": \"authorized_user\",\n  \"relationship_type\": \"parent\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "related_consumer_id": "string",
  "role": "authorized_user",
  "relationship_type": "parent"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.upwardli.com/v2/consumers/consumer_external_id/relationships/")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Example 2

**Request**

```json
{
  "related_consumer_id": "string",
  "role": "authorized_user",
  "relationship_type": "parent"
}
```

**Response**

```json
{
  "id": "string",
  "principal_id": "string",
  "principal_type": "consumer",
  "related_consumer_id": "string",
  "ownership_percentage": 1.1,
  "relationship_type": "parent",
  "role": "beneficial_owner",
  "status": "active",
  "created_at": "2024-01-15T09:30:00Z"
}
```

**SDK Code**

```python
import requests

url = "https://api.upwardli.com/v2/consumers/consumer_external_id/relationships/"

payload = {
    "related_consumer_id": "string",
    "role": "authorized_user",
    "relationship_type": "parent"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.upwardli.com/v2/consumers/consumer_external_id/relationships/';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"related_consumer_id":"string","role":"authorized_user","relationship_type":"parent"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

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

func main() {

	url := "https://api.upwardli.com/v2/consumers/consumer_external_id/relationships/"

	payload := strings.NewReader("{\n  \"related_consumer_id\": \"string\",\n  \"role\": \"authorized_user\",\n  \"relationship_type\": \"parent\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

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

url = URI("https://api.upwardli.com/v2/consumers/consumer_external_id/relationships/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"related_consumer_id\": \"string\",\n  \"role\": \"authorized_user\",\n  \"relationship_type\": \"parent\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.upwardli.com/v2/consumers/consumer_external_id/relationships/")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"related_consumer_id\": \"string\",\n  \"role\": \"authorized_user\",\n  \"relationship_type\": \"parent\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.upwardli.com/v2/consumers/consumer_external_id/relationships/', [
  'body' => '{
  "related_consumer_id": "string",
  "role": "authorized_user",
  "relationship_type": "parent"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.upwardli.com/v2/consumers/consumer_external_id/relationships/");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"related_consumer_id\": \"string\",\n  \"role\": \"authorized_user\",\n  \"relationship_type\": \"parent\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "related_consumer_id": "string",
  "role": "authorized_user",
  "relationship_type": "parent"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.upwardli.com/v2/consumers/consumer_external_id/relationships/")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```