Skip to content
Peal
Esc
↑↓navigate↵open⌘Jpreview
On this page

API quickstart

Create an API key, find your channels, check a post, send it and hear how it went, in five requests.

In this quickstart you’ll send a post to one of your channels with the API, then get a webhook when it’s out. Each step shows the same request in every SDK, with curl and with the peal command line.

Before you start

You need three things:

The ids on this page are made up, so yours will differ. The answers are abridged.

Using a coding agent? Give it this prompt.

1. Create an API key

Open the API keys

In the app, open the workspace’s Settings, then API keys.

Give it what this page needs

Name the key and set how long it works. For this page it needs channel:read, post:read and post:schedule, plus webhook:manage for the last step.

Copy it

Click Create the key and copy it. You’ll only see it once (API keys).

Then set up your client with the key:

import { PealClient } from "@peal-social/sdk";

const peal = new PealClient({
  token: process.env.PEAL_API_KEY,
  baseUrl: "https://api.example.com",
});
import os

from peal import Peal

peal = Peal(token=os.environ["PEAL_API_KEY"], base_url="https://api.example.com")
import (
	"context"
	"fmt"
	"os"

	peal "github.com/peal-social/peal/packages/peal-sdk/go"
	"github.com/peal-social/peal/packages/peal-sdk/go/client"
	"github.com/peal-social/peal/packages/peal-sdk/go/option"
)

// The client is named `client`, so that `peal` stays the package of the
// request types.
client := client.NewClient(
	option.WithToken(os.Getenv("PEAL_API_KEY")),
	option.WithBaseURL("https://api.example.com"),
)
ctx := context.Background()
require "peal"

peal = Peal::Client.new(
  token: ENV.fetch("PEAL_API_KEY"),
  base_url: "https://api.example.com"
)
import social.peal.PealClient;

PealClient peal = PealClient.builder()
    .token(System.getenv("PEAL_API_KEY"))
    .url("https://api.example.com")
    .build();
<?php
use Peal\PealClient;

$peal = new PealClient(
    token: getenv('PEAL_API_KEY'),
    options: ['baseUrl' => 'https://api.example.com'],
);
using Peal;

var peal = new PealClient(
    Environment.GetEnvironmentVariable("PEAL_API_KEY")!,
    clientOptions: new ClientOptions { BaseUrl = "https://api.example.com" }
);
use peal_sdk::prelude::*;

let peal = PealClient::new(ClientConfig {
    token: std::env::var("PEAL_API_KEY").ok(),
    base_url: "https://api.example.com".to_string(),
    ..Default::default()
})?;
export PEAL_API_KEY="peal_…"
export PEAL_API_URL="https://api.example.com"
export PEAL_API_KEY="peal_…"

2. Check the key

GET /api/v1/credential tells you who the key is and what it may do, and it reads no data. Its workspace.id is the workspace the key belongs to. Every request with the key acts there, so none of them sends the workspace’s id (The workspace of a request).

const credential = await peal.credential.get();

if (credential._tag === "apiKey") {
  console.log(credential.workspace.id, credential.permissions);
}
credential = peal.credential.get()

if credential.type == "apiKey":
    print(credential.workspace.id, credential.permissions)
credential, err := client.Credential.Get(ctx)
if err != nil {
	return err
}

if credential.APIKey != nil {
	fmt.Println(credential.APIKey.Workspace.ID, credential.APIKey.Permissions)
}
# Each kind of credential is a class of its own.
credential = peal.credential.get

puts credential.workspace.id if credential.is_a?(Peal::Types::CredentialAPIKey)
import social.peal.types.Credential;

Credential credential = peal.credential().get();

credential.getApiKey().ifPresent(key ->
    System.out.println(key.getWorkspace().getId() + " " + key.getPermissions()));
$credential = $peal->credential->get();

if ($credential->isApiKey()) {
    echo $credential->asApiKey()->workspace->id, PHP_EOL;
}
var credential = await peal.Credential.GetAsync();

