Search…
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

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

Vanilla JS

1
const fetch = require("node-fetch");
2
const token = 'YOUR-TOKEN';
3
4
fetch(
5
'https://api.hal.xyz/',
6
{
7
method: 'POST',
8
headers: {
9
'Content-Type': 'application/json',
10
'Accept': 'application/json',
11
'Authorization': `Bearer ${token}`,
12
},
13
body: JSON.stringify({
14
query: '{ allTriggers { name } }'
15
}),
16
}
17
)
18
.then(res => res.json())
19
.then((res) => {
20
console.log(res.data)
21
})
22
.catch((error) => {
23
console.log(error);
24
});
Copied!

Apollo Example

1
const { ApolloClient } = require('apollo-client');
2
const { createHttpLink } = require('apollo-link-http');
3
const { setContext } = require('apollo-link-context');
4
const { InMemoryCache } = require('apollo-cache-inmemory');
5
const fetch = require('node-fetch');
6
const gql = require('graphql-tag');
7
8
const token = 'YOUR-TOKEN';
9
10
const httpLink = createHttpLink({
11
uri: 'https://api.hal.xyz/',
12
fetch: fetch
13
});
14
15
const authLink = setContext((_, { headers }) => {
16
return {
17
headers: Object.assign(
18
headers || {},
19
{
20
'Content-Type': 'application/json',
21
'Accept': 'application/json',
22
'Authorization': `Bearer ${token}`,
23
}
24
)
25
}
26
});
27
28
const client = new ApolloClient({
29
link: authLink.concat(httpLink),
30
cache: new InMemoryCache(),
31
});
32
33
client.query({ query: gql`{ allTriggers { name } }` })
34
.then((res) => {
35
console.log(res.data);
36
})
37
.catch((error) => {
38
console.log(error);
39
});
40
Copied!
Last modified 2yr ago