Go Client

Welcome to the MagiBell GO SDK documentation. This guide will help you get started with integrating and using the MagicBell GO SDK in your project.

Authentication

Both the ProjectClient and the UserClient require authentication. Please read more about authentication and generation of tokens in our Authentication docs.

ProjectClient

Authentication

Access Token Authentication

The Client API uses an Access Token for authentication.

This token must be provided to authenticate your requests to the API.

Setting the Access Token

When you initialize the SDK, you can set the access token as follows:

import (
    "github.com/magicbell/magicbell-go/pkg/project-client/client"
    "github.com/magicbell/magicbell-go/pkg/project-client/clientconfig"
  )

config := clientconfig.NewConfig()
config.SetAccessToken("YOUR-TOKEN")

sdk := client.NewClient(config)

If you need to set or update the access token after initializing the SDK, you can use:

import (
    "github.com/magicbell/magicbell-go/pkg/project-client/client"
    "github.com/magicbell/magicbell-go/pkg/project-client/clientconfig"
  )

config := clientconfig.NewConfig()

sdk := client.NewClient(config)
sdk.SetAccessToken("YOUR-TOKEN")

Setting a Custom Timeout

You can set a custom timeout for the SDK's HTTP requests as follows:

import "time"

config := clientconfig.NewConfig()

sdk := client.NewClient(config)

sdk.SetTimeout(10 * time.Second)

Sample Usage

Below is a comprehensive example demonstrating how to authenticate and call a simple endpoint:

import (
  "fmt"
  "encoding/json"
  "context"
  "github.com/magicbell/magicbell-go/pkg/project-client/clientconfig"
  "github.com/magicbell/magicbell-go/pkg/project-client/client"
  "github.com/magicbell/magicbell-go/pkg/project-client/util"
  "github.com/magicbell/magicbell-go/pkg/project-client/broadcasts"
)

config := clientconfig.NewConfig()
config.SetAccessToken("ACCESS_TOKEN")
client := client.NewClient(config)


params := broadcasts.ListBroadcastsRequestParams{
  Limit: util.ToPointer(int64(0)),
  StartingAfter: util.ToPointer("starting_after"),
  EndingBefore: util.ToPointer("ending_before"),
}

response, err := client.Broadcasts.ListBroadcasts(context.Background(), params)
if err != nil {
  panic(err)
}

fmt.Println(response)

Services

The SDK provides various services to interact with the API.

Below is a list of all available services with links to their detailed documentation:
Name
BroadcastsService
ChannelsService
EventsService
IntegrationsService
UsersService
WorkflowsService

Response Wrappers

All services use response wrappers to provide a consistent interface to return the responses from the API.

The response wrapper itself is a generic struct that contains the response data and metadata.

Below are the response wrappers used in the SDK:

ClientResponse[T]

This response wrapper is used to return the response data from the API. It contains the following fields:

Name Type Description
Data T The body of the API response
Metadata ClientResponseMetadata Status code and headers returned by the API

ClientError[T]

This response wrapper is used to return an error. It contains the following fields:

Name Type Description
Err error The error that occurred
Data *T The deserialized error response data (nil if unmarshaling failed)
Body []byte The raw body of the API response
Metadata ClientErrorMetadata Status code and headers returned by the API

ClientResponseMetadata

This struct is shared by both response wrappers and contains the following fields:

Name Type Description
Headers map[string]string A map containing the headers returned by the API
StatusCode int The status code returned by the API

Models

The SDK includes several models that represent the data structures used in API requests and responses. These models help in organizing and managing the data efficiently.

Below is a list of all available models with links to their detailed documentation:
Name Description
BroadcastCollection
Broadcast
User
Links
CategoryDeliveryConfig
InboxTokenResponseCollection
InboxTokenResponse
Links
DiscardResult
ApnsTokenCollection
ApnsToken
ExpoTokenCollection
ExpoToken
FcmTokenCollection
FcmToken
SlackTokenCollection
SlackToken
TeamsTokenCollection
TeamsToken
WebPushTokenCollection
WebPushToken
EventCollection
Event
Links
IntegrationConfigCollection
IntegrationConfig
Links
ApnsConfigCollection
ApnsConfig
ApnsConfigPayload
EventSourceConfigCollection
EventSourceConfig
EventSourceConfigPayload
ExpoConfigCollection
ExpoConfig
ExpoConfigPayload
FcmConfigCollection
FcmConfig
FcmConfigPayload
GithubConfigCollection
GithubConfig
GithubConfigPayload
InboxConfigCollection
InboxConfig
InboxConfigPayload
SlackBotConfigCollection
SlackBotConfig
SlackBotConfigPayload
MailgunConfigCollection
MailgunConfig
MailgunConfigPayload
PingConfigCollection
PingConfig
PingConfigPayload
SendgridConfigCollection
SendgridConfig
SendgridConfigPayload
SesConfigCollection
SesConfig
SesConfigPayload
SlackConfigCollection
SlackConfig
SlackConfigPayload
SmtpConfigObjectCollection
SmtpConfigObject
SmtpConfig
StripeConfigCollection
StripeConfig
StripeConfigPayload
TwilioConfigCollection
TwilioConfig
TwilioConfigPayload
WebpushConfigCollection
WebpushConfig
WebpushConfigPayload
UserCollection
User
Links
WorkflowList
WorkflowDefinition
CreateRunResponse
ExecuteWorkflowRequest
GetRunResponse
WorkflowRunCollection
WorkflowRun
Links

