Issues with Ghost Migration: API Authentication and Image Handling during Import

Hello Ghost Community,

I’ve been working on migrating content to my Ghost(Pro) site using two different methods—via the Ghost Admin API and the JSON import method—but I’ve encountered separate issues with each. I’d appreciate any help or guidance in resolving these problems.

1.API Method: JWT Token Authentication (400 Error)

I’ve been trying to use the Ghost Admin API to programmatically migrate posts to my site, but I keep getting a 400 response with the error message Invalid token.

Here’s a summary of my setup and the steps I’ve taken:

JWT Token Generation: I’m using Python’s PyJWT library to generate the token. The token includes the iat (issued at) and exp (expiration) fields, and the aud is set to /admin/ as per the API documentation.
System Time Sync: The system time on my macOS is synced with an NTP server (pool.ntp.org) to prevent timing issues.
API Key: I’m using the API key in the correct format (id:secret), copied directly from the Ghost Admin panel.
Authorization Header: The API request includes the Authorization: Ghost <JWT_TOKEN> header.
Error: Despite these efforts, I consistently receive the following error:

Response status code: 400
Response content: {“errors”:[{“message”:“Invalid token”,“context”:null,“type”:“BadRequestError”,“details”:null,“property”:null,“help”:null,“code”:“INVALID_JWT”,“id”:“xxxxxx”,“ghostErrorCode”:null}]}

I’ve also compared my token generation script to the example provided in the Ghost documentation, and the setup seems correct.

  1. Import Method: Image Handling Issue

In addition to the API method, I’ve been using the Ghost import feature with a JSON file. The title and content of the posts are imported successfully, but I’m having trouble with images. Here’s the issue:

I download the images locally and adjust the paths in the JSON file to point to the correct directory (e.g., /content/images/20240829151742.jpg).
After importing, the posts display the titles and content correctly, but the images do not show up in the posts.

I’ve ensured that:

  • The image paths in the JSON are correct.
  • The images are correctly stored in the /content/images/ directory on the Ghost server.

However, the images still don’t appear in the posts after import.

Request for Help:

  • For theAPI method, could someone guide me on how to resolve the Invalid token error? Is there something I’m missing in my token generation or the request setup?
  • For the Import method, I’d appreciate advice on why the images aren’t being displayed and how to properly link and display them after importing posts.

Thanks in advance for your help! I’ve spent considerable time troubleshooting both methods, and any insights or suggestions would be greatly appreciated.

Best regards,
Tahoe

API Method: JWT Token Authentication (400 Error)

It would be easier to help you if you post related code

  1. Import Method: Image Handling Issue

Do you see any errors in the “console” tab of your browser’s developer tools (you can open it by pressing F12) when loading images?