---
title: API quickstart
description: Create an API key, find your channels, check a post, send it and hear how it went, in five requests.
sidebar:
  icon: terminal
  order: 3
---

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 [#before]

You need three things:

- A workspace with at least one channel connected in the app ([Quickstart](/quickstart), [Connect channels](/guides/channels)).
- `curl`, the [command line](/developers/cli) or an [SDK](/developers/sdks) (`npm install --save-exact @peal-social/sdk@0.4.0-beta.1` for Node.js, a beta).
- Your instance's address. The examples use `https://api.example.com`, and Peal Cloud is `https://app.peal.social` ([Base URL](/developers#base-url)).

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

**Using a coding agent? Give it this prompt.**

> Add the Peal API to this project, following Peal's API quickstart.
>
> 1. Read the API key from the `PEAL_API_KEY` environment variable. Never hardcode it or commit it.
> 2. Call `GET /api/v1/credential` to check the key. It answers the key's workspace and permissions. The key acts in that workspace, so no request names it.
> 3. List the channels with `GET /api/v1/channels` and ask me which ones to post to.
> 4. Check the post with `POST /api/v1/posts/validate`. If `valid` is false, show me every violation and stop.
> 5. Send the same body to `POST /api/v1/posts`, with an `Idempotency-Key` header holding a new UUID.
> 6. Create a webhook endpoint with `POST /api/v1/webhooks` for `post.published` and `post.failed`, and store its signing secret, which is shown once.
>
> What goes out reaches the platforms' public and can't be taken back from Peal. Show me the post and wait for my OK before sending it. Stop and ask me if any call returns an error.

## 1. Create an API key [#key]

1. **Open the API keys**

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

2. **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.

3. **Copy it**

    Click **Create the key** and copy it. You'll only see it once ([API
    keys](/guides/workspace#api-keys)).

Then set up your client with the key:

```ts Node.js
import { PealClient } from "@peal-social/sdk";

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

```python Python
import os

from peal import Peal

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

```go Go
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()
```

```ruby Ruby
require "peal"

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

```java Java
import social.peal.PealClient;

PealClient peal = PealClient.builder()
    .token(System.getenv("PEAL_API_KEY"))
    .url("https://api.example.com")
    .build();
```

```php PHP
<?php
use Peal\PealClient;

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

```csharp .NET
using Peal;

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

```rust Rust
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()
})?;
```

```bash curl
export PEAL_API_KEY="peal_…"
```

```sh CLI
export PEAL_API_URL="https://api.example.com"
export PEAL_API_KEY="peal_…"
```

## 2. Check the key [#credential]

`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](/developers/conventions#workspace)).

```ts Node.js
const credential = await peal.credential.get();

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

```python Python
credential = peal.credential.get()

if credential.type == "apiKey":
    print(credential.workspace.id, credential.permissions)

```

```go Go
credential, err := client.Credential.Get(ctx)
if err != nil {
	return err
}

if credential.APIKey != nil {
	fmt.Println(credential.APIKey.Workspace.ID, credential.APIKey.Permissions)
}

```

```ruby Ruby
# 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)

```

```java Java
import social.peal.types.Credential;

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

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

```

```php PHP
$credential = $peal->credential->get();

if ($credential->isApiKey()) {
    echo $credential->asApiKey()->workspace->id, PHP_EOL;
}

```

```csharp .NET
var credential = await peal.Credential.GetAsync();

if (credential.IsApiKey)
{
    var key = credential.AsApiKey();
    Console.WriteLine($"{key.Workspace.Id} {string.Join(", ", key.Permissions)}");
}

```

```rust Rust
let credential = peal.credential.get(None).await?;

if let Credential::ApiKey { workspace, permissions, .. } = &credential {
    println!("{} {:?}", workspace.id, permissions);
}

```

```bash curl
curl https://api.example.com/api/v1/credential \
  -H "Authorization: Bearer $PEAL_API_KEY"
```

```sh CLI
peal whoami
```

## 3. Find your channels [#channels]

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

```ts Node.js
const channels = await peal.channels.list();
```

```python Python
channels = peal.channels.list()
```

```go Go
channels, err := client.Channels.List(ctx)
```

```ruby Ruby
channels = peal.channels.list
```

```java Java
import java.util.List;
import social.peal.types.Channel;

List<Channel> channels = peal.channels().list();
```

```php PHP
$channels = $peal->channels->list();
```

```csharp .NET
var channels = await peal.Channels.ListAsync();
```

```rust Rust
let channels = peal.channels.list(None).await?;
```

```bash curl
curl https://api.example.com/api/v1/channels \
  -H "Authorization: Bearer $PEAL_API_KEY"
```

```sh CLI
peal channels list
```

## 4. Check the post, then send it [#post]

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

```ts Node.js
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);
```

```python Python
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)
```

```go Go
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,
})
```

```ruby Ruby
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)
```

```java Java
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());
```

```php PHP
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,
]));
```

```csharp .NET
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,
});
```

```rust Rust
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?;
```

```bash curl
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" }
  }'
