Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The following code can be used to retrieve example retrieves a token and request requests the list of service locations accessible to the current account:

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

Code Block
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();