import { Col, DangerNote, Note, Properties, Row, WarningNote } from '../../../components/mdx'
import { Tag } from '../../../components/Tag'
import { TimelineContainer } from '../../../components/TimelineContainer'
import { TimelineHeader } from '../../../components/TimelineHeader'
import { TimelineBody } from '../../../components/TimelineBody'
import { Card, CardContent, CardFooter, CardHeader, CardTitle } from '../../../components/ui/card'
import { UpBubbleIcon } from '../../../components/icons/UpBubbleIcon'
import { ThumbUpIcon } from '../../../components/icons/ThumbUpIcon'
import { EmailBubbleIcon } from '../../../components/icons/EmailBubbleIcon'
import { BentoCoinIcon } from '../../../components/icons/BentoCoinIcon'
import { SectionTitle } from '../../../components/SectionTitle'
import ClipboardButton from '../../../components/ui/ClipboardButton'
import { Code } from '../../../components/Code'
import {
  Accordion,
  AccordionContent,
  AccordionItem,
  AccordionTrigger,
} from "@/components/ui/accordion"
import { Collapsable } from '../../../components/MDXCollapsible'
import CodeSample from '../../../components/CodeSample'
import { ArrowIcon } from '../../../components/icons/ArrowIcon'
import Link from 'next/link'
import { GuideLinkCards } from '../../../components/GuideLinks'

export const exampleFile = 'rust-guide-examples'
export const metadata = {
  title: 'Rust SDK Guide',
  description:
    "Today, we'll explore integrating the Rust SDK from Bento.",
}



# Bento Rust Guide

This guide will help you implement Bento into your Rust applications, regardless of your development experience.

<div className="grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-2">
  <GuideLinkCards
    icon={UpBubbleIcon}
    title="Getting Started"
    links={[
      { label: 'Installation', href: '#installation' },
      { label: 'Basic Setup', href: '#basic-setup' },
    ]}
  />

  <GuideLinkCards
    icon={ThumbUpIcon}
    title="Beginner Guide"
    links={[
      { label: 'Tracking Your First Event', href: '#tracking-your-first-event' },
      { label: 'Managing Subscribers', href: '#managing-subscribers' },
      { label: 'Common Use Cases', href: '#common-use-cases' },
    ]}
  />

  <GuideLinkCards
    icon={EmailBubbleIcon}
    title="Intermediate Guide"
    links={[
      { label: 'Custom Fields and Tags', href: '#custom-fields-and-tags' },
      { label: 'Tracking Purchase Events', href: '#tracking-purchase-events' },
      { label: 'Namespaced Tags', href: '#using-custom-fields-and-tags' },
    ]}
  />

  <GuideLinkCards
    icon={BentoCoinIcon}
    title="Advanced Guide"
    links={[
      { label: 'Batch Operations', href: '#batch-operations' },
      { label: 'Transactional Emails', href: '#transactional-emails' },
      { label: 'Subscriber Updates', href: '#subscriber-updates' },
      { label: 'Utility Features', href: '#utility-features' },
    ]}
  />
</div>

### Reference
<div className={'flex flex-col gap-y-1 mb-8'}>
  <div><span className={'text-xl text-violet-500'}>#</span> [API Reference](#api-reference)</div>
  <div><span className={'text-xl text-violet-500'}>#</span> [Troubleshooting](#troubleshooting)</div>
  <div><span className={'text-xl text-violet-500'}>#</span> [FAQ](#faq)</div>
</div>

<SectionTitle title={'Getting Started'}/>

