Skip to main content

Go SDK

Official Go SDK for the Flow API.

Installation

go get github.com/flowdev/go-sdk

Quick Start

package main

import (
"fmt"
"time"
"github.com/flowdev/go-sdk"
)

func main() {
client := flow.NewClient("flow_sk_live_abc12345_xyz789...")

// Create a post
post, err := client.Posts.Create(&flow.CreatePostRequest{
ChannelID: "channel_123",
Content: "Hello from Flow!",
ScheduledFor: time.Date(2024, 12, 25, 10, 0, 0, 0, time.UTC),
})
if err != nil {
panic(err)
}

fmt.Printf("Post created: %s\n", post.ID)
}

Configuration

client := flow.NewClient(
"flow_sk_live_...",
flow.WithBaseURL("https://api.flow.dev"),
flow.WithTimeout(30*time.Second),
flow.WithMaxRetries(3),
)

Posts

List Posts

// List all posts
posts, err := client.Posts.List(nil)
if err != nil {
panic(err)
}

// With filters
posts, err := client.Posts.List(&flow.ListPostsOptions{
Filter: map[string]interface{}{
"status": "queued",
"channelId": "channel_123",
},
Sort: "-scheduledFor",
Page: 1,
PerPage: 50,
})

Create Post

// Immediate post
post, err := client.Posts.Create(&flow.CreatePostRequest{
ChannelID: "channel_123",
Content: "Hello!",
})

// Scheduled post
post, err := client.Posts.Create(&flow.CreatePostRequest{
ChannelID: "channel_123",
Content: "Scheduled post",
ScheduledFor: time.Date(2024, 12, 25, 10, 0, 0, 0, time.UTC),
MediaKeys: []string{"media_key_123"},
}, flow.WithIdempotencyKey("unique-key-123"))

Get Post

post, err := client.Posts.Get("post_123")
if err != nil {
panic(err)
}

Update Post

err := client.Posts.Update("post_123", &flow.UpdatePostRequest{
Content: flow.String("Updated content"),
ScheduledFor: flow.Time(time.Date(2024, 12, 26, 10, 0, 0, 0, time.UTC)),
})

Delete Post

err := client.Posts.Delete("post_123")
if err != nil {
panic(err)
}

Batch Operations

// Batch create
result, err := client.Posts.CreateBatch(&flow.BatchCreatePostsRequest{
Posts: []flow.CreatePostRequest{
{ChannelID: "channel_123", Content: "Post 1"},
{ChannelID: "channel_123", Content: "Post 2"},
},
})

// Batch update
err := client.Posts.UpdateBatch(&flow.BatchUpdatePostsRequest{
Posts: []flow.UpdatePostRequest{
{ID: "post_1", Content: flow.String("Updated 1")},
{ID: "post_2", Content: flow.String("Updated 2")},
},
})

// Batch delete
err := client.Posts.DeleteBatch(&flow.BatchDeletePostsRequest{
PostIDs: []string{"post_1", "post_2", "post_3"},
})

Channels

List Channels

channels, err := client.Channels.List(nil)

Create Channel

channel, err := client.Channels.Create(&flow.CreateChannelRequest{
Name: "My Channel",
Color: flow.String("#3B82F6"),
})

Get Channel

channel, err := client.Channels.Get("channel_123")

Update Channel

err := client.Channels.Update("channel_123", &flow.UpdateChannelRequest{
Name: flow.String("Updated Name"),
Color: flow.String("#FF0000"),
})

Delete Channel

err := client.Channels.Delete("channel_123")

Webhooks

List Webhooks

webhooks, err := client.Webhooks.List(nil)

Create Webhook

webhook, err := client.Webhooks.Create(&flow.CreateWebhookRequest{
URL: "https://example.com/webhooks/flow",
Events: []string{"post.delivered", "post.failed"},
})

fmt.Printf("Webhook secret: %s\n", webhook.Secret) // Save this!

Get Webhook

webhook, err := client.Webhooks.Get("webhook_123")

Update Webhook

err := client.Webhooks.Update("webhook_123", &flow.UpdateWebhookRequest{
URL: flow.String("https://new-url.com/webhooks/flow"),
Active: flow.Bool(false),
})

Delete Webhook

err := client.Webhooks.Delete("webhook_123")

Error Handling

post, err := client.Posts.Create(&flow.CreatePostRequest{
ChannelID: "invalid",
Content: "Test",
})

if err != nil {
if flowErr, ok := err.(*flow.Error); ok {
switch flowErr.Status {
case 401:
fmt.Println("Authentication failed")
case 403:
fmt.Println("Permission denied")
case 404:
fmt.Println("Resource not found")
case 429:
fmt.Printf("Rate limited. Retry after %ds\n", flowErr.RetryAfter)
default:
fmt.Printf("API error: %s\n", flowErr.Message)
}

// Access error details
for _, detail := range flowErr.Details {
fmt.Printf("%s: %s\n", detail.Field, detail.Message)
}
}
}

Examples

Schedule Weekly Posts

func scheduleWeeklyPosts(client *flow.Client, channelID string, contents []string) error {
posts := make([]flow.CreatePostRequest, len(contents))

for i, content := range contents {
date := time.Now().AddDate(0, 0, i+1)
date = time.Date(date.Year(), date.Month(), date.Day(), 9, 0, 0, 0, time.UTC)

posts[i] = flow.CreatePostRequest{
ChannelID: channelID,
Content: content,
ScheduledFor: date,
}
}

_, err := client.Posts.CreateBatch(&flow.BatchCreatePostsRequest{
Posts: posts,
})

return err
}

Next Steps