```

```sh CLI
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](/developers/conventions/idempotency)).

```ts Node.js
const sent = await peal.posts.create({
  ...post,
  "idempotency-key": "5f0c2b7e-3d1a-4e58-9a6b-2c4d8e1f7a90",
});
```

```python Python
sent = peal.posts.create(**post, idempotency_key="5f0c2b7e-3d1a-4e58-9a6b-2c4d8e1f7a90")
```

```go Go
sent, err := client.Posts.Create(ctx, &peal.NewPost{
	ChannelIDs:     channelIDs,
	Content:        content,
	When:           when,
	IdempotencyKey: peal.String("5f0c2b7e-3d1a-4e58-9a6b-2c4d8e1f7a90"),
})
```

```ruby Ruby
sent = peal.posts.create(**post, idempotency_key: "5f0c2b7e-3d1a-4e58-9a6b-2c4d8e1f7a90")
```

```java Java
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());
```

```php PHP
use Peal\Posts\Requests\NewPost;

$sent = $peal->posts->create(new NewPost([
    'channelIds' => $channelIds,
    'content' => $content,
    'when' => $when,
    'idempotencyKey' => '5f0c2b7e-3d1a-4e58-9a6b-2c4d8e1f7a90',
]));
```

```csharp .NET
var sent = await peal.Posts.CreateAsync(new NewPost
{
    ChannelIds = channelIds,
    Content = content,
    When = when,
    IdempotencyKey = "5f0c2b7e-3d1a-4e58-9a6b-2c4d8e1f7a90",
});
```

```rust Rust
// 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?;
```

```bash curl
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" }
  }'
```

```sh CLI
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.

> **A post can go out at once**
>
> With `"when": { "_tag": "now" }`, the post goes out at once. Add `?wait=30`
> and the answer waits until each channel has its result ([Publish
> now](/developers/posting#wait)).

## 5. Hear how it went [#webhook]

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](/developers/webhooks/requests).

```ts Node.js
const endpoint = await peal.webhooks.create({
  url: "https://example.com/peal-events",
  eventTypes: ["post.published", "post.failed"],
});
```

```python Python
endpoint = peal.webhooks.create(
    url="https://example.com/peal-events",
    event_types=["post.published", "post.failed"],
)
```

```go Go
endpoint, err := client.Webhooks.Create(ctx, &peal.NewWebhookEndpoint{
	URL: "https://example.com/peal-events",
	EventTypes: []peal.SubscribableWebhookEventType{
		peal.SubscribableWebhookEventTypePostPublished,
		peal.SubscribableWebhookEventTypePostFailed,
	},
})
```

```ruby Ruby
endpoint = peal.webhooks.create(
  url: "https://example.com/peal-events",
  event_types: ["post.published", "post.failed"]
)
```

```java Java
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());
```

```php PHP
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,
    ],
]));
```

```csharp .NET
var endpoint = await peal.Webhooks.CreateAsync(new NewWebhookEndpoint
{
    Url = "https://example.com/peal-events",
    EventTypes = new List<SubscribableWebhookEventType>
    {
        SubscribableWebhookEventType.PostPublished,
        SubscribableWebhookEventType.PostFailed,
    },
});
```

```rust Rust
let endpoint = peal
    .webhooks
    .create(
        &NewWebhookEndpoint::builder()
            .url("https://example.com/peal-events")
            .event_types(vec![
                SubscribableWebhookEventType::PostPublished,
                SubscribableWebhookEventType::PostFailed,
            ])
            .build()?,
        None,
    )
    .await?;
```

```bash curl
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"]
  }'
```

```sh CLI
peal webhooks create --url https://example.com/peal-events \
  --events post.published,post.failed
```

When the post goes out, your server gets [`post.published`](/developers/webhooks/events/posts#post-published) for each channel it reached, or [`post.failed`](/developers/webhooks/events/posts#post-failed) with the reason.

## Next [#next]

**[SDKs](/developers/sdks)**

Install a client, and publish a post from start to finish.

**[Errors](/developers/conventions/errors)**

Every error code, and what to do with each.

**[Posting API](/developers/posting)**

Check, send, bulk and import posts, and read their outcome.

**[API reference](/reference)**

Every endpoint and field.
