All Collections
Development
How to Login and Authenticate API Calls in Timerise API
How to Login and Authenticate API Calls in Timerise API
Updated over a week ago

This tutorial provides a detailed guide on authenticating and making API calls using Timerise's GraphQL API. We will focus on the login mutation, and the me and teamMember queries. Examples are provided in both CURL and Node.js using Apollo Client.

Prerequisites

  • Basic understanding of GraphQL.

  • Node.js environment for running examples using Apollo Client.

  • Timerise API credentials (email and password).

Mutation: Login

The login mutation is used for user authentication to interact with the Timerise API.

CURL Example:

curl -X POST -H "Content-Type: application/json" --data '{ "query": "mutation { login(email: \"YOUR_EMAIL\", password: \"YOUR_PASSWORD\") }" }' https://api.timerise.io/graphql

Apollo Example:

const { ApolloClient, InMemoryCache, gql } = require('@apollo/client');

const client = new ApolloClient({
uri: 'https://api.timerise.io/graphql',
cache: new InMemoryCache()
});

const LOGIN_MUTATION = gql`
mutation Login($email: EmailAddress!, $password: NonEmptyString!) {
login(email: $email, password: $password)
}
`;

client.mutate({
mutation: LOGIN_MUTATION,
variables: {
email: 'YOUR_EMAIL',
password: 'YOUR_PASSWORD'
}
}).then(response => {
console.log(response.data.login);
}).catch(error => {
console.error(error);
});

Query: me

Fetches details of the currently authenticated user.

CURL Example:

curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer YOUR_TOKEN" --data '{ "query": "{ me { userId fullName email role } }" }' https://api.timerise.io/graphql

Apollo Example:

const ME_QUERY = gql`
{
me {
userId
fullName
email
role
}
}
`;

client.query({
query: ME_QUERY
}).then(response => {
console.log(response.data.me);
}).catch(error => {
console.error(error);
});

Query: teamMember

Retrieve information about a specific team member.

CURL Example:

curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer YOUR_TOKEN" --data '{ "query": "{ teamMember(projectId: \"PROJECT_ID\", userId: \"USER_ID\") { userId fullName email role } }" }' https://api.timerise.io/graphql

Apollo Example:

const TEAM_MEMBER_QUERY = gql`
query TeamMember($projectId: ID!, $userId: ID!) {
teamMember(projectId: $projectId, userId: $userId) {
userId
fullName
email
role
}
}
`;

client.query({
query: TEAM_MEMBER_QUERY,
variables: {
projectId: 'PROJECT_ID',
userId: 'USER_ID'
}
}).then(response => {
console.log(response.data.teamMember);
}).catch(error => {
console.error(error);
});

Static API Key for Company and Enterprise Plans

For users subscribed to the Company and Enterprise plans, Timerise offers the option of a static API key. This key provides a convenient way to authorize API calls without the need for repeated logins. To learn more about these plans and the availability of a static API key, you can contact the Timerise sales team at sales@timerise.io. For current pricing details, please visit Timerise Pricing.

Conclusion

This guide demonstrated how to authenticate and execute basic queries using Timerise's GraphQL API. You learned how to perform a login mutation to authenticate, and then use the obtained token to fetch details of the current user and a specific team member.

Replace YOUR_EMAIL, YOUR_PASSWORD, YOUR_TOKEN, PROJECT_ID, and USER_ID with your actual Timerise credentials and relevant IDs.

Feel free to use this tutorial to interact with the Timerise API effectively. If you need further assistance or have more questions, feel free to ask!

Did this answer your question?