-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickstart.js
More file actions
38 lines (33 loc) · 1.16 KB
/
quickstart.js
File metadata and controls
38 lines (33 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const { SquareClient, SquareEnvironment, SquareError } = require("square"); //this imports the Square SDK
require('dotenv').config() //what this does is load the .env file and makes the variables available in process.env
// client object
const client = new SquareClient({ //this section creates a new Square client
token: process.env.SQUARE_ACCESS_TOKEN, //set access token from .env file
environment: SquareEnvironment.Sandbox, //set environment to Sandbox
});
// async function to list locations
async function getLocations() {
try {
let listLocationsResponse = await client.locations.list();
let locations = listLocationsResponse.locations;
locations.forEach(function (location) {
console.log(
location.id + ": " +
location.name + ", " +
location.address.addressLine1 + ", " +
location.address.locality
);
});
} catch (error) {
if (error instanceof SquareError) {
error.errors.forEach(function (e) {
console.log(e.category);
console.log(e.code);
console.log(e.detail);
});
} else {
console.log("Unexpected error occurred: ", error);
}
}
};
getLocations();