Skip to main content

Perform API Request

Tribe allows apps to perform actions on behalf of a bot account or a specific member in the community using Tribe API. Bot accounts can perform all actions that a community admin can perform.

note

You can only generate and use app access token on communities that the app is published AND installed on. If the app is not installed in the community the following requests will result in Forbidden response.

The first step is to generate an app access token using app's client ID and client secret.

Using GraphQL

You can follow the instructions here to generate access token using GraphQL and perform actions on behalf of a bot account or a specific member.

Using JavaScript Client

Generating access token

If you're using Node.js, you can simply use Tribe's gql-client to generate access token and perform API requests.

To generate and access token, you can use the following code:

import { TribeClient } from "@tribeplatform/gql-client";

const client = new TribeClient({
clientId: "{clientId}",
clientSecret: "{clientSecret}",
graphqlUrl: "https://app.tribe.so/graphql",
});

client.generateToken({
networkId: "{networkId}",
memberId: "{memberId}",
}).then(async accessToken => {
console.log(accessToken);
});

You should replace {clientId}, {clientSecret}, {networkId}, and {memberId} with app's client ID, app's client secret, network/community ID, and the ID of the member that you want to impersonate.

note

Not providing memberId in generateToken will generate access token for a bot account.

Using the generated access token

You can simply set the generated access token using client.setToken:

client.setToken(accessToken);
const spaces = client.spaces.list({ limit: 5 }).then(spaces => {
// The following line will log 5 spaces
console.log(spaces)
})