Migrate members to your community using API

To migrate members to your Bettermode community using Bettermode's API, follow the steps below:

Step 1: Generate a Guest Access Token: The first step to start using Bettermode's GraphQL's API is generating a guest access token. Here's a sample query that you can use:

Copy

query {
getTokens(networkDomain: "[community.bettermode.com](<http://community.bettermode.com/>)") {
accessToken
role {
name
scopes
}
member {
id
name
}
}
}

❗Important Note: Please replace networkDomain value with your own domain value.

Once the query is completed, it will return a result similar to the screenshot below:

Step 2: Generate a User Access token: Once you have a Guest access token, you can use it to create a User Access token that's required to perform different queries, mutations, etc. A User Access token is generated using a member's E-mail address or username and password. To generate a User Access token, you need to pass the access token (provided in Step 1) in the header with the following format:

Copy

Authorization: Bearer {accessToken}

Here's a sample query that you can use:

Copy

query {
loginNetwork(
input: { usernameOrEmail: "bettermodeuser", password: "bettermodepassword" }
) {
accessToken
role {
name
scopes
}
member {
id
name
}
}
}

❗Important Note: Please replace 'bettermodeuser' with e-mail address or username and 'bettermodepassword' with the password of the member.

The above 'query' will generate a user access token for you that can be used for a variety of queries, mutations, etc. Here's a sample result that you can expect:

Step 1 & 2 are also covered in a video tutorial here- How to generate a Bettermode Guest and User Access token

Step 3: Creating a Member using "joinNetwork mutation": Using the access token from Step 2, we can use joinNetwork mutation to create a Member in a specific space. Here's a sample mutation that needs to be used:

Copy

mutation {
  joinNetwork(
    input: {
      email: "[email protected]",
      name: "Name of the user",
      password: "TestPassword",
      phone: "+919213849901",
      username: "username-of-the-user"
    }
) {
    accessToken
    refreshToken
  }
}

Depending on the fields requested, you will receive a result similar to the one below:

By following these steps, you will be able to create user profiles in your community and migrate data to the community by automating these queries and mutations.

Contact Us

Do you still need help? Learn how to get in touch with the Bettermode Team.