if (credential.IsApiKey)
{
    var key = credential.AsApiKey();
    Console.WriteLine($"{key.Workspace.Id} {string.Join(", ", key.Permissions)}");
}
let credential = peal.credential.get(None).await?;

if let Credential::ApiKey { workspace, permissions, .. } = &credential {
    println!("{} {:?}", workspace.id, permissions);
}
curl https://api.example.com/api/v1/credential \
  -H "Authorization: Bearer $PEAL_API_KEY"
peal whoami

3. Find your channels

A channel is an account the workspace posts to. Connect one in the app first (Connect channels). Then list them, and you’ll get each one’s id and platform:

const channels = await peal.channels.list();
channels = peal.channels.list()
channels, err := client.Channels.List(ctx)
channels = peal.channels.list
import java.util.List;
import social.peal.types.Channel;

List<Channel> channels = peal.channels().list();
$channels = $peal->channels->list();
var channels = await peal.Channels.ListAsync();
let channels = peal.channels.list(None).await?;
curl https://api.example.com/api/v1/channels \
  -H "Authorization: Bearer $PEAL_API_KEY"
peal channels list

4. Check the post, then send it

POST …/posts/validate tells you whether a post would go through, with everything that would refuse it. It makes nothing (Check a post).

const post = {
  channelIds: ["0190f3a0-0000-7000-8000-00000000c001"],
  content: { text: "Hello from the API", media: [], overrides: [] },
  when: {
    _tag: "at" as const,
    at: "2026-11-16T08:00:00Z",
    timeZone: "Europe/Paris",
  },
};

const check = await peal.posts.validate(post);
from peal import PostContent, PostTiming_At

post = dict(
    channel_ids=["0190f3a0-0000-7000-8000-00000000c001"],
    content=PostContent(text="Hello from the API", media=[], overrides=[]),
    when=PostTiming_At(at="2026-11-16T08:00:00Z", time_zone="Europe/Paris"),
)

check = peal.posts.validate(**post)
channelIDs := []string{"0190f3a0-0000-7000-8000-00000000c001"}
content := &peal.PostContent{
	Text:      "Hello from the API",
	Media:     []*peal.MediaAttachment{},
	Overrides: []*peal.TextOverride{},
}
when := &peal.PostTiming{
	At: &peal.PostTimingAt{At: "2026-11-16T08:00:00Z", TimeZone: "Europe/Paris"},
}

check, err := client.Posts.Validate(ctx, &peal.PostToValidate{
	ChannelIDs: channelIDs,
	Content:    content,
	When:       when,
})
post = {
  channel_ids: ["0190f3a0-0000-7000-8000-00000000c001"],
  content: { text: "Hello from the API", media: [], overrides: [] },
  when: { _tag: "at", at: "2026-11-16T08:00:00Z", timeZone: "Europe/Paris" }
}

check = peal.posts.validate(**post)
import social.peal.resources.posts.requests.PostToValidate;
import social.peal.types.PostContent;
import social.peal.types.PostTiming;
import social.peal.types.PostTimingAt;
import social.peal.types.PostValidation;

List<String> channelIds = List.of("0190f3a0-0000-7000-8000-00000000c001");
PostContent content = PostContent.builder().text("Hello from the API").build();
PostTiming when = PostTiming.at(PostTimingAt.builder()
    .at("2026-11-16T08:00:00Z")
    .timeZone("Europe/Paris")
    .build());

PostValidation check = peal.posts().validate(PostToValidate.builder()
    .content(content)
    .channelIds(channelIds)
    .when(when)
    .build());
use Peal\Posts\Requests\PostToValidate;
use Peal\Types\PostContent;
use Peal\Types\PostTiming;
use Peal\Types\PostTimingAt;

$channelIds = ['0190f3a0-0000-7000-8000-00000000c001'];
$content = new PostContent(['text' => 'Hello from the API', 'media' => [], 'overrides' => []]);
$when = PostTiming::at(new PostTimingAt([
    'at' => '2026-11-16T08:00:00Z',
    'timeZone' => 'Europe/Paris',
]));

