# Link a customer to an account hierarchy

> For the complete machine-readable documentation index, see [llms.txt](https://apidocs.chargebee.com/llms.txt).


[Idempotency Supported](/docs/api/idempotency)

Creates a [hierarchical relationship](https://www.chargebee.com/docs/account-hierarchy.html) between two customers. The path parameter `customer_id` identifies the child in this relationship, and `parent_id` identifies the parent.

**Note**

For the `use_default_hierarchy_settings`, `parent_account_access`, and `child_account_access` parameters in this operation, the term "parent" usually refers to [`payment_owner_id`](/docs/api/customers/link-a-customer#payment_owner_id). If `payment_owner_id` is the same as `customer_id`, then "parent" refers to [`parent_id`](/docs/api/customers/link-a-customer#parent_id).

### Prerequisites & Constraints

-   `customer_id` and `parent_id` must belong to the same [business entity](/docs/api/advanced-features).
-   The [Account Hierarchy limits](https://www.chargebee.com/docs/billing/2.0/customers/account-hierarchy#limits) must not be exceeded due to this operation.

### Impacts

**

Customer

**

-   Sets the following attributes on the `customer` resource:
    -   [`relationship`](/docs/api/customers)
    -   [`use_default_hierarchy_settings`](/docs/api/customers)
    -   [`child_account_access`](/docs/api/customers)
    -   [`parent_account_access`](/docs/api/customers)

**

Invoices

**

-   For all invoices generated for `customer_id` after you link the customer, Chargebee sets `invoice.customer_id` to `invoice_owner_id`.

**

Transactions

**

-   When Chargebee generates invoices for `customer_id`, if `auto_collection` is `on` for `invoice_owner_id`, Chargebee uses the `payment_source` of the `payment_owner_id` to pay the invoices and creates transactions for the payment under `payment_owner_id`.

**

RevenueStory

**

-   The [Customer Insights](https://www.chargebee.com/docs/billing/2.0/reports-and-analytics/chargebee-analytics#customer-insights) report in RevenueStory shows parent-level views for customers with hierarchy relationships.

## Sample Request

### creates a relationship for reporting purpose

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/customers/__test__KyVnHhSBWlDY12d5/relationships \
     -u {site_api_key}:\
     -d parent_id="__test__KyVnHhSBWlDa22d7" \
     -d payment_owner_id="__test__KyVnHhSBWlDY12d5" \
     -d invoice_owner_id="__test__KyVnHhSBWlDY12d5"
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Customer.Relationships("__test__KyVnHhSBWlDY12d5")
		.ParentId("__test__KyVnHhSBWlDa22d7")
		.PaymentOwnerId("__test__KyVnHhSBWlDY12d5")
		.InvoiceOwnerId("__test__KyVnHhSBWlDY12d5")
		.Request();

Customer customer = result.Customer;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    customerAction "github.com/chargebee/chargebee-go/v3/actions/customer"
    "github.com/chargebee/chargebee-go/v3/models/customer"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := customerAction.Relationships("__test__KyVnHhSBWlDY12d5", &customer.RelationshipsRequestParams{
        ParentId : "__test__KyVnHhSBWlDa22d7",
        PaymentOwnerId : "__test__KyVnHhSBWlDY12d5",
        InvoiceOwnerId : "__test__KyVnHhSBWlDY12d5",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Customer := res.Customer
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.CustomerRelationshipsRequest{
    ParentId : "__test__KyVnHhSBWlDa22d7",
    PaymentOwnerId : "__test__KyVnHhSBWlDY12d5",
    InvoiceOwnerId : "__test__KyVnHhSBWlDY12d5",
}
  res, err := client.Customer.Relationships("__test__KyVnHhSBWlDY12d5", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Customer := res.Customer
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Customer.relationships("__test__KyVnHhSBWlDY12d5")
            .parentId("__test__KyVnHhSBWlDa22d7")
            .paymentOwnerId("__test__KyVnHhSBWlDY12d5")
            .invoiceOwnerId("__test__KyVnHhSBWlDY12d5")
            .request();

        Customer customer = result.customer();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.customer.Customer;
import com.chargebee.v4.models.customer.params.CustomerRelationshipsParams;
import com.chargebee.v4.models.customer.responses.CustomerRelationshipsResponse;

public class CustomerRelationships {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        CustomerRelationshipsParams params = CustomerRelationshipsParams.builder()
            .parentId("__test__KyVnHhSBWlDa22d7")
            .paymentOwnerId("__test__KyVnHhSBWlDY12d5")
            .invoiceOwnerId("__test__KyVnHhSBWlDY12d5")
            .build();

        CustomerRelationshipsResponse response = client
            .customers()
            .relationships("__test__KyVnHhSBWlDY12d5", params);

        Customer customer = response.getCustomer();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.customer.relationships("__test__KyVnHhSBWlDY12d5", {
        parent_id: "__test__KyVnHhSBWlDa22d7",
        payment_owner_id: "__test__KyVnHhSBWlDY12d5",
        invoice_owner_id: "__test__KyVnHhSBWlDY12d5"
    });

    console.log(result);
    const customer = result.customer;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->customer()->relationships("__test__KyVnHhSBWlDY12d5", [
    "parent_id" => "__test__KyVnHhSBWlDa22d7",
    "payment_owner_id" => "__test__KyVnHhSBWlDY12d5",
    "invoice_owner_id" => "__test__KyVnHhSBWlDY12d5"
]);
$customer = $result->customer;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Customer.relationships("__test__KyVnHhSBWlDY12d5",
    cb_client.Customer.RelationshipsParams(
        parent_id="__test__KyVnHhSBWlDa22d7",
        payment_owner_id="__test__KyVnHhSBWlDY12d5",
        invoice_owner_id="__test__KyVnHhSBWlDY12d5"
    )
)
customer = response.customer
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::Customer.relationships("__test__KyVnHhSBWlDY12d5",{
  :parent_id => "__test__KyVnHhSBWlDa22d7",
  :payment_owner_id => "__test__KyVnHhSBWlDY12d5",
  :invoice_owner_id => "__test__KyVnHhSBWlDY12d5"
})

customer = result.customer
```

### creates a completely dependent relationship

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/customers/__test__KyVnHhSBWlDwm2dJ/relationships \
     -u {site_api_key}:\
     -d parent_id="__test__KyVnHhSBWlDrp2dC" \
     -d payment_owner_id="__test__KyVnHhSBWlDrp2dC" \
     -d invoice_owner_id="__test__KyVnHhSBWlDrp2dC"
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Customer.Relationships("__test__KyVnHhSBWlDwm2dJ")
		.ParentId("__test__KyVnHhSBWlDrp2dC")
		.PaymentOwnerId("__test__KyVnHhSBWlDrp2dC")
		.InvoiceOwnerId("__test__KyVnHhSBWlDrp2dC")
		.Request();

Customer customer = result.Customer;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    customerAction "github.com/chargebee/chargebee-go/v3/actions/customer"
    "github.com/chargebee/chargebee-go/v3/models/customer"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := customerAction.Relationships("__test__KyVnHhSBWlDwm2dJ", &customer.RelationshipsRequestParams{
        ParentId : "__test__KyVnHhSBWlDrp2dC",
        PaymentOwnerId : "__test__KyVnHhSBWlDrp2dC",
        InvoiceOwnerId : "__test__KyVnHhSBWlDrp2dC",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Customer := res.Customer
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.CustomerRelationshipsRequest{
    ParentId : "__test__KyVnHhSBWlDrp2dC",
    PaymentOwnerId : "__test__KyVnHhSBWlDrp2dC",
    InvoiceOwnerId : "__test__KyVnHhSBWlDrp2dC",
}
  res, err := client.Customer.Relationships("__test__KyVnHhSBWlDwm2dJ", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Customer := res.Customer
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Customer.relationships("__test__KyVnHhSBWlDwm2dJ")
            .parentId("__test__KyVnHhSBWlDrp2dC")
            .paymentOwnerId("__test__KyVnHhSBWlDrp2dC")
            .invoiceOwnerId("__test__KyVnHhSBWlDrp2dC")
            .request();

        Customer customer = result.customer();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.customer.Customer;
import com.chargebee.v4.models.customer.params.CustomerRelationshipsParams;
import com.chargebee.v4.models.customer.responses.CustomerRelationshipsResponse;

public class CustomerRelationships {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        CustomerRelationshipsParams params = CustomerRelationshipsParams.builder()
            .parentId("__test__KyVnHhSBWlDrp2dC")
            .paymentOwnerId("__test__KyVnHhSBWlDrp2dC")
            .invoiceOwnerId("__test__KyVnHhSBWlDrp2dC")
            .build();

        CustomerRelationshipsResponse response = client
            .customers()
            .relationships("__test__KyVnHhSBWlDwm2dJ", params);

        Customer customer = response.getCustomer();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.customer.relationships("__test__KyVnHhSBWlDwm2dJ", {
        parent_id: "__test__KyVnHhSBWlDrp2dC",
        payment_owner_id: "__test__KyVnHhSBWlDrp2dC",
        invoice_owner_id: "__test__KyVnHhSBWlDrp2dC"
    });

    console.log(result);
    const customer = result.customer;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->customer()->relationships("__test__KyVnHhSBWlDwm2dJ", [
    "parent_id" => "__test__KyVnHhSBWlDrp2dC",
    "payment_owner_id" => "__test__KyVnHhSBWlDrp2dC",
    "invoice_owner_id" => "__test__KyVnHhSBWlDrp2dC"
]);
$customer = $result->customer;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Customer.relationships("__test__KyVnHhSBWlDwm2dJ",
    cb_client.Customer.RelationshipsParams(
        parent_id="__test__KyVnHhSBWlDrp2dC",
        payment_owner_id="__test__KyVnHhSBWlDrp2dC",
        invoice_owner_id="__test__KyVnHhSBWlDrp2dC"
    )
)
customer = response.customer
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::Customer.relationships("__test__KyVnHhSBWlDwm2dJ",{
  :parent_id => "__test__KyVnHhSBWlDrp2dC",
  :payment_owner_id => "__test__KyVnHhSBWlDrp2dC",
  :invoice_owner_id => "__test__KyVnHhSBWlDrp2dC"
})

customer = result.customer
```

### creates a relationship and sets custom parent/child access settings

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/customers/__test__KyVnHhSBWlEhB2dd/relationships \
     -u {site_api_key}:\
     -d parent_id="__test__KyVnHhSBWlEc92dW" \
     -d payment_owner_id="__test__KyVnHhSBWlEc92dW" \
     -d invoice_owner_id="__test__KyVnHhSBWlEhB2dd" \
     -d use_default_hierarchy_settings="false" \
     -d "parent_account_access[portal_edit_child_subscriptions]"="YES" \
     -d "parent_account_access[portal_download_child_invoices]"="YES" \
     -d "parent_account_access[send_subscription_emails]"="true" \
     -d "parent_account_access[send_payment_emails]"="false" \
     -d "parent_account_access[send_invoice_emails]"="false" \
     -d "child_account_access[portal_edit_subscriptions]"="VIEW_ONLY" \
     -d "child_account_access[portal_download_invoices]"="VIEW_ONLY" \
     -d "child_account_access[send_subscription_emails]"="true" \
     -d "child_account_access[send_payment_emails]"="true" \
     -d "child_account_access[send_invoice_emails]"="true"
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Customer.Relationships("__test__KyVnHhSBWlEhB2dd")
		.ParentId("__test__KyVnHhSBWlEc92dW")
		.PaymentOwnerId("__test__KyVnHhSBWlEc92dW")
		.InvoiceOwnerId("__test__KyVnHhSBWlEhB2dd")
		.UseDefaultHierarchySettings(false)
		.ParentAccountAccessPortalEditChildSubscriptions(Customer.CustomerParentAccountAccess.PortalEditChildSubscriptionsEnum.Yes)
		.ParentAccountAccessPortalDownloadChildInvoices(Customer.CustomerParentAccountAccess.PortalDownloadChildInvoicesEnum.Yes)
		.ParentAccountAccessSendSubscriptionEmails(true)
		.ParentAccountAccessSendPaymentEmails(false)
		.ParentAccountAccessSendInvoiceEmails(false)
		.ChildAccountAccessPortalEditSubscriptions(Customer.CustomerChildAccountAccess.PortalEditSubscriptionsEnum.ViewOnly)
		.ChildAccountAccessPortalDownloadInvoices(Customer.CustomerChildAccountAccess.PortalDownloadInvoicesEnum.ViewOnly)
		.ChildAccountAccessSendSubscriptionEmails(true)
		.ChildAccountAccessSendPaymentEmails(true)
		.ChildAccountAccessSendInvoiceEmails(true)
		.Request();

Customer customer = result.Customer;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    customerAction "github.com/chargebee/chargebee-go/v3/actions/customer"
    "github.com/chargebee/chargebee-go/v3/models/customer"
    customerEnum "github.com/chargebee/chargebee-go/v3/models/customer/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := customerAction.Relationships("__test__KyVnHhSBWlEhB2dd", &customer.RelationshipsRequestParams{
        ParentId : "__test__KyVnHhSBWlEc92dW",
        PaymentOwnerId : "__test__KyVnHhSBWlEc92dW",
        InvoiceOwnerId : "__test__KyVnHhSBWlEhB2dd",
        UseDefaultHierarchySettings : chargebee.Bool(false),
        ParentAccountAccess : &customer.RelationshipsParentAccountAccessParams{
            PortalEditChildSubscriptions : customerEnum.ParentAccountAccessPortalEditChildSubscriptionsYes,
            PortalDownloadChildInvoices : customerEnum.ParentAccountAccessPortalDownloadChildInvoicesYes,
            SendSubscriptionEmails : chargebee.Bool(true),
            SendPaymentEmails : chargebee.Bool(false),
            SendInvoiceEmails : chargebee.Bool(false),
        },
        ChildAccountAccess : &customer.RelationshipsChildAccountAccessParams{
            PortalEditSubscriptions : customerEnum.ChildAccountAccessPortalEditSubscriptionsViewOnly,
            PortalDownloadInvoices : customerEnum.ChildAccountAccessPortalDownloadInvoicesViewOnly,
            SendSubscriptionEmails : chargebee.Bool(true),
            SendPaymentEmails : chargebee.Bool(true),
            SendInvoiceEmails : chargebee.Bool(true),
        },
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Customer := res.Customer
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.CustomerRelationshipsRequest{
    ParentId : "__test__KyVnHhSBWlEc92dW",
    PaymentOwnerId : "__test__KyVnHhSBWlEc92dW",
    InvoiceOwnerId : "__test__KyVnHhSBWlEhB2dd",
    UseDefaultHierarchySettings : chargebee.Bool(false),
    ParentAccountAccess : &chargebee.CustomerRelationshipsParentAccountAccess{
        PortalEditChildSubscriptions : chargebee.CustomerParentAccountAccessPortalEditChildSubscriptionsYes,
        PortalDownloadChildInvoices : chargebee.CustomerParentAccountAccessPortalDownloadChildInvoicesYes,
        SendSubscriptionEmails : chargebee.Bool(true),
        SendPaymentEmails : chargebee.Bool(false),
        SendInvoiceEmails : chargebee.Bool(false),
    },
    ChildAccountAccess : &chargebee.CustomerRelationshipsChildAccountAccess{
        PortalEditSubscriptions : chargebee.CustomerChildAccountAccessPortalEditSubscriptionsViewOnly,
        PortalDownloadInvoices : chargebee.CustomerChildAccountAccessPortalDownloadInvoicesViewOnly,
        SendSubscriptionEmails : chargebee.Bool(true),
        SendPaymentEmails : chargebee.Bool(true),
        SendInvoiceEmails : chargebee.Bool(true),
    },
}
  res, err := client.Customer.Relationships("__test__KyVnHhSBWlEhB2dd", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Customer := res.Customer
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Customer.relationships("__test__KyVnHhSBWlEhB2dd")
            .parentId("__test__KyVnHhSBWlEc92dW")
            .paymentOwnerId("__test__KyVnHhSBWlEc92dW")
            .invoiceOwnerId("__test__KyVnHhSBWlEhB2dd")
            .useDefaultHierarchySettings(false)
            .parentAccountAccessPortalEditChildSubscriptions(Customer.ParentAccountAccess.PortalEditChildSubscriptions.YES)
            .parentAccountAccessPortalDownloadChildInvoices(Customer.ParentAccountAccess.PortalDownloadChildInvoices.YES)
            .parentAccountAccessSendSubscriptionEmails(true)
            .parentAccountAccessSendPaymentEmails(false)
            .parentAccountAccessSendInvoiceEmails(false)
            .childAccountAccessPortalEditSubscriptions(Customer.ChildAccountAccess.PortalEditSubscriptions.VIEW_ONLY)
            .childAccountAccessPortalDownloadInvoices(Customer.ChildAccountAccess.PortalDownloadInvoices.VIEW_ONLY)
            .childAccountAccessSendSubscriptionEmails(true)
            .childAccountAccessSendPaymentEmails(true)
            .childAccountAccessSendInvoiceEmails(true)
            .request();

        Customer customer = result.customer();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.customer.Customer;
import com.chargebee.v4.models.customer.params.CustomerRelationshipsParams;
import com.chargebee.v4.models.customer.responses.CustomerRelationshipsResponse;

public class CustomerRelationships {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        CustomerRelationshipsParams.ParentAccountAccessParams parentAccountAccessParams =
            CustomerRelationshipsParams.ParentAccountAccessParams.builder()
                .portalEditChildSubscriptions(CustomerRelationshipsParams.ParentAccountAccessParams.PortalEditChildSubscriptions.YES)
                .portalDownloadChildInvoices(CustomerRelationshipsParams.ParentAccountAccessParams.PortalDownloadChildInvoices.YES)
                .sendSubscriptionEmails(true)
                .sendPaymentEmails(false)
                .sendInvoiceEmails(false)
                .build();

        CustomerRelationshipsParams.ChildAccountAccessParams childAccountAccessParams =
            CustomerRelationshipsParams.ChildAccountAccessParams.builder()
                .portalEditSubscriptions(CustomerRelationshipsParams.ChildAccountAccessParams.PortalEditSubscriptions.VIEW_ONLY)
                .portalDownloadInvoices(CustomerRelationshipsParams.ChildAccountAccessParams.PortalDownloadInvoices.VIEW_ONLY)
                .sendSubscriptionEmails(true)
                .sendPaymentEmails(true)
                .sendInvoiceEmails(true)
                .build();

        CustomerRelationshipsParams params = CustomerRelationshipsParams.builder()
            .parentId("__test__KyVnHhSBWlEc92dW")
            .paymentOwnerId("__test__KyVnHhSBWlEc92dW")
            .invoiceOwnerId("__test__KyVnHhSBWlEhB2dd")
            .useDefaultHierarchySettings(false)
            .parentAccountAccess(parentAccountAccessParams)
            .childAccountAccess(childAccountAccessParams)
            .build();

        CustomerRelationshipsResponse response = client
            .customers()
            .relationships("__test__KyVnHhSBWlEhB2dd", params);

        Customer customer = response.getCustomer();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.customer.relationships("__test__KyVnHhSBWlEhB2dd", {
        parent_id: "__test__KyVnHhSBWlEc92dW",
        payment_owner_id: "__test__KyVnHhSBWlEc92dW",
        invoice_owner_id: "__test__KyVnHhSBWlEhB2dd",
        use_default_hierarchy_settings: false,
        parent_account_access: {
            portal_edit_child_subscriptions: "yes",
            portal_download_child_invoices: "yes",
            send_subscription_emails: true,
            send_payment_emails: false,
            send_invoice_emails: false
        },
        child_account_access: {
            portal_edit_subscriptions: "view_only",
            portal_download_invoices: "view_only",
            send_subscription_emails: true,
            send_payment_emails: true,
            send_invoice_emails: true
        }
    });

    console.log(result);
    const customer = result.customer;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->customer()->relationships("__test__KyVnHhSBWlEhB2dd", [
    "parent_id" => "__test__KyVnHhSBWlEc92dW",
    "payment_owner_id" => "__test__KyVnHhSBWlEc92dW",
    "invoice_owner_id" => "__test__KyVnHhSBWlEhB2dd",
    "use_default_hierarchy_settings" => false,
    "parent_account_access" => [
        "portal_edit_child_subscriptions" => "yes",
        "portal_download_child_invoices" => "yes",
        "send_subscription_emails" => true,
        "send_payment_emails" => false,
        "send_invoice_emails" => false
    ],
    "child_account_access" => [
        "portal_edit_subscriptions" => "view_only",
        "portal_download_invoices" => "view_only",
        "send_subscription_emails" => true,
        "send_payment_emails" => true,
        "send_invoice_emails" => true
    ]
]);
$customer = $result->customer;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Customer.relationships("__test__KyVnHhSBWlEhB2dd",
    cb_client.Customer.RelationshipsParams(
        parent_id="__test__KyVnHhSBWlEc92dW",
        payment_owner_id="__test__KyVnHhSBWlEc92dW",
        invoice_owner_id="__test__KyVnHhSBWlEhB2dd",
        use_default_hierarchy_settings=False,
        parent_account_access=cb_client.Customer.RelationshipsParentAccountAccessParams(
            portal_edit_child_subscriptions=chargebee.Customer.ParentAccountAccessPortalEditChildSubscriptions.YES,
            portal_download_child_invoices=chargebee.Customer.ParentAccountAccessPortalDownloadChildInvoices.YES,
            send_subscription_emails=True,
            send_payment_emails=False,
            send_invoice_emails=False
        ),
        child_account_access=cb_client.Customer.RelationshipsChildAccountAccessParams(
            portal_edit_subscriptions=chargebee.Customer.ChildAccountAccessPortalEditSubscriptions.VIEW_ONLY,
            portal_download_invoices=chargebee.Customer.ChildAccountAccessPortalDownloadInvoices.VIEW_ONLY,
            send_subscription_emails=True,
            send_payment_emails=True,
            send_invoice_emails=True
        )
    )
)
customer = response.customer
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::Customer.relationships("__test__KyVnHhSBWlEhB2dd",{
  :parent_id => "__test__KyVnHhSBWlEc92dW",
  :payment_owner_id => "__test__KyVnHhSBWlEc92dW",
  :invoice_owner_id => "__test__KyVnHhSBWlEhB2dd",
  :use_default_hierarchy_settings => "false",
  :parent_account_access => {
    :portal_edit_child_subscriptions => "YES",
    :portal_download_child_invoices => "YES",
    :send_subscription_emails => "true",
    :send_payment_emails => "false",
    :send_invoice_emails => "false"
  },
  :child_account_access => {
    :portal_edit_subscriptions => "VIEW_ONLY",
    :portal_download_invoices => "VIEW_ONLY",
    :send_subscription_emails => "true",
    :send_payment_emails => "true",
    :send_invoice_emails => "true"
  }
})

customer = result.customer
```

### creates a partially dependent relationship

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/customers/__test__KyVnHhSBWlEIc2dT/relationships \
     -u {site_api_key}:\
     -d parent_id="__test__KyVnHhSBWlEDb2dM" \
     -d payment_owner_id="__test__KyVnHhSBWlEDb2dM" \
     -d invoice_owner_id="__test__KyVnHhSBWlEIc2dT"
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Customer.Relationships("__test__KyVnHhSBWlEIc2dT")
		.ParentId("__test__KyVnHhSBWlEDb2dM")
		.PaymentOwnerId("__test__KyVnHhSBWlEDb2dM")
		.InvoiceOwnerId("__test__KyVnHhSBWlEIc2dT")
		.Request();

Customer customer = result.Customer;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    customerAction "github.com/chargebee/chargebee-go/v3/actions/customer"
    "github.com/chargebee/chargebee-go/v3/models/customer"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := customerAction.Relationships("__test__KyVnHhSBWlEIc2dT", &customer.RelationshipsRequestParams{
        ParentId : "__test__KyVnHhSBWlEDb2dM",
        PaymentOwnerId : "__test__KyVnHhSBWlEDb2dM",
        InvoiceOwnerId : "__test__KyVnHhSBWlEIc2dT",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Customer := res.Customer
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.CustomerRelationshipsRequest{
    ParentId : "__test__KyVnHhSBWlEDb2dM",
    PaymentOwnerId : "__test__KyVnHhSBWlEDb2dM",
    InvoiceOwnerId : "__test__KyVnHhSBWlEIc2dT",
}
  res, err := client.Customer.Relationships("__test__KyVnHhSBWlEIc2dT", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Customer := res.Customer
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Customer.relationships("__test__KyVnHhSBWlEIc2dT")
            .parentId("__test__KyVnHhSBWlEDb2dM")
            .paymentOwnerId("__test__KyVnHhSBWlEDb2dM")
            .invoiceOwnerId("__test__KyVnHhSBWlEIc2dT")
            .request();

        Customer customer = result.customer();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.customer.Customer;
import com.chargebee.v4.models.customer.params.CustomerRelationshipsParams;
import com.chargebee.v4.models.customer.responses.CustomerRelationshipsResponse;

public class CustomerRelationships {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        CustomerRelationshipsParams params = CustomerRelationshipsParams.builder()
            .parentId("__test__KyVnHhSBWlEDb2dM")
            .paymentOwnerId("__test__KyVnHhSBWlEDb2dM")
            .invoiceOwnerId("__test__KyVnHhSBWlEIc2dT")
            .build();

        CustomerRelationshipsResponse response = client
            .customers()
            .relationships("__test__KyVnHhSBWlEIc2dT", params);

        Customer customer = response.getCustomer();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.customer.relationships("__test__KyVnHhSBWlEIc2dT", {
        parent_id: "__test__KyVnHhSBWlEDb2dM",
        payment_owner_id: "__test__KyVnHhSBWlEDb2dM",
        invoice_owner_id: "__test__KyVnHhSBWlEIc2dT"
    });

    console.log(result);
    const customer = result.customer;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->customer()->relationships("__test__KyVnHhSBWlEIc2dT", [
    "parent_id" => "__test__KyVnHhSBWlEDb2dM",
    "payment_owner_id" => "__test__KyVnHhSBWlEDb2dM",
    "invoice_owner_id" => "__test__KyVnHhSBWlEIc2dT"
]);
$customer = $result->customer;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Customer.relationships("__test__KyVnHhSBWlEIc2dT",
    cb_client.Customer.RelationshipsParams(
        parent_id="__test__KyVnHhSBWlEDb2dM",
        payment_owner_id="__test__KyVnHhSBWlEDb2dM",
        invoice_owner_id="__test__KyVnHhSBWlEIc2dT"
    )
)
customer = response.customer
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::Customer.relationships("__test__KyVnHhSBWlEIc2dT",{
  :parent_id => "__test__KyVnHhSBWlEDb2dM",
  :payment_owner_id => "__test__KyVnHhSBWlEDb2dM",
  :invoice_owner_id => "__test__KyVnHhSBWlEIc2dT"
})

customer = result.customer
```

## Sample Response

```json
{
  "customer": {
    "allow_direct_debit": false,
    "auto_collection": "on",
    "card_status": "no_card",
    "child_account_access": {
      "portal_download_invoices": "view_only",
      "portal_edit_subscriptions": "yes",
      "send_invoice_emails": true,
      "send_payment_emails": true,
      "send_subscription_emails": true
    },
    "created_at": 1517505753,
    "deleted": false,
    "excess_payments": 0,
    "first_name": "Bella",
    "id": "__test__KyVnHhSBWlDY12d5",
    "last_name": "Brown",
    "net_term_days": 0,
    "object": "customer",
    "parent_account_access": {
      "portal_download_child_invoices": "yes",
      "portal_edit_child_subscriptions": "view_only",
      "send_invoice_emails": true,
      "send_payment_emails": true,
      "send_subscription_emails": false
    },
    "pii_cleared": "active",
    "preferred_currency_code": "USD",
    "promotional_credits": 0,
    "refundable_credits": 0,
    "relationship": {
      "invoice_owner_id": "__test__KyVnHhSBWlDY12d5",
      "parent_id": "__test__KyVnHhSBWlDa22d7",
      "payment_owner_id": "__test__KyVnHhSBWlDY12d5",
      "root_id": "__test__KyVnHhSBWlDa22d7"
    },
    "resource_version": 1517505753000,
    "taxability": "taxable",
    "unbilled_charges": 0,
    "updated_at": 1517505753,
    "use_default_hierarchy_settings": true
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/customers/{customer-id}/relationships

## Input Parameters

- `parent_id` (optional, string, max chars=50)
  ID of the customer intended to be set as the immediate parent of the customer identified by `customer_id` .

- `payment_owner_id` (optional, string, max chars=50)
  The `id` of the customer responsible for paying the invoices for the customer identified by `customer_id`.
  
  **Constraints**
  
  -   If the `invoice_owner_id` is the same as the `customer_id`, then the `payment_owner_id` can be the `customer_id` or an ancestor of the `customer_id`.
  -   If the `invoice_owner_id` is not the same as the `customer_id`, then the `payment_owner_id` must be the `invoice_owner_id`.

- `invoice_owner_id` (optional, string, max chars=50)
  The `id` of the customer who receives the invoice for charges incurred by the customer identified by `customer_id`.
  
  **Constraint**
  
  -   This ID must match either `customer_id` or one of its ancestors.

- `use_default_hierarchy_settings` (optional, boolean, default=true)
  Decides if Chargebee should apply settings from the [Chargebee Billing UI](https://www.chargebee.com/docs/1.0/account-hierarchy.html#advanced-mode) or from this API request.
  
  -   If set to `true`: Chargebee uses settings configured in the Chargebee Billing UI.
  -   If set to `false`: Settings provided in the `parent_account_access` and `child_account_access` parameters are applied.

- `parent_account_access` (optional, enumerated string)
  Settings for the parent account's access.
  - `portal_edit_child_subscriptions` (optional, enumerated string)
    Determines the parent's access to the child's subscriptions in the Self-Serve Portal.
    Possible enum values:
      - `yes`
        The parent can view and edit the child's subscriptions.
      - `view_only`
        The parent can only view the child's subscriptions.
      - `no`
        The parent can't view or edit the child's subscriptions.
  - `portal_download_child_invoices` (optional, enumerated string)
    Determines the parent's access to the child's invoices in the Self-Serve Portal.
    Possible enum values:
      - `yes`
        The parent can both view and download the child's invoices.
      - `view_only`
        The parent can view but not download the child's invoices.
      - `no`
        The parent can't view or download the child's invoices.
  - `send_subscription_emails` (optional, boolean)
    If set to `true` , the parent receives email notifications for the child's subscriptions.
  - `send_payment_emails` (optional, boolean)
    If set to `true` , the parent receives email notifications for payment-related activities on the child's invoices.
  - `send_invoice_emails` (optional, boolean)
    If set to `true` , the parent receives email notifications for the child's invoices.

- `child_account_access` (optional, enumerated string)
  Settings for the child account's access.
  - `portal_edit_subscriptions` (optional, enumerated string)
    Determines the child's access to its own subscriptions in the Self-Serve Portal.
    Possible enum values:
      - `yes`
        The child account can view and edit its subscriptions.
      - `view_only`
        The child account can only view its subscriptions.
  - `portal_download_invoices` (optional, enumerated string)
    Determines the child's access to its own invoices in the Self-Serve Portal.
    Possible enum values:
      - `yes`
        The child account can both view and download its invoices.
      - `view_only`
        The child account can view but not download its invoices.
      - `no`
        The child account cannot view or download its own invoices.
  - `send_subscription_emails` (optional, boolean)
    If set to `true` , the child account receives email notifications for its subscriptions.
  - `send_payment_emails` (optional, boolean)
    If set to `true` , the child account receives email notifications for payment-related activities for its invoices.
  - `send_invoice_emails` (optional, boolean)
    If set to `true` , the child account receives email notifications for its invoices.

## Returns

- `customer` (Customer object)
  Resource object representing customer.
