Authentication

Authenticate with your token

To send requests to the HAL GraphQL server you need a valid token. A token is used to authenticate users as well as to create or retrieve user's data.

In REST, HTTP verbs determine the operation performed. In GraphQL, you need to provide a JSON-encoded body whether you're performing a query or a mutation, so the HTTP verb to be used isPOST. The exception is when performing an introspection query, which only needs a GET request.

How to obtain a valid token

Create an account on HAL and click on "Get my token" from the user menu.

Examples

Curl

$ curl 'https://api.hal.xyz/' \
-H 'Authorization: Bearer YOUR-TOKEN' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
--data-binary '{ "query": "query getAllTriggers { allTriggers { name } }" }'

Vanilla JS

const fetch = require("node-fetch");
const token = 'YOUR-TOKEN';
fetch(
'https://api.hal.xyz/',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${token}`,
},
body: JSON.stringify({
query: '{ allTriggers { name } }'
}),
}
)
.then(res => res.json())
.then((res) => {
console.log(res.data)
})
.catch((error) => {
console.log(error);
});

Apollo Example

const { ApolloClient } = require('apollo-client');
const { createHttpLink } = require('apollo-link-http');
const { setContext } = require('apollo-link-context');
const { InMemoryCache } = require('apollo-cache-inmemory');
const fetch = require('node-fetch');
const gql = require('graphql-tag');
const token = 'YOUR-TOKEN';
const httpLink = createHttpLink({
uri: 'https://api.hal.xyz/',
fetch: fetch
});
const authLink = setContext((_, { headers }) => {
return {
headers: Object.assign(
headers || {},
{
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${token}`,
}
)
}
});
const client = new ApolloClient({
link: authLink.concat(httpLink),
cache: new InMemoryCache(),
});
client.query({ query: gql`{ allTriggers { name } }` })
.then((res) => {
console.log(res.data);
})
.catch((error) => {
console.log(error);
});