$check = $peal->posts->validate(new PostToValidate([
    'channelIds' => $channelIds,
    'content' => $content,
    'when' => $when,
]));
var channelIds = new List<string> { "0190f3a0-0000-7000-8000-00000000c001" };
var content = new PostContent
{
    Text = "Hello from the API",
    Media = new List<MediaAttachment>(),
    Overrides = new List<TextOverride>(),
};
var when = new PostTiming(new PostTiming.At(new PostTimingAt
{
    At = "2026-11-16T08:00:00Z",
    TimeZone = "Europe/Paris",
}));

var check = await peal.Posts.ValidateAsync(new PostToValidate
{
    ChannelIds = channelIds,
    Content = content,
    When = when,
});
let channel_ids = vec!["0190f3a0-0000-7000-8000-00000000c001".to_string()];
let content = PostContent {
    text: "Hello from the API".to_string(),
    ..Default::default()
};
let when = PostTiming::at("2026-11-16T08:00:00Z".to_string(), "Europe/Paris".to_string());

let check = peal
    .posts
    .validate(
        &PostToValidate::builder()
            .channel_ids(channel_ids.clone())
            .content(content.clone())
            .when(when.clone())
            .build()?,
        None,
    )
    .await?;
curl -X POST https://api.example.com/api/v1/posts/validate \
  -H "Authorization: Bearer $PEAL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "channelIds": ["0190f3a0-0000-7000-8000-00000000c001"],
    "content": { "text": "Hello from the API", "media": [], "overrides": [] },
    "when": { "_tag": "at", "at": "2026-11-16T08:00:00Z", "timeZone": "Europe/Paris" }
  }'
peal post "Hello from the API" --channel 0190f3a0-0000-7000-8000-00000000c001 \
  --at 2026-11-16T09:00 --time-zone Europe/Paris --dry-run

When it answers "valid": true, send the same body to POST …/posts. With an Idempotency-Key, you can send it again after a timeout without posting twice (Idempotency).

const sent = await peal.posts.create({
  ...post,
  "idempotency-key": "5f0c2b7e-3d1a-4e58-9a6b-2c4d8e1f7a90",
});
sent = peal.posts.create(**post, idempotency_key="5f0c2b7e-3d1a-4e58-9a6b-2c4d8e1f7a90")
sent, err := client.Posts.Create(ctx, &peal.NewPost{
	ChannelIDs:     channelIDs,
	Content:        content,
	When:           when,
	IdempotencyKey: peal.String("5f0c2b7e-3d1a-4e58-9a6b-2c4d8e1f7a90"),
})
sent = peal.posts.create(**post, idempotency_key: "5f0c2b7e-3d1a-4e58-9a6b-2c4d8e1f7a90")
import social.peal.resources.posts.requests.NewPost;
import social.peal.types.Post;

Post sent = peal.posts().create(NewPost.builder()
    .content(content)
    .when(when)
    .channelIds(channelIds)
    .idempotencyKey("5f0c2b7e-3d1a-4e58-9a6b-2c4d8e1f7a90")
    .build());
use Peal\Posts\Requests\NewPost;

$sent = $peal->posts->create(new NewPost([
    'channelIds' => $channelIds,
    'content' => $content,
    'when' => $when,
    'idempotencyKey' => '5f0c2b7e-3d1a-4e58-9a6b-2c4d8e1f7a90',
]));
var sent = await peal.Posts.CreateAsync(new NewPost
{
    ChannelIds = channelIds,
    Content = content,
    When = when,
    IdempotencyKey = "5f0c2b7e-3d1a-4e58-9a6b-2c4d8e1f7a90",
});
// NewPost has no field for the key: it goes in the request's headers.
let sent = peal
    .posts
    .create(
        &NewPost::builder()
            .channel_ids(channel_ids)
            .content(content)
            .when(when)
            .build()?,
        Some(RequestOptions::new().additional_header(
            "Idempotency-Key",
            "5f0c2b7e-3d1a-4e58-9a6b-2c4d8e1f7a90",
        )),
    )
    .await?;
