Migrate content using the GraphQL API

Migrate content to your site using API

Follow these steps to migrate content to your Bettermode site using Bettermode's GraphQL API.

Step 1: Generate a guest access token

Start by generating a guest access token. Use the following query:

query { 
  getTokens(networkDomain: "community.bettermode.com") { 
    accessToken 
    role { 
      name 
      scopes 
    } 
    member { 
      id 
      name 
    } 
  } 
}

Important: Replace community.bettermode.com with your own domain.

The query returns a result containing your access token and member information:

Step 2: Generate a user access token

Use the guest access token from Step 1 to create a user access token. Pass the access token in your request header using this format:

Authorization: Bearer {accessToken}

Then use the following query with your member's credentials:

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

Important: Replace bettermodeuser with your email address or username, and bettermodepassword with your password.

The query generates a user access token you can use for queries, mutations, and other API operations:

For a walkthrough of Steps 1 and 2, see How to generate Bettermode guest and user access tokens.

Step 3: Create a post using the createPost mutation

Use the user access token from Step 2 to create a post in your space with the createPost mutation. Use the following mutation:

mutation {
  createPost(
    input: {
      postTypeId: "insert postTypeID",
      mappingFields: [{
        type: text,
        key: "title",
        value: "\"This is where title goes\""
      }, {
        type: html,
        key: "content",
        value: "\"<p> this is where content goes</p>\""
      }],
      tagNames: [],
      attachmentIds: []
    },
    spaceId: "insert Space ID"
  ) {
    attachmentIds
    createdAt
    hasMoreContent
    id
    imageIds
    isAnonymous
    isHidden
    pinnedInto
    postTypeId
    repliedToIds
    repliesCount
    shortContent
    slug
    totalRepliesCount
  }
}

Important: Replace postTypeID with the post type ID specific to your site, and spaceId with the ID of the space where you want to add the post.

The mutation returns a result with the post details you requested:

By completing these three steps, you can create posts on your site and automate content migration by running these queries and mutations programmatically.

Contact Us

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