Follow the steps below to migrate content to your Bettermode site using Bettermode's API:
Step 1: Generate a Guest Access Token:
The first step to start using Bettermode's GraphQL API is generating a guest access token. Here's a sample query that you can use:
Copy
query {
getTokens(networkDomain: "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:
By following these steps, you will be able to create posts on your site and migrate data to the site by automating these queries and mutations.
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 the 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 Bettermode Guest and User Access token
Step 3: Creating a post using "createPost mutation"
ļ»æUsing the access token from Step 2, we can use createPost mutation to create a post in a specific space. Here's a sample mutation that needs to be used:
Copy
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 note: Please replace 'postTypeId' with the id unique to your site and 'spaceId' with the id you'd like to add.
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 posts on your site and migrate data to the site by automating these queries and mutations.