curl -X POST https://api.example.com/api/v1/posts \
  -H "Authorization: Bearer $PEAL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 5f0c2b7e-3d1a-4e58-9a6b-2c4d8e1f7a90" \
  -d '{
    "channelIds": ["0190f3a0-0000-7000-8000-00000000c001"],
    "content": { "text": "Hello from the API", "media": [], "overrides": [] },
    "when": { "_tag": "at", "at": "2026-11-16T08:00:00Z", "timeZone": "Europe/Paris" }
  }'
peal post "Hello from the API" --channel 0190f3a0-0000-7000-8000-00000000c001 \
  --at 2026-11-16T09:00 --time-zone Europe/Paris \
  --idempotency-key 5f0c2b7e-3d1a-4e58-9a6b-2c4d8e1f7a90

The post is now scheduled. It shows on the workspace’s calendar and goes out at its time.

5. Hear how it went

Instead of asking, have Peal tell your server. Create a webhook endpoint for the events you want. The answer holds its signing secret, and you’ll only see it once, so keep it to verify each delivery.

const endpoint = await peal.webhooks.create({
  url: "https://example.com/peal-events",
  eventTypes: ["post.published", "post.failed"],
});
endpoint = peal.webhooks.create(
    url="https://example.com/peal-events",
    event_types=["post.published", "post.failed"],
)
endpoint, err := client.Webhooks.Create(ctx, &peal.NewWebhookEndpoint{
	URL: "https://example.com/peal-events",
	EventTypes: []peal.SubscribableWebhookEventType{
		peal.SubscribableWebhookEventTypePostPublished,
		peal.SubscribableWebhookEventTypePostFailed,
	},
})
endpoint = peal.webhooks.create(
  url: "https://example.com/peal-events",
  event_types: ["post.published", "post.failed"]
)
import social.peal.resources.webhooks.requests.NewWebhookEndpoint;
import social.peal.types.SubscribableWebhookEventType;
import social.peal.types.WebhookEndpointSecret;

WebhookEndpointSecret endpoint = peal.webhooks().create(NewWebhookEndpoint.builder()
    .url("https://example.com/peal-events")
    .eventTypes(List.of(
        SubscribableWebhookEventType.POST_PUBLISHED,
        SubscribableWebhookEventType.POST_FAILED))
    .build());
use Peal\Types\SubscribableWebhookEventType;
use Peal\Webhooks\Requests\NewWebhookEndpoint;

$endpoint = $peal->webhooks->create(new NewWebhookEndpoint([
    'url' => 'https://example.com/peal-events',
    'eventTypes' => [
        SubscribableWebhookEventType::PostPublished->value,
        SubscribableWebhookEventType::PostFailed->value,
    ],
]));
var endpoint = await peal.Webhooks.CreateAsync(new NewWebhookEndpoint
{
    Url = "https://example.com/peal-events",
    EventTypes = new List<SubscribableWebhookEventType>
    {
        SubscribableWebhookEventType.PostPublished,
        SubscribableWebhookEventType.PostFailed,
    },
});
let endpoint = peal
    .webhooks
    .create(
        &NewWebhookEndpoint::builder()
            .url("https://example.com/peal-events")
            .event_types(vec![
                SubscribableWebhookEventType::PostPublished,
                SubscribableWebhookEventType::PostFailed,
            ])
            .build()?,
        None,
    )
    .await?;
curl -X POST https://api.example.com/api/v1/webhooks \
  -H "Authorization: Bearer $PEAL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/peal-events",
    "eventTypes": ["post.published", "post.failed"]
  }'
peal webhooks create --url https://example.com/peal-events \
  --events post.published,post.failed

When the post goes out, your server gets post.published for each channel it reached, or post.failed with the reason.

Next

Was this page helpful?