Importing Ghost Blog Users to Appwrite
Tags: appwrite, opensource, tutorial
Published: 2022-10-25 09:31:57

In Appwrite 1.0, a new feature has been added to allow users to migrate from other platforms like Firebase, WordPress, Ghost, Supabase, etc. to Appwrite. So in this tutorial we are going to migrate all the users(members) from Ghost Blog to Appwrite, and this is going to be super easy!

Let's do it 🦾

## Step 1: Export users(members) from Ghost Blog

Firstly, login to your Ghost admin and go to the _**Settings**_ page, and then scroll down and go to the _**Labs**_ section.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8rdtqkmnspv1pz4tk36v.png)

Now in Labs, export your content into a json file by clicking the _**Export**_ button.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r0py8t5vhfmsyae8wqgh.png)

You'll get a json file of all your contents like this

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xiljs68kgrlf8uj5h292.png)
This json file contains all the users' data. Now we need to import all the data into the Appwrite.

## Step 2: Import Users to Appwrite
To import users into Appwrite, we can use any [Server SDK](https://appwrite.io/docs/sdks#server) to access the Users API. For this example, we will use the NodeJS SDK.

Newly added functions let you create a user with one of seven different hashing algorithms. Ghost uses the Bcrypt algorithm for saving passwords. So we will use Bcrypt Password in the Appwrite Server SDK to import users.

```javascript
async createBcryptUser(
        userId,
        email,
        password,
        name
      );
```
Going through the function parameters one by one:

- **userId**: The ID to assign to the new user in Appwrite. It can be custom, or you can use the SDK's new ID.unique() function to assign a randomly generated ID.
- **email**: Corresponds to the email value from the json file.
- **password**: Corresponds to the passwordHash value from json file.
- **name**: The name to assign to the user. Can be null.

Putting this all together, we could import all of the exported users into Appwrite like so:

```javascript
const outfile = "cozblog.ghost.2022-10-24-17-31-47.json";
  const json = await fs.readFile(outfile, { encoding: "utf8" });
  const exported = JSON.parse(json).db[0].data.users;
  await Promise.all(
    exported.map(async (user) => {
      await users.createBcryptUser(
        ID.unique(),
        user.email,
        user.password,
        user.name
      );
    })
  );
```
After all the user export the Appwrite dashboard looks like this


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2izui5web0j1lejy741b.png)

So now the whole code looks like this

```javascript

const sdk = require("node-appwrite");
const { ID } = require("node-appwrite");
const fs = require('fs/promises');

let client = new sdk.Client();

const users = new sdk.Users(client);

const endPoint = "Your End Point";
const projectId = "Your Project Id";
const apiKey = "Your Api Key";
client
  .setEndpoint(endPoint)
  .setProject(projectId)
  .setKey(apiKey)
  .setSelfSigned();

const migrate = async () => {
  const outfile = "cozblog.ghost.2022-10-24-17-31-47.json";
  const json = await fs.readFile(outfile, { encoding: "utf8" });
  const exported = JSON.parse(json).db[0].data.users;
  await Promise.all(
    exported.map(async (user) => {
      await users.createBcryptUser(
        ID.unique(),
        user.email,
        user.password,
        user.name
      );
    })
  );
};

migrate()
  .then((r) => console.log("Done!"))
  .catch((e) => console.log(e));

```
Hope you learn how to migrate users from WordPress to Appwrite.
Don't forget to follow me @joysankar2001