Errors when generating JWT from API

I have an error when generating a JWT token using Bash script as noted in the API Reference.

The error is “ 8: Syntax error: redirection unexpected”. The URL is listed below in the proper format but could it be something related to the “#” in my URL’s (which I didn’t set, was there by default, don’t know if this is normal) in for example “”.

Help appreciated! Have tried a ton to get this fixed. Thank you!

Note, I’m posting my admin API key because may help and is a throwaway for testing purposes and not my main, so not a real security risk

#!/usr/bin/env bash

# Admin API key goes here


# Split the key into ID and SECRET


IFS=':' read ID SECRET <<< "$KEY"


# Prepare header and payload

NOW=$(date +'%s')

FIVE_MINS=$(($NOW + 300))

HEADER="{\"alg\": \"HS256\",\"typ\": \"JWT\", \"kid\": \"$ID\"}"

PAYLOAD="{\"iat\":$NOW,\"exp\":$FIVE_MINS,\"aud\": \"/v2/admin/\"}"

# Helper function for perfoming base64 URL encoding

base64_url_encode() {

    declare input=${1:-$(</dev/stdin)}

    # Use `tr` to URL encode the output from base64.

    printf '%s' "${input}" | base64 | tr -d '=' | tr '+' '-' |  tr '/' '_'


# Prepare the token body

header_base64=$(base64_url_encode "$HEADER")

payload_base64=$(base64_url_encode "$PAYLOAD")


# Create the signature

signature=$(printf '%s' "${header_payload}" | openssl dgst -binary -sha256 -mac HMAC -macopt hexkey:$SECRET | base64_url_encode)

# Concat payload and signature into a valid JWT token


# Make an authenticated request to create a post

curl -H "Authorization: Ghost $TOKEN" \

-H "Content-Type: application/json" \

-d '{"posts":[{"title":"Hello world"}]}' \


If you’re looking for help, please provide information about your environment. If you delete this template and don’t provide any information, your topic will be closed.

If you aren’t running the latest version of Ghost, the first thing we will ask you to do is update to the latest version of Ghost.

  • What’s your URL? This is the easiest way for others to help you

-*What version of Ghost are you using?

If it’s not the latest, please update Ghost first before opening your topic

  • Version 3.36.0
  • Environment production
  • Database mysql


  • How was Ghost installed and configured?

CLI install

  • What Node version, database, OS & browser are you using?

Ubuntu 20.04

  • What errors or information do you see in the console? 8: Syntax error: redirection unexpected

  • What steps could someone else take to reproduce the issue you’re having?


It’s not a Ghost error but a bash syntax error. You’re running the script with sh which is not necessarily the same as bash, on Ubuntu sh will use a dash shell instead which doesn’t support the <<< redirection syntax.

If you Google “Syntax error: redirection unexpected” you should find a number of results that explain the problem further along with workarounds. I’d start with trying to run the script with bash if you want to skip ahead before diving in deeper.

1 Like

Kevin, thanks for the response.

Ah yes, just learned on SO the difference between sh and bash.

Now a new problem. That command appears to run but just sits there hanging. Any ideas?:


Mod can close this. Used another method and issue resolved.