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

# Sample SDK Initialization

<Note>
  This flow is provided as an example scenario for initializing an Onboarding SDK 3 instance.
  Your experience may differ depending on your contract with Worth services.
</Note>

The following document details an end-to-end scenario of using the Worth API to invite a business to the onboarding platform and using the returned `invite_token` to initialize an Onboarding SDK 3 instance.

This flow consists of two sequential API calls that handle signing into the Worth platform as a customer and inviting a business to complete an application.

## Overview

The business onboarding process follows a linear sequence of API calls:

```mermaid theme={null}
flowchart LR
    A[Customer Sign-in] --> B[Invite Business]
    B --> C[Initialize SDK]
```

This diagram shows the complete sequence of API calls required for the business onboarding process:

```mermaid theme={null}
sequenceDiagram
    actor Customer
    participant WorthAPI as Worth API
    participant SDK as Worth SDK

    Note over Customer,WorthAPI: Step 1: Customer Sign-in
    Customer->>+WorthAPI: POST /auth/api/v1/customer/sign-in
    Note right of Customer: Request: email, password
    WorthAPI-->>-Customer: Response: data.id_token

    Note over Customer,WorthAPI: Step 2: Send Business Invite
    Customer->>+WorthAPI: POST /case/api/v1/customers/{customerID}/businesses/invite
    Note right of Customer: Request: business, applicant, and onboarding template version ID <br/>Auth: customer token (data.id_token)
    WorthAPI-->>-Customer: Response: invititation_url

    Note over Customer,SDK: Step 3: Initialize SDK
    Customer->>+SDK: Pass invite token to SDK
    Note right of Customer: Request: invite_token extracted from invitation_url
```

> **Note**: In this scenario, the customer application in which the Onboarding SDK is mounted does **not** send requests to the `customer/sign-in` or `businesses/invite` endpoints

## Key Points

**Step 1 - Customer Sign-in**:

* Using the POST `/auth/api/v1/customer/sign-in` endpoint, a customer may sign into the Worth platform with their email and password
  * See [Customer Sign In](/api-reference/auth/sign-in/customer-sign-in) for a complete reference of this endpoint
* Upon successfully signing in, an `id_token` will have been returned in the request response. This token should be used when authenticating subsequent requests

  ```
  POST  /auth/api/v1/customer/sign-in
  ```

  ```json theme={null}
  // Sample request body
  {
    "email": "customer@joinworth.com",
    "password": "12345"
  }
  ```

  ```json theme={null}
  // Sample response
  {
      "status": "success",
      "message": "Logged In successfully",
      "data": {
          "user_details": {
              "id": "c03d6f6a-012a-4e71-8195-9f6f590a0000",
              "first_name": "Sample",
              "last_name": "Customer",
              "email": "customer@joinworth.com",
              "is_email_verified": true
          },
          "access_token": "{access_token}",
          "id_token": "{id_token}",
          "refresh_token": "{refresh_token}",
          "subrole": {
              // ...
          },
          "permissions": [
              // ...
          ],
          "customer_details": {
              "id": "a04d6f6a-59ab-4e71-8195-9f6f590a1234",
              "name": "Sample Customer"
          }
      }
  }
  ```

> **Important**: Always use the `id_token` for secure API communication in subsequent steps

**Step 2 - Send Business Invite**:

* Using the POST `/case/api/v1/customers/{customerID}/businesses/invite` endpoint, a customer may send an invite to a business to complete a Worth onboarding application
* The `id_token` that is received from the sign-in step should be passed into the `Authentication` header when POSTing to this endpoint
* Within the body of this request, the following attributes must be provided: `business`, `applicants`, and `template_version_id`
  * See [Send Business Invite](/api-reference/case/invites/send-business-invite#send-business-invite) for a complete reference of this endpoint
* Upon successfully sending a business invite, an `invitation_url` will have been returned in the request response. This URL will contain the token that should be passed into the SDK 3 instance

See example:

```
POST  /case/api/v1/customers/:customerID/businesses/invite
```

```json theme={null}
// Sample request body
{
    "business": {
        "name": "Sample Business"
    },
    "applicants": [
        {
            "first_name": "John",
            "last_name": "Smith",
            "email": "jsmith@example.com"
        }
    ],
    "template_version_id": "b03d6f6a-063b-4e71-8195-9f6f590a6257"
}
```

```json theme={null}
// Sample response
{
    "status": "success",
    "message": "Business invited successfully",
    "data": {
        "business_id": "52310d5d-7d7a-4ae8-ab00-7849bb0d4f5a",
        "applicant_email": "jsmith@example.com",
        "invitation_id": "57ff5d40-f25d-44f4-9f4c-6640b63a74ea",
        "customer_id": "a04d6f6a-59ab-4e71-8195-9f6f590a1234",
        "onboarding_instance_id": "876f6b5b-17b3-46ae-8cbf-c912b1036c07",
        "invitation_url": "https://app.joinworth.com/onboarding/verify/invite?token={invite_token}&first_name=John&last_name=Smith&business_name=Sample%20Business&customer_name=Sample%20Customer%20&is_co_applicant=false"
    }
}
```

**Step 3 - Initialize SDK**:

* In the customer application in which the SDK is mounted, call `createWorthOnboarding` with the extracted `invite_token`
  * See the full [Quick Start Guide](/onboarding-sdk-3/quickstart) for a step-by-step walkthrough, including cleanup and error handling

## Related Documentation

* Check the [Getting Started](/getting-started/overview) guide for key concepts
* Explore [Business Onboarding Flows](/use-cases/onboarding/overview) for additional use cases

***

## Support

For questions or issues, please contact your Worth Customer Success team or reach out to [support@joinworth.com](mailto:support@joinworth.com).
