Javascript example code

The following example retrieves a token and requests the list of service locations accessible to the current account:

(make sure to replace the credentials with your own!)

var test = async () => { let formData = new URLSearchParams(); formData.append('grant_type', 'password'); formData.append('username', '{{username}}'); formData.append('password', '{{password}}'); formData.append('client_id', '{{client_id}}); formData.append('client_secret', '{{client_secret}}'); const tokens = await fetch('https://farm1pub.smappee.net/dev/v3/oauth2/token', { method: 'POST', body: formData }) .then(response => response.json()); const accessToken = tokens.access_token; const result = await fetch('https://farm1pub.smappee.net/dev/v3/servicelocation', { headers: { Authorization: 'Bearer ' + accessToken } }) .then(response => response.json()); console.log(result); }; test();