<div className={'ml-4'}>
  <TimelineContainer>
    <TimelineHeader title={'Package Installation'} number={'1'}/>
    <TimelineBody>
      ## Installation

      Install the Bento Rust SDK in your project:

      <CodeSample exampleFile={exampleFile} exampleKey="install_cargo"  />
    </TimelineBody>

    <TimelineHeader title={'Client Configuration'} number={'2'}/>
    <TimelineBody>
      ## Basic Setup

      To initialize the Bento client, you'll need your Site UUID, Publishable Key, and Secret Key from your Bento account.
      You can find your keys in your [Bento Team](https://app.bentonow.com/account/teams). To see your keys click
      `Your Private API Keys` Button and if do you do not see a Publishable key and Secret Key, click on `Generate Key` to
      create a set.

      <CodeSample exampleFile={exampleFile} exampleKey="basic_setup"  />
    </TimelineBody>
  </TimelineContainer>
</div>

<SectionTitle title={'Beginner Guide'}/>

## Tracking Your First Event

Events represent specific actions users take within your application. Tracking these actions provides valuable insights
into user behavior patterns and engagement.

#### Streamlined Subscriber Management
We recommend using Events as the preferred method to add subscribers, as they simultaneously initiate workflows and
automations in a single operation.

#### Powerful Data Enrichment
Events excel at capturing contextual information alongside user actions. This can be used in emails via
[liquid tags](/liquid_guide) or in segmentation. For instance, when recording a purchase event, you can include detailed
transaction information such as:

| Detail                                                   | Liquid tag                                                                                                                                         |
|----------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|
| <span className="text-violet-400">Product details</span> | <ClipboardButton isColored={true} textToCopy='{{ event.details.product.size }}' defaultLabel="{{ event.details.product.size }}" />                 |
| <span className="text-violet-400">Purchase amount</span> | <ClipboardButton isColored={true} textToCopy='{{ event.details.value.amount }}' defaultLabel="{{ event.details.value.amount }}" />                 |
| <span className="text-violet-400">Transaction ID</span>  | <ClipboardButton isColored={true} textToCopy='{{ event.details.value.amount }}' defaultLabel="{{ event.details.value.amount }}" />                 |
| <span className="text-violet-400">Payment method</span>  | <ClipboardButton isColored={true} textToCopy='{{ event.details.value.payment_method }}' defaultLabel="{{ event.details.value.payment_method }}" /> |

### Practical Example
When a customer completes a purchase, you can track this as an event while including all relevant purchase details. This
approach enables you to:

- Trigger specific post-purchase workflows
- Launch targeted follow-up automations
- Track lifetime value (LTV) metrics
- Create personalized communications based on purchase history


<CodeSample exampleFile={exampleFile} exampleKey="simple_page_view"  />

<CodeSample exampleFile={exampleFile} exampleKey="track_form_submission"  />

## Managing Subscribers

If you need to manage subscribers directly there are a set of convenience methods available to you. Add, update, and
unsubscribe subscribers with these simple methods. Currently, you cannot remove subscribers via the API, but you can
remove them from the dashboard `People > All Users`.

<Collapsable defaultOpen={false} openLabel="2 More Samples">
  <summary>
    <CodeSample exampleFile={exampleFile} exampleKey="create_a_new_subscriber"  />
  </summary>
  <content>

    <CodeSample exampleFile={exampleFile} exampleKey="tag_a_subscriber"  />
    <CodeSample exampleFile={exampleFile} exampleKey="unsubscribe_a_subscriber"  />
  </content>
</Collapsable>



#### Adding Individual Subscribers
Please note, while these methods make it easy to manage a subscriber, the Bento recommended way to add **a** subscriber
is via an `event`. This allows you to kick off sequences and automations, while also recording the "event" at the same
time (1 API call).

#### Adding Multiple Subscribers
Importing or modifying multiple subscribers should be handled via the [bulk methods](/examples/nodejs#subscriber-updates),
instead of looping over these calls multiple times.


## Common Use Cases

Here are some common scenarios with ready-to-use code:
<Collapsable defaultOpen={false} openLabel="2 More Samples">
  <summary>
    <CodeSample exampleFile={exampleFile} exampleKey="tracking_user_login_event"  />
  </summary>
  <content>
    <CodeSample exampleFile={exampleFile} exampleKey="updaing_user_information"  />
    <CodeSample exampleFile={exampleFile} exampleKey="adding_multiple_tags_to_a_subscriber"  />
  </content>
</Collapsable>

<SectionTitle title={'Intermediate Guide'}/>

## Custom Fields and Tags

Bento allows you to store custom data about your users through fields and segment them with tags:
<Collapsable defaultOpen={false} openLabel="3 More Samples">
  <summary>
    <CodeSample exampleFile={exampleFile} exampleKey="create_a_new_custom_field_definition"  />
  </summary>
  <content>
    <CodeSample exampleFile={exampleFile} exampleKey="get_all_fields"  />
    <CodeSample exampleFile={exampleFile} exampleKey="create_a_new_tag"  />
    <CodeSample exampleFile={exampleFile} exampleKey="get_all_tags"  />
  </content>
</Collapsable>

## Using Custom Fields & Tags
While custom fields and tags can be used to segment subscribers, most Bento users find that namespaced tags provide a more
effective and easier-to-maintain solution for most segmentation use cases.

#### Namespaced Tags
Namespaced tags follow this format: `namespace`:`detail`
For example, if you offer three subscription plans, you could create these tags:
* `subscription:basic`
* `subscription:pro`
* `subscription:enterprise`

We recommend applying these tags either through an automated flow or via bulk updates.

<Note>Tags do not need to be namespaced, but for many customers the organization pays off by using namespaced tags when
  it makes sense.</Note>

#### Fields
Fields are perfect for storing information about your subscribers, such as their language, timezone,
or other relevant details. By using fields, you can easily segment subscribers based on their specific needs and
preferences, allowing you to tailor your marketing efforts and messaging to each group.

The primary difference between
fields and namespaced tags is that fields are not limited to a specific detail and do not need to be predefined. You can
store any type of data in a field, including strings, numbers, or even objects. This flexibility makes fields a powerful
tool for storing data.

#### Best Practices
For optimal organization, consider using tags for segmentation while storing more detailed user information in custom
fields. Many successful implementations use a strategic combination of both approaches.


## Tracking Purchase Events

When recording purchase events, you must include a `unique:` key as part of the tracking data. This requirement prevents
duplicate transactions from being recorded in your analytics.

Most users find it beneficial to use their internal cart or order number as the `unique:` key. This approach simplifies
future lookups and maintains consistency across your systems. The `unique:` key value you provide is accessible through
liquid tags when creating custom email templates, allowing for personalized transactional messaging based on specific
purchase details.

Tracking purchases is a great way to monitor customer lifetime value (LTV) and identify recurring customers. Bento reports
on the LTV of each subscriber, allowing you to identify high-value customers and tailor your marketing efforts accordingly.

<CodeSample exampleFile={exampleFile} exampleKey="tracking_purchase_events"  />

<SectionTitle title={'Advanced Guide'}/>

## Batch Operations

For efficiency, we suggest using batch operations when integrating with Bento. These methods allow for single or bulk
operations on subscribers and events, improving the performance and scalability of your integration. They also cover more
than 80% of the API use cases for most customers.

<CodeSample exampleFile={exampleFile} exampleKey="import_multiple_subscribers"  />
<CodeSample exampleFile={exampleFile} exampleKey="import_multiple_events"  />


## Transactional Emails

Bento allows you to send personalized transactional emails for time-sensitive, direct communications. These emails serve
specific functional purposes rather than marketing objectives.

<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
  <div className=" ">
    #### Ideal Transactional Email Use Cases
    * User onboarding (confirmation etc)
    * Password reset notifications
    * Sign-in verification links
    * Order confirmations and details
    * Account notifications
  </div>

  <div className="md:bg-neutral-900 rounded-lg md:pl-4">
    #### NOT Ideal Transactional Email Use Cases
    * CC / BCC recipients
    * Emails that require an attachment (we suggest always using links for emails for best deliverability)
    * Marketing of any kind
    * Promotional content
    * Newsletters
  </div>
</div>



#### From Address Requirements
The sender address used in your transactional emails must be configured as an Author email within your Bento settings.
Please note that generic addresses such as "~[no-reply@domain.com](mailto:no-reply@domain.com)~" or similar non-personal
addresses are not currently supported.

#### Important Distinction
**Transactional** emails are designed for **essential communications** that facilitate specific **user actions** or provide
critical information.

<DangerNote>Transactional emails should **not** be used as substitutes for **marketing** campaigns or **promotional**
  content.</DangerNote>


<CodeSample exampleFile={exampleFile} exampleKey="send_transactional_emails"  />

## Subscriber Updates

Many organizations joining Bento already have an established subscriber base that requires bulk updates over time. These
updates commonly include setting field data and managing tags across multiple subscribers. We firmly believe that these
methods are the best way to manage a single or multiple subscribers, and we recommend using them for all subscriber
updates.

<Note>These methods cover more than 80% of the API use cases for most customers.</Note>

#### Choosing the Right Update Method:


The SDK offers multiple approaches for creating subscribers in Bento, each suited to different scenarios.

#### Preferred Method: Events

The recommended way to create subscribers is via events in response to user activity. This approach activates
automations, workflows, and can contain data enrichment.

<Collapsable defaultOpen={false} openLabel="1 More Sample">
  <summary>
    <CodeSample exampleFile={exampleFile} exampleKey="create_a_subscriber_when_they_sign_up"  />
  </summary>
  <content>
    <CodeSample exampleFile={exampleFile} exampleKey="create_a_subscriber_when_they_make_a_purchase"  />
  </content>
</Collapsable>

#### Alternative Methods

For scenarios where you need to create subscribers independently of user actions:
<TimelineContainer>
  <TimelineHeader title={'Single Subscriber Creation'} number={'1'} />
  <TimelineBody>
    Use this method when you need to quickly create a single subscriber with minimal data:

    <CodeSample exampleFile={exampleFile} exampleKey="create_a_single_subscriber"  />

    <WarningNote> This endpoint is rate-limited and not suitable for loops or bulk creation. Use only for individual subscriber creation.</WarningNote>

  </TimelineBody>
  <TimelineHeader title={'Multiple Or Enriched Subscriber Creation'} number={'2'} />
  <TimelineBody>
    For creating multiple subscribers or including additional fields:

    <CodeSample exampleFile={exampleFile} exampleKey="import_multiple_subscribers_at_once"  />

    Best Practices for Batch Imports:
    * Though the API supports up to 1,000 subscribers per call, we recommend batches of 200-300 for optimal performance when dealing with extensive data.
    * Include all relevant custom fields in the initial import to minimize follow-up updates.
    * For very large imports (10,000+ subscribers), consider implementing a queue system with delay between batches.

  </TimelineBody>
</TimelineContainer>

#### Updating Subscribers
Depending on your requirements, several approaches are available for updating subscriber information.

#### Event-Based Updates (Preferred)
When updates occur in response to user actions, tracking events is the recommended approach:

<CodeSample exampleFile={exampleFile} exampleKey="update_subscriber_when_they_update_their_profile"  />

<Note>Becuase you can apply as many changes via automations / workflows as you want this is the most flexible method.
  It doesn't require code or deployment changes, and can be completely handled in Bento. </Note>

#### Alternative Update Methods

For updates outside of user-triggered actions:
<TimelineContainer>
  <TimelineHeader title="Single Attribute Updates" number={'1'}/>
  <TimelineBody>
    For quickly updating a specific attribute on a single subscriber:
    <Collapsable defaultOpen={false} openLabel="2 More Samples">
      <summary>
        <CodeSample exampleFile={exampleFile} exampleKey="add_or_update_a_single_field"  />
      </summary>
      <content>
        <CodeSample exampleFile={exampleFile} exampleKey="add_a_tag"  />
        <CodeSample exampleFile={exampleFile} exampleKey="remove_a_field"  />
      </content>
    </Collapsable>

    <WarningNote>The Command API is not recommended for multiple updates or bulk operations. Given its heavy rate limit, use the Batch API instead.</WarningNote>
  </TimelineBody>
  <TimelineHeader title="Batch Updates" number={'2'}/>
  <TimelineBody>
    For updating multiple subscribers or multiple fields at once, use the batch import method:

    <CodeSample exampleFile={exampleFile} exampleKey="update_multiple_subscribers"  />

    Recommendations:
    * Even for single-subscriber updates, consider using the batch import method when multiple fields need updating.
    * The batch import performs an "upsert" operation – it creates subscribers that don't exist and updates those that do.
    * This approach provides the most flexibility as your use cases evolve, whether you need to add more changes or modify multiple users simultaneously.

  </TimelineBody>
</TimelineContainer>

#### Specialized Update Operations
For specific update scenarios, the SDK offers dedicated methods:

<Collapsable defaultOpen={false} openLabel="2 More Samples">
  <summary>
    <CodeSample exampleFile={exampleFile} exampleKey="change_a_subscribers_email_address"  />
  </summary>
  <content>

    <CodeSample exampleFile={exampleFile} exampleKey="update_all_fields_at_once"  />
    <CodeSample exampleFile={exampleFile} exampleKey="unsubscribe_a_user"  />
  </content>
</Collapsable>

## Utility Features

These features provide additional convenience utility for Bento users, to handle some of the common secondary use cases
we commonly see, such as validation and blacklist checks.

<Collapsable defaultOpen={false} openLabel="3 More Samples">
  <summary>
    <CodeSample exampleFile={exampleFile} exampleKey="validate_email"  />
  </summary>
  <content>
    <CodeSample exampleFile={exampleFile} exampleKey="guess_gender"  />
    <CodeSample exampleFile={exampleFile} exampleKey="geolocate_ip"  />
    <CodeSample exampleFile={exampleFile} exampleKey="check_blacklist"  />

  </content>
</Collapsable>

<SectionTitle title={'API Reference'}/>

#### Core API

- **Client** - Main entry point for using the SDK (`bento::Client`)
- **Configuration** - Set up through the `bento::Config` struct with API keys and settings
- **Context Support** - All API operations are async and support cancellation via futures
- **Data Types** - Structured request/response types in the root package (`bento::EventData`, `bento::ImportSubscriberData`, etc.)
- **Error Handling** - Predefined error types (`Error::InvalidConfig`, `Error::InvalidEmail`, etc.) for specialized error handling


### Convenience Methods


#### Core API

| Use Case                                                                         | Rust SDK Method                                                                                                                                            |
|----------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|
| <span className="text-violet-400"> Add a new subscriber </span>                  | <ClipboardButton isColored={true} textToCopy='client.create_subscriber(email).await' defaultLabel="client.create_subscriber(email).await" />               |
| <span className="text-violet-400">Unsubscribe a subscriber </span>               | <ClipboardButton isColored={true} textToCopy='client.subscriber_command(commands).await' defaultLabel="client.subscriber_command(commands).await" />       |
| <span className="text-violet-400">Update data for an existing subscriber </span> | <ClipboardButton isColored={true} textToCopy='client.import_subscribers(subscribers).await' defaultLabel="client.import_subscribers(subscribers).await" /> |
| <span className="text-violet-400">Add a tag to a subscriber </span>              | <ClipboardButton isColored={true} textToCopy='client.subscriber_command(commands).await' defaultLabel="client.subscriber_command(commands).await" />       |
| <span className="text-violet-400">Update subscriber fields </span>               | <ClipboardButton isColored={true} textToCopy='client.subscriber_command(commands).await' defaultLabel="client.subscriber_command(commands).await" />       |
| <span className="text-violet-400">Track a custom event </span>                   | <ClipboardButton isColored={true} textToCopy='client.track_events(events).await' defaultLabel="client.track_events(events).await" />                       |
| <span className="text-violet-400">Track a purchase event </span>                 | <ClipboardButton isColored={true} textToCopy='client.track_events(events).await' defaultLabel="client.track_events(events).await" />                       |


### Modules

#### Batch
| Use Case                                                              | Method                                                                                                                                                     | API Reference                                                                                                                                         |
|-----------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| <span className="text-violet-400">Import multiple subscribers </span> | <ClipboardButton isColored={true} textToCopy='client.import_subscribers(subscribers).await' defaultLabel="client.import_subscribers(subscribers).await" /> | <Link href="/subscribers#import-subscribers" className="inline-flex items-center gap-1">Import Subscribers <ArrowIcon className={'h-6 w-6'} /></Link> |
| <span className="text-violet-400">Import multiple events </span>      | <ClipboardButton isColored={true} textToCopy='client.track_events(events).await' defaultLabel="client.track_events(events).await" />                       | <Link href="/events_api#create-events" className="inline-flex items-center gap-1">Import Events <ArrowIcon className={'h-6 w-6'} /></Link>            |
| <span className="text-violet-400">Send emails </span>                 | <ClipboardButton isColored={true} textToCopy='client.send_emails(batch).await' defaultLabel="client.send_emails(batch).await" />                           | <Link href="/emails_api#create-emails" className="inline-flex items-center gap-1">Send Emails <ArrowIcon className={'h-6 w-6'} /></Link>              |

#### Commands
| Use Case                                                       | Method                                                                                                                                                     | API Reference                                                                                                                                        |
|----------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|
| <span className="text-violet-400">Add a tag </span>            | <ClipboardButton isColored={true} textToCopy='client.import_subscribers(subscribers).await' defaultLabel="client.import_subscribers(subscribers).await" /> | <Link href="/subscribers#import-subscribers" className="inline-flex items-center gap-1">Subscriber Upsert <ArrowIcon className={'h-6 w-6'} /></Link> |
| <span className="text-violet-400">Remove a tag </span>         | <ClipboardButton isColored={true} textToCopy='client.import_subscribers(subscribers).await' defaultLabel="client.import_subscribers(subscribers).await" /> | <Link href="/subscribers#import-subscribers" className="inline-flex items-center gap-1">Subscriber Upsert <ArrowIcon className={'h-6 w-6'} /></Link> |
| <span className="text-violet-400">Add a field </span>          | <ClipboardButton isColored={true} textToCopy='client.import_subscribers(subscribers).await' defaultLabel="client.import_subscribers(subscribers).await" /> | <Link href="/subscribers#import-subscribers" className="inline-flex items-center gap-1">Subscriber Upsert <ArrowIcon className={'h-6 w-6'} /></Link> |
| <span className="text-violet-400">Remove a field </span>       | <ClipboardButton isColored={true} textToCopy='client.import_subscribers(subscribers).await' defaultLabel="client.import_subscribers(subscribers).await" /> | <Link href="/subscribers#import-subscribers" className="inline-flex items-center gap-1">Subscriber Upsert <ArrowIcon className={'h-6 w-6'} /></Link> |
| <span className="text-violet-400">Subscribe a user </span>     | <ClipboardButton isColored={true} textToCopy='client.subscriber_command(commands).await' defaultLabel="client.subscriber_command(commands).await" />       | <Link href="/subscribers#run-command" className="inline-flex items-center gap-1">Subscriber Command <ArrowIcon className={'h-6 w-6'} /></Link>       |
| <span className="text-violet-400">Unsubscribe a user </span>   | <ClipboardButton isColored={true} textToCopy='client.subscriber_command(commands).await' defaultLabel="client.subscriber_command(commands).await" />       | <Link href="/subscribers#run-command" className="inline-flex items-center gap-1">Subscriber Command <ArrowIcon className={'h-6 w-6'} /></Link>       |
| <span className="text-violet-400">Change email address </span> | <ClipboardButton isColored={true} textToCopy='client.subscriber_command(commands).await' defaultLabel="client.subscriber_command(commands).await" />       | <Link href="/subscribers#run-command" className="inline-flex items-center gap-1">Subscriber Command <ArrowIcon className={'h-6 w-6'} /></Link>       |

#### Experimental
| Use Case                                                            | Method                                                                                                                                           | API Reference                                                                                                                                   |
|---------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|
| <span className="text-violet-400">Validate email address </span>    | <ClipboardButton isColored={true} textToCopy='client.validate_email(data).await' defaultLabel="client.validate_email(data).await" />             | <Link href="/utility#validate-email" className="inline-flex items-center gap-1">Validate Email <ArrowIcon className={'h-6 w-6'} /></Link>       |
| <span className="text-violet-400">Predict gender from name </span>  | <ClipboardButton isColored={true} textToCopy='client.get_gender(name).await' defaultLabel="client.get_gender(name).await" />                     | <Link href="/utility#guess-gender" className="inline-flex items-center gap-1">Gender Guess <ArrowIcon className={'h-6 w-6'} /></Link>           |
| <span className="text-violet-400">Get IP geolocation </span>        | <ClipboardButton isColored={true} textToCopy='client.geolocate_ip(ip).await' defaultLabel="client.geolocate_ip(ip).await" />                     | <Link href="/utility#geolocate-ip-address" className="inline-flex items-center gap-1">IP Geolocation <ArrowIcon className={'h-6 w-6'} /></Link> |
| <span className="text-violet-400">Check domain/IP blacklist </span> | <ClipboardButton isColored={true} textToCopy='client.get_blacklist_status(data).await' defaultLabel="client.get_blacklist_status(data).await" /> | <Link href="/utility#search-blacklists" className="inline-flex items-center gap-1">Blacklist Check <ArrowIcon className={'h-6 w-6'} /></Link>   |

#### Fields
| Use Case                                                 | Method                                                                                                                         | API Reference                                                                                                                         |
|----------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|
| <span className="text-violet-400">Get all fields </span> | <ClipboardButton isColored={true} textToCopy='client.get_fields().await' defaultLabel="client.get_fields().await" />           | <Link href="/fields#get-fields" className="inline-flex items-center gap-1">Get Fields <ArrowIcon className={'h-6 w-6'} /></Link>      |
| <span className="text-violet-400">Create a field </span> | <ClipboardButton isColored={true} textToCopy='client.create_field(key).await' defaultLabel="client.create_field(key).await" /> | <Link href="/fields#create-field" className="inline-flex items-center gap-1">Create Fields <ArrowIcon className={'h-6 w-6'} /></Link> |

#### Subscribers
| Use Case                                                      | Method                                                                                                                                               | API Reference                                                                                                                                     |
|---------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|
| <span className="text-violet-400">Find subscriber </span>     | <ClipboardButton isColored={true} textToCopy='client.find_subscriber(email).await' defaultLabel="client.find_subscriber(email).await" />             | <Link href="/subscribers#find-subscriber" className="inline-flex items-center gap-1">Find Subscriber <ArrowIcon className={'h-6 w-6'} /></Link>   |
| <span className="text-violet-400">Create a subscriber </span> | <ClipboardButton isColored={true} textToCopy='client.create_subscriber(email).await' defaultLabel="client.create_subscriber(email).await" />         | <Link href="/subscribers#find-subscriber" className="inline-flex items-center gap-1">Create Subscriber <ArrowIcon className={'h-6 w-6'} /></Link> |
| <span className="text-violet-400">Run commands </span>        | <ClipboardButton isColored={true} textToCopy='client.subscriber_command(commands).await' defaultLabel="client.subscriber_command(commands).await" /> | <Link href="/subscribers#run-command" className="inline-flex items-center gap-1">Subscriber Commands <ArrowIcon className={'h-6 w-6'} /></Link>   |

#### Tags
| Use Case                                               | Method                                                                                                                       | API Reference                                                                                                                      |
|--------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|
| <span className="text-violet-400">Get all tags </span> | <ClipboardButton isColored={true} textToCopy='client.get_tags().await' defaultLabel="client.get_tags().await" />             | <Link href="/tags_api#get-tags" className="inline-flex items-center gap-1">List Tags <ArrowIcon className={'h-6 w-6'} /></Link>    |
| <span className="text-violet-400">Create a tag </span> | <ClipboardButton isColored={true} textToCopy='client.create_tag(name).await' defaultLabel="client.create_tag(name).await" /> | <Link href="/tags_api#create-tag" className="inline-flex items-center gap-1">Create Tag <ArrowIcon className={'h-6 w-6'} /></Link> |

#### Broadcasts
| Use Case                                                     | Method                                                                                                                                                 | API Reference                                                                                                                                      |
|--------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|
| <span className="text-violet-400">Get all broadcasts </span> | <ClipboardButton isColored={true} textToCopy='client.get_broadcasts().await' defaultLabel="client.get_broadcasts().await" />                           | <Link href="/broadcasts#get-broadcasts" className="inline-flex items-center gap-1">Get Broadcasts <ArrowIcon className={'h-6 w-6'} /></Link>       |
| <span className="text-violet-400">Create broadcasts </span>  | <ClipboardButton isColored={true} textToCopy='client.create_broadcasts(broadcasts).await' defaultLabel="client.create_broadcasts(broadcasts).await" /> | <Link href="/broadcasts#create-broadcasts" className="inline-flex items-center gap-1">Create Broadcasts <ArrowIcon className={'h-6 w-6'} /></Link> |

#### Stats
| Use Case                                                    | Method                                                                                                                                                 | API Reference                                                                                                                                 |
|-------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| <span className="text-violet-400">Get site stats </span>    | <ClipboardButton isColored={true} textToCopy='client.get_site_stats().await' defaultLabel="client.get_site_stats().await" />                           | <Link href="/stats#get-site-stats" className="inline-flex items-center gap-1">Get Site Stats <ArrowIcon className={'h-6 w-6'} /></Link>       |
| <span className="text-violet-400">Get segment stats </span> | <ClipboardButton isColored={true} textToCopy='client.get_segment_stats(segment_id).await' defaultLabel="client.get_segment_stats(segment_id).await" /> | <Link href="/stats#get-segment-stats" className="inline-flex items-center gap-1">Get Segment Stats <ArrowIcon className={'h-6 w-6'} /></Link> |
| <span className="text-violet-400">Get report stats </span>  | <ClipboardButton isColored={true} textToCopy='client.get_report_stats(report_id).await' defaultLabel="client.get_report_stats(report_id).await" />     | <Link href="/stats#get-report-stats" className="inline-flex items-center gap-1">Get Report Stats <ArrowIcon className={'h-6 w-6'} /></Link>   |

<SectionTitle title={'Troubleshooting'}/>

#### Common Errors

|                                                            |                                                                   |
|------------------------------------------------------------|-------------------------------------------------------------------|
| <Tag color={'rose'} variant={'large'}>Not Authorized</Tag> | Check your API keys and ensure they have appropriate permissions  |
| <Tag color={'rose'} variant={'large'}>Rate Limited</Tag>   | Implement backoff/retry logic for batch operations                |
| <Tag color={'rose'} variant={'large'}>Network Errors</Tag> | Check internet connectivity and API endpoint availability         |
| <Tag color={'rose'} variant={'large'}>Exceptions</Tag>     | Double check you are using a valid `Author` & the payload format. |


#### Debugging Tips

|    |                                                                                |
|----|--------------------------------------------------------------------------------|
| 1. | Use `Result<T>` pattern with proper error matching for detailed error handling |
| 2. | Use `match` statements around API calls to handle errors gracefully            |
| 3. | For batch operations, start with smaller batches to isolate issues             |


<SectionTitle title={'FAQ'}/>

<Accordion type="single" collapsible>
  <AccordionItem value="item-1">
    <AccordionTrigger>Can I use this SDK in a frontend environment?</AccordionTrigger>
    <AccordionContent>
      No, this SDK is designed for server-side Rust applications as it requires secret API keys that should never be
      exposed to clients. If you wish to track events from the frontend, consider using our JavaScript SDK or create a
      Rust API endpoint that securely handles tracking authenticated user actions.
    </AccordionContent>
  </AccordionItem>

  <AccordionItem value="item-2">
    <AccordionTrigger>How do I handle rate limiting?</AccordionTrigger>
    <AccordionContent>
      The SDK includes built-in retry logic with exponential backoff for rate limiting. You can also implement additional retry patterns when you encounter rate limit responses using tokio-retry:

      <CodeSample exampleFile={exampleFile} exampleKey="rate_limiting"  />
    </AccordionContent>
  </AccordionItem>

  <AccordionItem value="item-3">
    <AccordionTrigger>What's the maximum batch size for importing subscribers or events?</AccordionTrigger>
    <AccordionContent>
      Up to 1,000 subscribers or events can be imported in a single batch operation. We recommend batches of 200-300 for
      optimal performance. For large imports, consider using Rust's async concurrency patterns:

      <CodeSample exampleFile={exampleFile} exampleKey="max_batch_size"  />
    </AccordionContent>
  </AccordionItem>

  <AccordionItem value="item-4">
    <AccordionTrigger>How do I track anonymous users?</AccordionTrigger>
    <AccordionContent>
      Currently, the SDK requires an email address for all tracking. Anonymous tracking support is planned for future
      releases.
    </AccordionContent>
  </AccordionItem>

  <AccordionItem value="item-5">
    <AccordionTrigger>Which Rust versions are supported?</AccordionTrigger>
    <AccordionContent>
      The SDK requires Rust 1.70 or higher to support the latest features and security improvements. We recommend using the latest stable version of Rust for optimal performance and security.
    </AccordionContent>
  </AccordionItem>

  <AccordionItem value="item-6">
    <AccordionTrigger>How can I contribute to the SDK?</AccordionTrigger>
    <AccordionContent>
      We welcome contributions! Check the GitHub repository at [github.com/bentonow/bento-rust-sdk](https://github.com/bentonow/bento-rust-sdk)
      for contribution guidelines. You can submit pull requests, report issues, or suggest new features.
      For direct assistance, join our community Discord server.
    </AccordionContent>
  </AccordionItem>

  <AccordionItem value="item-7">
    <AccordionTrigger>How do I handle async operations and cancellation?</AccordionTrigger>
    <AccordionContent>
      All SDK methods are async and require a Tokio runtime. Use tokio::time::timeout for operations that shouldn't run too long:

      <CodeSample exampleFile={exampleFile} exampleKey="context_support"  />

      For long-running operations or background tasks, consider using cancellation tokens that can be terminated when needed.
    </AccordionContent>
  </AccordionItem>

  <AccordionItem value="item-8">
    <AccordionTrigger>Can I use the SDK with AWS Lambda or other serverless environments?</AccordionTrigger>
    <AccordionContent>
      Yes, the SDK is compatible with Rust serverless environments like AWS Lambda. For best performance, create and reuse the Bento client outside your handler function to take advantage of connection reuse across invocations:

      <CodeSample exampleFile={exampleFile} exampleKey="serverless_support"  />

        For bulk operations, be mindful of Lambda execution time limits and consider breaking large batches into smaller chunks.
    </AccordionContent>
  </AccordionItem>
</Accordion>

