> ## Documentation Index
> Fetch the complete documentation index at: https://docs.suprsend.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Tenants

> Learn how to create, update, fetch, & list tenants using Java SDK.

Tenants (previously named as brands) are used for white labeling notifications, personalizing template content or capturing admin preferences for another entity/organization. Tenants are workspace-level entities and by default, a tenant with `tenant_id="default"` (representing your organization) is created your workspace. Read more about tenants [here](/docs/tenants).

## Create / Update Tenant

This method will create a new tenant or update an existing tenant.

<CodeGroup>
  ```java Request theme={"system"}
  import org.json.JSONObject;

  import suprsend.Suprsend;
  import suprsend.SuprsendAPIException;

  public class Tenants {
    public static void main(String[] args) throws Exception {
      updateTenant();
    }

    private static Subscriber updateTenant() throws SuprsendException {
  		Suprsend suprsendClient = new Suprsend("_workspace_key_", "_workspace_secret_");

      // Create Tenant data JSON
      String tenantId = "br-01";
      JSONObject payload = new JSONObject()
        .put("tenant_name", "awesome tenant")
        .put("logo", "https://ik.imagekit.io/l0quatz6utm/suprsend/staging/media/suprsend-only-logo_c8aa27faef118418e8c5bd7b31a1cafc74e09200.png")
        .put("primary_color", "#ff0000")
        .put("secondary_color", "#0000ff")
        .put("tertiary_color", "#00ffff")
        .put("social_links", new JSONObject()
             .put("website", "https://www.company.com")
             .put("youtube", "https://www.company.com/youtube")
             .put("x", "https://www.company.com/x")
             .put("facebook", "")
             .put("linkedin", "")
             .put("instagram", "")
             .put("discord", "")
             .put("medium", "")
             .put("telegram", "")
             .put("tiktok","")
            )
        .put("properties", new JSONObject()
             .put("address", "my company address")
            )
        ;
      try {
        JSONObject res = suprClient.tenants.upsert(tenantId, payload);
        System.out.println(res);
      } catch (SuprsendException e) {
        System.out.println(e);
      }
    }
  	}
  ```
</CodeGroup>

| Field                                   | Description                                                                                                                                                                                                                                                                                                                                                                                                  |   |
| :-------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | - |
| `tenant_id` (mandatory)                 | max 64 characters and should contains alphanumeric characters(a-z, 0-9), hyphen (-) and underscode(\_). tenant\_id is case-insensitive. Suprsend will first converts tenant\_id to lowercase before storing it or doing any sort of comparison on it.                                                                                                                                                        |   |
| `tenant_name` (mandatory)               | name of the tenant.                                                                                                                                                                                                                                                                                                                                                                                          |   |
| `colors` (primary, secondary, tertiary) | colors settings are mainly used while designing templates. If you don't provide any of the colors for the brand, SuprSend will assume you want to use the default values, so color settings will automatically be set to the color settings of `default` brand.                                                                                                                                              |   |
| `social_links`                          | URLs of social media accounts of the tenant. While updating a social link, if you pass its value as null, then SuprSend will ignore it. If you really want to remove the value you must the `value= " "` (instead of null). for example If you want to remove social\_link url for `facebook`, you must pass `facebook= " "`. Consider this code block for the same:`{ "social_links": {"facebook": " " } }` |   |
| `properties`                            | Custom properties associated with the tenant. Update operation is upsert (new properties are added to existing one's and if key is already present, value is overridden).                                                                                                                                                                                                                                    |   |

All properties of the tenant can be referred as `{{$brand.prop}}` (handlebars) or `data["tenant"].prop` in JSONNET format.

## Get tenant

<CodeGroup>
  ```java Request theme={"system"}
  String tenantId = "_tenant_id_";
  JSONObject res = suprClient.tenants.get(tenantId);
  System.out.println(res);
  ```

  ```java Response theme={"system"}
  {
  	"tenant_id": "_tenant_id_",
  	"tenant_name": "Tenant Name",
  	"logo": "https://logo.url",
  	"primary_color": "#ff0000",
  	"secondary_color": "#00ff00",
  	"tertiary_color": "#0000ff",
  	"social_links": {
  		"website": "",
  		"facebook": "",
  		"linkedin": "",
  		"x": "",
  		"instagram": "",
  		"medium": "",
  		"discord": "",
  		"telegram": "",
  		"youtube": "",
      "tiktok": ""
  	},
  	"properties": {
  		"prop1": "value1",
  		"prop2": "value2"
  	}
  }
  ```
</CodeGroup>

## List tenants

By default, `limit=20`. The maximum value for `limit` is `1000`.

<CodeGroup>
  ```java Request theme={"system"}
  JSONObject res = suprClient.tenants.list();

  //Get list with offset = 10 and limit = 20
  //JSONObject res = suprClient.tenants.list(20,10);

  System.out.println(res);
  ```

  ```java Response theme={"system"}
  {
    "meta": {
    	"limit": 20,
      "offset": 0,
      "count": 1
    },
    "results": [
      {
        "tenant_id": "tenant-id",
        "tenant_name": "Tenant Name",
        "logo": "https://logo.url",
        "primary_color": "#ff0000",
        "secondary_color": "#00ff00",
        "tertiary_color": "#0000ff",
        "social_links": {
          "website": "",
          "facebook": "",
          "linkedin": "",
          "x": "",
          "instagram": "",
          "medium": "",
          "discord": "",
          "telegram": "",
          "youtube": "",
          "tiktok": ""
        },
        "properties": {
          "prop1": "value1",
          "prop2": "value2"
        }
      }
    ]
  }
  ```
</CodeGroup>

## Add tenant in Workflow

<CodeGroup>
  ```java Request theme={"system"}
  WorkflowTriggerRequest wf = new WorkflowTriggerRequest(body, tenantId);
  ```
</CodeGroup>

## Add tenant in Event

<CodeGroup>
  ```java Request theme={"system"}
  Event e = new Event(distinctId, eventName, eventProps, , brandId);
  ```
</CodeGroup>
