business_entity
Resource
The business_entity
resource represents a business unit or brand under your organization. Key resources in Chargebee Billing (such as customer
, subscriptions
, invoices
, and transactions
) along with the associated site configurations, fall under a business entity. Each Chargebee Billing site has one business entity by default. You may create multiple business entities in the following scenarios:
Multiple Business Units: You may be running your business under different regional units with different "invoice-from" addresses. This is usually done to manage taxation and bookkeeping. In such a case, you may create a business entity for each business unit.
Multiple Brands: You may have multiple brands within your business, such as those acquired via mergers and acquisitions. You may create a business entity for each brand.
Creating multiple business entities lets you separate configuration and data for your business units or brands so that you can manage their billing and revenue operations independently.
Specifying business entity in API operations
All API operations in Chargebee have site context. The "context" of an API operation is the subset of site data it has access to. An API operation can only read or write data within its context. By default, an API operation has "site context", which means it has access to the entire site's data. If your site has multiple business entities, you can specify the business entity context for an API call by passing a custom HTTP request header.
API behavior based on business entity specified
The table below explains how Chargebee responds to various API calls depending on whether the business entity ID is specified as part of the API call.
| Operation/Type of operation | Behavior | Examples |
---|
1 | Any operation that creates a customer resource. | If business_entity_id is provided, the customer resource is created and linked to it. If business_entity_id is not provided, the customer resource is created under the default business entity of the site.
| |
2 | Create a resource other than customer | If business_entity_id is provided, and it is the same as that linked to the target resource: the resource is created and linked to the business entity provided. If business_entity_id is provided, and it is not the same as that linked to the target resource, a 404 Not Found response is sent because the resource cannot be found in the context of the business entity specified. If business_entity_id is not provided, the resource is created and linked to the business entity of the target resource.
| |
3 | Update/delete a resource | If business_entity_id is provided, and it is the same as that linked to the resource, the operation proceeds successfully. If business_entity_id is provided, and it is not the same as that linked to the resource, a 404 Not Found response is sent because the resource cannot be found in the context of the business entity specified. If business_entity_id is not provided, the operation proceeds successfully.
| |
4 | List resources | If business_entity_id is provided, then only those resources linked to the business entity are returned since the context of the operation is now restricted to the business entity specified. If business_entity_id is not provided, then all resources in the site are returned.
| |
5 | Retrieve a resource | If business_entity_id is provided, and it is the same as that linked to the resource, the resource is retrieved successfully. If business_entity_id is provided, and it is not the same as that linked to the resource, a 404 Not Found response is sent because the resource cannot be found in the context of the business entity specified. If business_entity_id is not provided, the resource is retrieved successfully.
| |
Terminology
This section defines some useful terms for describing how business entities work.
Linked business entity
Any resource is always associated with precisely one and only one business entity. We call it the linked business entity of the resource, or simply, the business entity of the resource.
Default business entity
When customer
resource is created and no business entity is specified, it is linked to the business entity designated as the default business entity of the site. A site always has a default business entity. At first, it is the same as the first business entity of the site and can be changed once more business entities are created. Contact Support to change the default business entity.
Context of an operation
Any site has data in it. This includes all the various resources such as customers, subscriptions, invoices, comments, and so on. The "context" of an API operation is the subset of site data it has access to. An API operation can only read or write data within its context. By default, an API operation has "site context", which means it has access to the entire site's data. However, when a business entity is specified in an API operation, it has "business entity context", which means that the operation only has access to the data linked to the business entity.
Target resource
While creating an API resource other than a customer
, you specify a target resource under which it should be created. For example:
While creating an invoice
resource for a one-time charge, you must specify either the customer
or the subscription
resource to which it belongs. The customer
or subscription
resource, in this case, is the target resource of the invoice
.
While creating a subscription
, the target resource of a subscription
resource is always a customer
resource.
While creating a quote
resource of type
change_subscription
, the target resource is a subscription
resource.
Attributes
| Name | Description |
---|
1 | id
| STRING MAX CHARS = 50 A unique and immutable identifier for the business entity. It is always autogenerated. |
2 | name
| STRING MAX CHARS = 50 A human-friendly name for the business entity. |
3 | status
| ENUM The status of business entity. Possible values: |
4 | resource_version
| LONG Version number of this resource. The resource_version is updated with a new timestamp in milliseconds for every change made to the resource. This attribute will be present only if the resource has been updated after 2016-09-28. |
5 | deleted
| BOOLEAN default=false Indicates that the business entity has been deleted. |
6 | created_at
| UNIX TIME Timestamp for when this business entity was created. |
7 | updated_at
| UNIX TIME The time period when the business entity was updated. |
Endpoints
Transfer a customer to another business entity
POST /business_entity/transfers
Transfers one or more customer
resources from one business entity to another.
The transfer is executed by creating a copy of the customer
resource. The original resource is called the deprecated resource, while the new copy is called the current resource.
Prerequisites
Click here to expand...
Transfers must always be initiated for a current customer
resources and never for a deprecated resources.
A customer
resource cannot be transferred more than three times in a single calendar year. For example, if already moved thrice in the year 2023, a customer
resource can only be moved again in 2024.
The customer
resource must not have any of the following:
an account hierarchy relationship
.
subscription
resource with
invoice
resource with status
as pending
. (Close pending invoices before invoking this API.)
invoice
resources that are advance invoices. (invoice.has_advance_charges
as true
.)
quote
resources with status
as open
or accepted
.
transaction
resource with:
Non-zero unbilled_charges
. (Invoice unbilled charges before invoking this API.)
Non-zero refundable_credits
. (Apply credits to unpaid invoices before invoking this API.)
The customer
resource must not be a gifter of a gift subscription with status
scheduled
or unclaimed
.
Mechanics of business entity transfer
Click here to expand...
When calling this endpoint, the current and deprecated resources are processed as follows:
For the current resource:
id
and active_id
are set to match the deprecated resource's id
.
business_entity_id
is set to destination_business_entity_id
parameter.
For the deprecated resource:
For customer
and subscription
resources, the value of active_id
is set to match the resource id
.
The value of id
is changed to a new random value.
Considerations for business entity transfer
Click here to expand...
When this API is endpoint is called, Chargebee blocks concurrent calls to incompatible POST
operations.
When a resource is transferred more than once, each transfer deprecates the previous current resource and creates a new current resource.
payment_source
resources linked to the customer
are immediately transferred to the destination business entity.
subscription
resources linked to the customer
are transferred automatically to the destination business entity as follows:
active
subscription resources are transferred on their next renewal.
paused
subscription resources are transferred when resumed.
future
subscription resources are transferred on their start_date
.
non_renewing
and cancelled
subscription resources are not transferred and remain linked to the deprecated customer resource.
Other resources linked to the customer, such as invoice
, quote
, credit_note
, and transaction
, remain linked to the deprecated customer resource.
Deprecated customer
and subscription
resources are not returned in list APIs such as List customers or List subscriptions.
Example
Click here to expand...
The following example illustrates the transfer of a customer
resource from a business entity (source) to another (destination). The example also shows how payment_source
, subscription
, and invoice
resources attached to the customer
resource are affected.
1. Initial state before the transfer
Imagine a customer
resource with the id
Ab6dRFt
belonging to the business entity acme-us
. This customer has a linked payment_source
, subscription
, and an invoice
.
2. Invoking the API endpoint
To transfer the customer
resource to a new business entity acme-eu
, you would call the endpoint as follows:
curl https://{site}.chargebee.com/api/v2/business_entities/transfers \
-u {api_key}:\
-d active_resource_ids[0]="Ab6dRFt" \
-d destination_business_entity_ids[0]="acme-us" \
-d reason_code[0]="correction"
The customer
resource is deprecated in favor of a new current customer
resource. The payment_source
resource is also deprecated and a new current payment_source
resource is created and linked to the new customer
resource. The subscription
and invoice
resources remain linked to the deprecated customer
resource.
3. Transfer of linked subscription
resources
When the subscription
renews, it automatically transfers to the business entity of the current customer
resource. This process mirrors the transfer of the customer
resource, resulting in a new current subscription
resource linked to the current customer
resource and the business entity acme-eu
.
Sample request
curl
curl https://{site}.chargebee.com/api/v2/business_entities/transfers \
-u {site_api_key}:\
-d active_resource_ids="Customer-1,Customer-2" \
-d destination_business_entity_ids="Entity-2,Entity-2" \
-d reason_codes="Correction,Correction"
PHP
require_once('vendor/autoload.php');
use ChargeBee\ChargeBee\Environment;
use ChargeBee\ChargeBee\Models\BusinessEntity;
Environment::configure("{site}","{site_api_key}");
$result = BusinessEntity::createTransfers(array(
"activeResourceIds" => array("Customer-1,Customer-2"),
"destinationBusinessEntityIds" => array("Entity-2,Entity-2"),
"reasonCodes" => array("Correction,Correction")
));
$businessEntityTransfer = $result->businessEntityTransfer();
Ruby
require 'chargebee'
ChargeBee.configure(:site => "{site}",
:api_key => "{site_api_key}")
result = ChargeBee::BusinessEntity.create_transfers({
:active_resource_ids => ["Customer-1,Customer-2"],
:destination_business_entity_ids => ["Entity-2,Entity-2"],
:reason_codes => ["Correction,Correction"]
})
business_entity_transfer = result.business_entity_transfer
Python
import chargebee
import json
chargebee.configure("{site_api_key}","{site}")
result = chargebee.BusinessEntity.create_transfers({
"active_resource_ids" : ["Customer-1,Customer-2"],
"destination_business_entity_ids" : ["Entity-2,Entity-2"],
"reason_codes" : ["Correction,Correction"]
})
business_entity_transfer = result.business_entity_transfer
Java
import java.io.IOException;
import com.chargebee.*;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
public class Sample{
public static void main(String args[]) throws IOException{
Environment.configure("{site}","{site_api_key}");
Result result = BusinessEntity.createTransfers()
.activeResourceIds("Customer-1,Customer-2")
.destinationBusinessEntityIds("Entity-2,Entity-2")
.reasonCodes("Correction,Correction")
.request();
BusinessEntityTransfer businessEntityTransfer = result.businessEntityTransfer();
System.out.println(result);
}
}
.NET
using ChargeBee.Api;
using ChargeBee.Models;
ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = BusinessEntity.CreateTransfers()
.ActiveResourceIds(new List<String>(new String[] {"Customer-1,Customer-2"}))
.DestinationBusinessEntityIds(new List<String>(new String[] {"Entity-2,Entity-2"}))
.ReasonCodes(new List<String>(new String[] {"Correction,Correction"}))
.Request();
BusinessEntityTransfer businessEntityTransfer = result.BusinessEntityTransfer;
Node
var chargebee = require("chargebee");
chargebee.configure({site : "{site}",
api_key : "{site_api_key}"})
chargebee.business_entity.create_transfers({
active_resource_ids : "Customer-1,Customer-2",
destination_business_entity_ids : "Entity-2,Entity-2",
reason_codes : "Correction,Correction"
}).request(function(error,result) {
if(error){
//handle error
console.log(error);
}else{
console.log(result);
var business_entity_transfer = result.business_entity_transfer;
}
});
Go
package main
import (
"fmt"
"github.com/chargebee/chargebee-go/v3"
businessEntityAction "github.com/chargebee/chargebee-go/v3/actions/businessEntity"
"github.com/chargebee/chargebee-go/v3/models/businessEntity"
)
func main() {
chargebee.Configure("{site_api_key}","{site}");
res,err := businessEntityAction.CreateTransfers(&businessEntity.CreateTransfersRequestParams {
ActiveResourceIds : []string{"Customer-1,Customer-2"},
DestinationBusinessEntityIds : []string{"Entity-2,Entity-2"},
ReasonCodes : []string{"Correction,Correction"},
}).Request()
if err != nil {
fmt.Println(err)
}else{
BusinessEntityTransfer := res.BusinessEntityTransfer
}
}
TypeScript
import {
ChargeBee,
_business_entity
} from 'chargebee-typescript';
var chargebee = new ChargeBee();
chargebee.configure({site : "{site}",
api_key : "{site_api_key}"});
chargebee.business_entity.create_transfers({
active_resource_ids : ["Customer-1,Customer-2"],
destination_business_entity_ids : ["Entity-2,Entity-2"],
reason_codes : ["Correction,Correction"]
}).request(function(error,result) {
if(error){
//handle error
console.log(error);
}else{
console.log(`${result}`);
var business_entity_transfer: typeof chargebee.business_entity_transfer = result.business_entity_transfer;
}
});
Sample response
Click here to expand...
{
"list": [
{
"business_entity_transfer": {
"id": "__dev__263BEVU6h5FoKt",
"resource_type": "customer",
"reason_code": "Correction",
"created_at": 1608209339,
"object": "business_entity_transfer",
"destination_business_entity_id": "Entity-2",
"source_business_entity_id": "Entity-1",
"resource_id": "__dev__263BEVU6h5FlTn",
"active_resource_id": "__dev__263BEVU6h5DnYj"
}
},
{
"business_entity_transfer": {
"id": "__dev__263BEVU6h5GoKt",
"resource_type": "customer",
"reason_code": "Correction",
"created_at": 1608209339,
"object": "business_entity_transfer",
"destination_business_entity_id": "Entity-2",
"source_business_entity_id": "Entity-1",
"resource_id": "__dev__263BEVU6h5FlPn",
"active_resource_id": "__dev__263BEVU6h5DnZj"
}
}
]
}
| Parameter | Description |
---|
1 | active_resource_ids[0..n]
| REQUIRED LIST OF STRING The list of unique identifiers of the customer resources to be transferred. Each id must belong to a current customer resource. |
2 | destination_business_entity_ids[0..n]
| REQUIRED LIST OF STRING The list of unique identifiers of the business_entity resources to which the corresponding customer resource must be transferred. |
3 | reason_codes[0..n]
| REQUIRED LIST OF STRING The list of reasons for changing the business entity of the corresponding customer resources. |
Returns
List business entity transfers
GET /business_entities/transfers
Returns a list of business_entity_transfer resources meeting all the conditions specified in the filter parameters below. By default, this list is sorted by created_at
in descending order (latest first).
Sample request
curl
curl https://{site}.chargebee.com/api/v2/business_entities/transfers \
-G \
-u {site_api_key}:\
--data-urlencode resource_type="customer" \
--data-urlencode active_resource_id="Customer-1"
PHP
require_once('vendor/autoload.php');
use ChargeBee\ChargeBee\Environment;
use ChargeBee\ChargeBee\Models\BusinessEntity;
Environment::configure("{site}","{site_api_key}");
$all = BusinessEntity::all(array(
"resourceType" => "customer",
"activeResourceId" => "Customer-1"
));
foreach($all as $entry){
$businessEntityTransfer = $entry->businessEntityTransfer();
}
Ruby
require 'chargebee'
ChargeBee.configure(:site => "{site}",
:api_key => "{site_api_key}")
list = ChargeBee::BusinessEntity.get_transfers({
:resource_type => "customer",
:active_resource_id => "Customer-1"
})
list.each do |entry|
business_entity_transfer = entry.business_entity_transfer
end
Python
import chargebee
import json
chargebee.configure("{site_api_key}","{site}")
entries = chargebee.BusinessEntity.get_transfers({
"resource_type" : "customer",
"active_resource_id" : "Customer-1"
})
for entry in entries:
business_entity_transfer = entry.business_entity_transfer
Java
import java.io.IOException;
import com.chargebee.*;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
public class Sample{
public static void main(String args[]) throws IOException{
Environment.configure("{site}","{site_api_key}");
ListResult result = BusinessEntity.getTransfers()
.resourceType("customer")
.activeResourceId("Customer-1")
.request();
for(ListResult.Entry entry:result) {
BusinessEntityTransfer businessEntityTransfer = entry.businessEntityTransfer();
}
System.out.println(result);
}
}
.NET
using ChargeBee.Api;
using ChargeBee.Models;
ApiConfig.Configure("{site}","{site_api_key}");
ListResult result = BusinessEntity.GetTransfers()
.ResourceType("customer")
.ActiveResourceId("Customer-1")
.Request();
foreach (var item in result.List){
BusinessEntityTransfer businessEntityTransfer = item.BusinessEntityTransfer;
}
Node
var chargebee = require("chargebee");
chargebee.configure({site : "{site}",
api_key : "{site_api_key}"})
chargebee.business_entity.get_transfers({
resource_type : "customer",
active_resource_id : "Customer-1"
}).request(function(error,result) {
if(error){
//handle error
console.log(error);
}else{
for(var i = 0; i < result.list.length;i++){
var entry=result.list[i]
console.log(entry);
var business_entity_transfer = entry.business_entity_transfer;
}
}
});
Go
package main
import (
"fmt"
"github.com/chargebee/chargebee-go/v3"
"github.com/chargebee/chargebee-go/v3/filter"
businessEntityAction "github.com/chargebee/chargebee-go/v3/actions/businessEntity"
"github.com/chargebee/chargebee-go/v3/models/businessEntity"
)
func main() {
chargebee.Configure("{site_api_key}","{site}");
res,err := businessEntityAction.GetTransfers(&businessEntity.GetTransfersRequestParams {
ResourceType : "customer",
ActiveResourceId : "Customer-1",
}).ListRequest()
if err != nil {
fmt.Println(err)
}else{
for idx := 0; idx < len(res.List); idx++ {
BusinessEntityTransfer := res.List[idx].BusinessEntityTransfer
}
}
}
TypeScript
import {
ChargeBee,
_business_entity
} from 'chargebee-typescript';
var chargebee = new ChargeBee();
chargebee.configure({site : "{site}",
api_key : "{site_api_key}"});
chargebee.business_entity.get_transfers({
resource_type : "customer",
active_resource_id : "Customer-1"
}).request(function(error,result) {
if(error){
//handle error
console.log(error);
}else{
for(var i = 0; i < result.list.length;i++){
var entry=result.list[i]
console.log(`${entry}`);
var business_entity_transfer: typeof chargebee.business_entity_transfer = entry.business_entity_transfer;
}
}
});
Sample response
Click here to expand...
{
"list": [
{
"business_entity_transfer": {
"id": "__dev__263BEVU6h5FoKu",
"resource_type": "customer",
"reason_code": "Correction",
"created_at": 1608209939,
"object": "business_entity_transfer",
"destination_business_entity_id": "Entity-4",
"source_business_entity_id": "Entity-3",
"resource_id": "__dev__263BEVU6h5FlTp",
"active_resource_id": "__dev__263BEVU6h5DnYj"
}
},
{
"business_entity_transfer": {
"id": "__dev__263BEVU6h5FoKu",
"resource_type": "customer",
"reason_code": "Correction",
"created_at": 1608209639,
"object": "business_entity_transfer",
"destination_business_entity_id": "Entity-3",
"source_business_entity_id": "Entity-2",
"resource_id": "__dev__263BEVU6h5FlTo",
"active_resource_id": "__dev__263BEVU6h5DnYj"
}
},
{
"business_entity_transfer": {
"id": "__dev__263BEVU6h5FoKt",
"resource_type": "customer",
"reason_code": "Correction",
"created_at": 1608209339,
"object": "business_entity_transfer",
"destination_business_entity_id": "Entity-2",
"source_business_entity_id": "Entity-1",
"resource_id": "__dev__263BEVU6h5FlTn",
"active_resource_id": "__dev__263BEVU6h5DnYj"
}
}
]
}
1 | sort_by[<sort-order>] STRING FILTER Sorts based on the specified attribute. Supported attributes : created_at Supported sort-orders : asc and desc
Example → sort_by[asc] = "created_at" (This will sort the result based on the 'created_at' attribute in ascending(earliest first) order.) |
2 | limit INTEGER DEFAULT = 10 MIN =1 MAX=100
The number of resources to be returned. |
3 | offset STRING MAXCHARS=1000
Determines your position in the list for pagination. To ensure that the next page is retrieved correctly, always set offset to the value of next_offset obtained in the previous iteration of the API call. |
Filter parameters
1 | resource_type[<operator>] STRING FILTER Filter business_entity_transfer resources based on resource_type .
|
2 | resource_id[<operator>] STRING FILTER Filter business_entity_transfer resources based on resource_id .
|
3 | active_resource_id[<operator>] STRING FILTER
Filter business_entity_transfer resources based on active_resource_id . |
4 | created_at[<operator>] UNIX TIME IN SECONDS FILTER Filter business_entity_transfer resources based on created_at . Supported operators : after , before , on , between
Example → created_at[after] = "1702022464" |
Returns
| Attribute | Description |
---|
1 | business_entity_transfer
| ALWAYS RETURNED Resource object representing business_entity_transfer. |
2 | next_offset
| STRING MAX CHARS=1000 This attribute is returned only if more resources are present. To fetch the next set of resources use this value for the input parameter offset . |