Migrate Wordpress Users to Appwrite
Tags: appwrite, tutorial, opensource
Published: 2022-10-11 07:32:10

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

Let's do it 🦾

## Step 1: Login to your WordPress website and install plugin

Firstly login to your WordPress website's admin panel and install the free plugin named _**[Import and export users and customers](https://wordpress.org/plugins/import-users-from-csv-with-meta/)**_

![Import and export users and customers](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i59xrudkr5wgkvybdmk4.png)

## Step 2: Export users from WordPress
Now in your WordPress dashboard go to **_Tools>Export>Users (in CSV format)_** and then **Download Export File**

![Wordpress export](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/22gtd0qpez7a2n79s33j.png)

Then download the csv file according to your preferred settings

![Export Users](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ckbi6vux2zzwt1u7vm5u.png)

## Step 3: 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 7 different hashing algorithms. Wordpress uses PHPass Password. So we will use PHPass Password in Appwrite Server SDK to import users.

```javascript
async createPHPassUser(
        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 csv file.
- **password**: Corresponds to the passwordHash value from csv 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 userslist = await CSVToJSON().fromFile("users.csv");
  await Promise.all(
    userslist.map(async (user) => {
      await users.createPHPassUser(
        ID.unique(),
        user.user_email,
        user.user_pass,
        user.display_name
      );
    })
  );
```
additionally you need to install `csvtojson` package to parse CSV data using the command below 

```javascript
npm i csvtojson
```
After all the user export the Appwrite dashboard looks like this

![Appwrite Users](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oqv6z1evbtv45cng5gbl.png)

So now the whole code looks like this

```javascript
const sdk = require("node-appwrite");
const { ID } = require("node-appwrite");
const CSVToJSON = require("csvtojson");

let client = new sdk.Client();

const users = new sdk.Users(client);

client
  .setEndpoint("Your Api Endpoint")
  .setProject("Your Project Key")
  .setKey("Your Api Key")
  .setSelfSigned();

const migrate = async () => {
  const userslist = await CSVToJSON().fromFile("users.csv");
  await Promise.all(
    userslist.map(async (user) => {
      await users.createPHPassUser(
        ID.unique(),
        user.user_email,
        user.user_pass,
        user.display_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