# Create a Complex Structure
source: https://developer.mastercard.com/mastercard-processing-core/documentation/use-cases/card-lifecycle/create-structure/index.md

## Overview {#overview}

This use case describes how the server can create complex structures of objects in the CMS. This structure includes two clients and two virtual cards with a shared account.
![](https://static.developer.mastercard.com/content/mastercard-processing-core/uploads/processing_32.png)

* There are two clients, and one is the owner of the account contracts.
* One of the card contracts is linked to a client who is assigned the cardholder role for this card but is not an owner of a card contract.

## Sequence diagram {#sequence-diagram}

Diagram create-structure

### Explanation {#explanation}

1. The server sends a `POST` request to the `/clients` endpoint to create the `Client` object in the CMS, passing the `clientNumber` in the request body from your CBS `clientType`, `firstName` and `lastName` (in this example,'John''Smith').
2. The `Client` object for 'John Smith' is created in the CMS.
3. After successful `Client` object creation in the CMS, the unique `clientId` number, in this example '12345' is returned to the server.
4. The server sends a `POST` request to the `/accounts` endpoint to create an account contract in the CMS passing the required fields in the request body. The fields include `accountContractNumber` from your CBS, `clientId` value '12345' and `productCode`.
5. The account contract for the applicable client is created in the CMS.
6. After successful account contract creation in the CMS, a unique `accountContractId` number is returned to the server (in this example, '60001').
7. The server sends a `POST` request to the `/cards` endpoint to create a card contract in the CMS passing required fields in the request body. In this example the required fields are `accountContractId` -- '60001', `clientId` -- '12345', `cardContractNumber` -- PAN1 (for example, '5123456789123456'), and `productCode` -- defined during onboarding configuration.
8. The card contract for the applicable account contract and `Client` object is created in the CMS with the `Plastic` object.
9. After the card is successfully created in the CMS, a unique `cardContractId` is returned to the server.
10. The server sends another `POST` request to the `/clients` endpoint to create a new `Client` object in the CMS passing the `clientNumber` from your CBS. `clientType`, `firstName`, and `lastName` (in this example, 'Anna''Smith').
11. The `Client` object for 'Anna Smith' is created in the CMS.
12. After the `Client` object is successfully created in the CMS, a unique `clientId` number (in this example, '56789') is returned to the server.
13. The server sends a `POST` request to the `/cards` endpoint to create a card contract in the CMS passing the required fields in the request body. In this example the required fields are `accountContractId` -- '60001', `clientId` -- '56789', `cardContractNumber` -- 'PAN2', `productCode` -- defined during onboarding configuration.
14. The card contract for the applicable account contract and `Client` object is created in the CMS with the `Plastic` object.
15. After the card contract is successfully created in the CMS, a unique `cardContractId` is returned to the server.

Note: CMS allows to create structure of objects with different length and levels of hierarchy. For example, you can create many sub-accounts to sub-account under top account contract.

When you create a top account contract, you are required to pass the POST request to the `/accounts` endpoint, and the `clientId` subsequently becomes the account contract owner.  

When you create a sub-account, it must be linked to a parent account contract that is not required to be a top account. Each request for sub-account creation requires to provide `parentAccountContractId` instead of the `clientId` in the request body.
Tip: Account contracts can also be linked using the `AccountContractLiability` object to indicate how an open-to-buy amount is checked when the transaction is performed. The link between account contracts is created to indicate one corporate headquarters account and many corporate branch accounts. Refer to the `AccountContractLiability` object in [API Reference](https://developer.mastercard.com/mastercard-processing-core/documentation/api-reference/index.md) for more information.

## Endpoints {#endpoints}


API Reference: `POST /clients`


API Reference: `POST /accounts`


API Reference: `POST /cards`

<br />

