← Blog

How to publish a video to YouTube and Instagram from the command line

Guide ·

Install the @socialized.dev/cli package, connect your accounts once in the dashboard, then run socialized.dev publications create with a video file, a title and a list of platforms. It uploads the file and publishes it. You can also script each platform’s API with curl or an SDK, if you’re ready to handle each one’s sign-in, upload flow and review yourself.

The CLI publishes to YouTube, Instagram and Facebook, in a terminal or in CI. It’s free for 10 videos a month.

Your options

  • curl, platform by platform. No third party holds your account grants, but you write each upload flow, keep each token alive and take your app through Google’s and Meta’s reviews. The API comparison shows what that takes for YouTube and Instagram.
  • Platform SDKs. A client library can save you some of the request code. The OAuth app, stored tokens, reviews and glue between platforms are still yours.
  • The socialized.dev CLI. One command for all the platforms. socialized.dev holds your account grants, encrypted, because it publishes for you. The API behind the CLI works from curl or any language too.

The rest of this guide uses the CLI.

Set it up once

  1. In the dashboard, connect your YouTube channel, Instagram account or Facebook Page. Instagram needs a Business or Creator account. Connecting happens in a browser, so the CLI can’t do it.
  2. Install the CLI and log in. login opens your browser for you to approve it.
npm install -g @socialized.dev/cli
socialized.dev login
socialized.dev brands list

A brand holds one connected account per platform, and you publish by platform name. If you have more than one brand, store a default with socialized.dev brands use --brand brand_…, or pass --brand-id on each command.

Publish from a terminal

socialized.dev publications create \
  --video ./clip.mp4 \
  --title "Launch day" \
  --description "What shipped." \
  --targets '[
    { "platform": "youtube" },
    { "platform": "instagram" },
    { "platform": "facebook" }
  ]'

List only the platforms you’ve connected. Add --cover ./cover.jpg for your own cover image. This posts for real, and YouTube videos are public unless you say otherwise.

Per-platform settings are easier to keep in a file than in shell quotes. Save this as publish.json:

{
  "title": "Launch day",
  "description": "What shipped.",
  "targets": [
    { "platform": "youtube", "options": { "privacyStatus": "unlisted" } },
    { "platform": "instagram", "options": { "caption": "It shipped." } },
    { "platform": "facebook", "options": { "format": "auto" } }
  ]
}

Then pass it as the request body:

socialized.dev publications create --video ./clip.mp4 --body @publish.json

The YouTube setting above makes only the YouTube video unlisted. The Instagram and Facebook posts still go out straight away. To see every option, run socialized.dev schema publications create.

Add --dry-run to print the publish request without sending or uploading anything. It checks the command and that your JSON parses. The API checks accounts, options and the video’s limits only on a real run.

What the CLI gives your script

A successful command prints its result as JSON on stdout. Upload progress and --watch updates go to stderr, so you can pipe stdout into jq. A failed command prints one JSON line on stderr and exits 1:

{
  "error": {
    "code": "PlatformNotConnectedError",
    "message": "…",
    "platform": "youtube",
    "status": 422,
    "idempotencyKey": "…"
  }
}

It’s shown wrapped here. Branch on code. UsageError means the command was wrong and nothing was sent. NetworkError means no answer came back, so a write may have gone through. No command stops to prompt you. The one thing that waits is login without a key, for your approval in the browser.

publications create returns as soon as the publication is accepted, before anything is live. It answers with a publicationId. To wait for the platforms, add --watch to publications get:

socialized.dev publications get --id pub_… --watch

It reads the publication every 2 seconds until it’s done, partial or failed.

--watch exits 0 for all three. The exit code says the command could read the publication, not that your video went out. A script has to check .publication.status.

A publish script

Save this as publish.sh, beside publish.json. It needs jq and uuidgen:

#!/usr/bin/env bash
set -euo pipefail
VIDEO=${1:?usage: publish.sh VIDEO}

# 1. Upload first, so a retry can name the same asset.
ASSET_ID=$(socialized.dev assets upload --file "$VIDEO" | jq -r .assetId)

# 2. Publish with a key you chose, and log both values.
KEY=$(uuidgen)
echo "asset=$ASSET_ID idempotency-key=$KEY" >&2
PUBLICATION_ID=$(socialized.dev publications create \
  --video-asset-id "$ASSET_ID" \
  --body @publish.json \
  --idempotency-key "$KEY" | jq -r .publicationId)
echo "publication=$PUBLICATION_ID" >&2

# 3. Wait until every destination settles.
socialized.dev publications get --id "$PUBLICATION_ID" --watch >result.json
jq -r '.publication.targets[]
  | [.platform, .status, .externalUrl // .failure.kind // ""]
  | @tsv' result.json

# 4. Fail unless every destination was published.
jq -e '.publication.status == "done"' result.json >/dev/null

Run it with bash publish.sh ./clip.mp4.

Run it in GitHub Actions

On a runner, skip login and set two environment variables:

Variable Value
SOCIALIZED_DEV_API_KEY An API key with Write access to the brand
SOCIALIZED_DEV_BRAND_ID The brand’s ID, brand_…

Create the key on the dashboard’s Developer page. Store it as a repository secret and the brand ID as a repository variable. This workflow runs by hand and publishes a video file from your repository with the script above:

name: Publish video

on:
  workflow_dispatch:
    inputs:
      video:
        description: Path to the video file
        required: true

permissions:
  contents: read

jobs:
  publish:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-node@v6
        with:
          node-version: 24
      - run: npm install -g @socialized.dev/cli
      - name: Publish and wait
        env:
          SOCIALIZED_DEV_API_KEY: ${{ secrets.SOCIALIZED_DEV_API_KEY }}
          SOCIALIZED_DEV_BRAND_ID: ${{ vars.SOCIALIZED_DEV_BRAND_ID }}
          VIDEO: ${{ inputs.video }}
        run: bash publish.sh "$VIDEO"

If your video is built by an earlier step, pass that file’s path to the script instead. Passing the input through env keeps its text out of the shell command. --watch has no time limit of its own, so keep timeout-minutes. A job that times out stops waiting; it doesn’t cancel the publish. Pin the CLI to a version you’ve tested if the workflow matters to you.

Retry without posting twice

Don’t re-run the whole job to fix a failure. A new run uploads a new asset and makes a new key, so it’s a new publish: platforms that already succeeded get the video again. First, find out what exists.

The publication exists, and a destination failed. Read it, fix what failure.kind points to, then retry that destination alone:

socialized.dev publications get --id pub_…
socialized.dev publications retry-target --id pub_… --tid tgt_…

Reconnect the account for reconnect and wait until retryAt for quota. A file failure means the same file will fail again: fix the video and publish it as a new publication that lists only the platforms that failed. A retry resends only a failed destination.

The create command got no answer. Run it again with the same asset ID, the same publish.json and the same key from the log:

socialized.dev publications create \
  --video-asset-id asset_… \
  --body @publish.json \
  --idempotency-key your-logged-key

For 24 hours, a repeat with the same key and body returns the publication the first call created. A different body under that key is refused, which is why the script uploads separately: running create --video again would upload a new asset. After 24 hours the key no longer protects you, and an upload that was never attached to a publication is deleted after 48 hours. If you’re unsure, check before you send anything:

socialized.dev publications list

The CLI can also run the rest of the API; socialized.dev commands lists every command. For the details, read the CLI docs and errors and idempotency. To see what happens behind the command on each platform, read the three-platform publishing guide.

Publish it once. See where it went live.

One upload to YouTube, Instagram and Facebook, from the dashboard, the API or the CLI. Free for 10 videos a month, no card needed.