Working with GraphQL API

Rasayel's public API is built with GraphQL. Internally, Rasayel Inbox app uses a similar API with inbox-specific stuff.

If you are not familar with GraphQL, we suggest you check out the official GraphQL learning docs. Apollo has also great resources and tools for working with GraphQL APIs.

Endpoint

htmlhttps://api.rasayel.io/api/graphql

Authentication

You can authenticate your client by using API keys that you create from Rasayel's API management page.

API keys provide you with a value for the Authorization header that you should configure with your GraphQL client of choice or your HTTP request.

shcurl \
  -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <Replace this with your access token>" \
  --data '{ "query": "{ app { conversations { nodes { id } } } }" }' \
  https://api.rasayel.io/graphql

Key Access

Some keys can be created to be "read-only" (supports queries) while others can be created as "read-write" (supports both queries and mutations). Make sure to use the correct key access before using the API.

Getting Started

Assuming you have your API key and a GraphQL client that can introspect the schema, you can begin using the queries and mutations available.

Here are a few clients that you can use:

Queries

Firstly, let's begin by the listing the last 10 conversations your workspace has:

graphqlquery Contacts {
  app {
    conversations(last: 10) {
      nodes {
        id
        name
        firstName
        lastName
        displayName
        avatarUrl
        identifiers {
          sourceId
          category
        }
      }
    }
  }
}

Mutations

Now that you have successfully fetched a few conversations, let's reply to one of them. Make sure to change the conversationId value to match one of your conversations returned earlier.

graphqlmutation TextMessageCreate {
  textMessageCreate(input: { conversationId: 1, body: "Hello from API" }) {
    message {
      id
    }
  }
}