UserClient

Authentication

Access Token Authentication

The Client API uses an Access Token for authentication.

This token must be provided to authenticate your requests to the API.

Setting the Access Token

When you initialize the SDK, you can set the access token as follows:

import (
    "github.com/magicbell/magicbell-go/pkg/user-client/client"
    "github.com/magicbell/magicbell-go/pkg/user-client/clientconfig"
  )

config := clientconfig.NewConfig()
config.SetAccessToken("YOUR-TOKEN")

sdk := client.NewClient(config)

If you need to set or update the access token after initializing the SDK, you can use:

import (
    "github.com/magicbell/magicbell-go/pkg/user-client/client"
    "github.com/magicbell/magicbell-go/pkg/user-client/clientconfig"
  )

config := clientconfig.NewConfig()

sdk := client.NewClient(config)
sdk.SetAccessToken("YOUR-TOKEN")

Setting a Custom Timeout

You can set a custom timeout for the SDK's HTTP requests as follows:

import "time"

config := clientconfig.NewConfig()

sdk := client.NewClient(config)

sdk.SetTimeout(10 * time.Second)

Sample Usage

Below is a comprehensive example demonstrating how to authenticate and call a simple endpoint:

import (
  "fmt"
  "encoding/json"
  "context"
  "github.com/magicbell/magicbell-go/pkg/user-client/clientconfig"
  "github.com/magicbell/magicbell-go/pkg/user-client/client"
  "github.com/magicbell/magicbell-go/pkg/user-client/util"
  "github.com/magicbell/magicbell-go/pkg/user-client/channels"
)

config := clientconfig.NewConfig()
config.SetAccessToken("ACCESS_TOKEN")
client := client.NewClient(config)


params := channels.ListInboxTokensRequestParams{
  Limit: util.ToPointer(int64(8)),
  StartingAfter: util.ToPointer("starting_after"),
  EndingBefore: util.ToPointer("ending_before"),
}

response, err := client.Channels.ListInboxTokens(context.Background(), params)
if err != nil {
  panic(err)
}

fmt.Println(response)

Services

The SDK provides various services to interact with the API.

Below is a list of all available services with links to their detailed documentation:
Name
ChannelsService
IntegrationsService
NotificationsService

Response Wrappers

All services use response wrappers to provide a consistent interface to return the responses from the API.

The response wrapper itself is a generic struct that contains the response data and metadata.

Below are the response wrappers used in the SDK:

ClientResponse[T]

This response wrapper is used to return the response data from the API. It contains the following fields:

Name Type Description
Data T The body of the API response
Metadata ClientResponseMetadata Status code and headers returned by the API

ClientError[T]

This response wrapper is used to return an error. It contains the following fields:

Name Type Description
Err error The error that occurred
Data *T The deserialized error response data (nil if unmarshaling failed)
Body []byte The raw body of the API response
Metadata ClientErrorMetadata Status code and headers returned by the API

ClientResponseMetadata

This struct is shared by both response wrappers and contains the following fields:

Name Type Description
Headers map[string]string A map containing the headers returned by the API
StatusCode int The status code returned by the API

Models

The SDK includes several models that represent the data structures used in API requests and responses. These models help in organizing and managing the data efficiently.

Below is a list of all available models with links to their detailed documentation:
Name Description
InboxTokenResponseCollection
InboxTokenResponse
Links
InboxToken
DiscardResult
ApnsTokenCollection
ApnsToken
ApnsTokenPayload
ExpoTokenCollection
ExpoToken
ExpoTokenPayload
FcmTokenCollection
FcmToken
FcmTokenPayload
SlackTokenCollection
SlackToken
SlackTokenPayload
TeamsTokenCollection
TeamsToken
TeamsTokenPayload
UserPreferences
WebPushTokenCollection
WebPushToken
WebPushTokenPayload
InboxConfigPayload
SlackInstallation
SlackFinishInstallResponse
SlackStartInstallResponseContent
SlackStartInstall
WebPushTokenPayload
WebPushStartInstallationResponse
NotificationCollection
Notification
Links
CountResponse