^Login

API Locations

The Location actions read and write an account's Locations: the sites staff are rostered and clock on at. get_locations returns every Location with its ID (LID). upsert_locations adds Locations or updates them, matched by Microkeeper's LID or by your software's own ID (third_ID).

Actionsget_locations, upsert_locations
Business key accessAccount: Read Only to get, Read/Write to upsert

Before you start, make your keys and test your connection: see Microkeeper API.


Get the Locations with get_locations

FieldValue
mk_actionget_locations
mk_data{"status":"all"}

Response

Every Location is returned, active and inactive:

{
"success": "1",
"authenticated": "1",
"message": "Location data",
"data": {
"locations": [
{
"LID": "14227",
"third_ID": "MEL-01",
"title": "Melbourne Restaurant",
"lon": "144.970700",
"lat": "-37.814100",
"JID": "0",
"manager_eusername": ["sophie_brown", "mia_chen"],
"GID": "59467",
"CID": "0",
"hours_goal": "100.00",
"cost_goal": "10000.00",
"color": "#FF80EA",
"active": "1",
"address1": "1 Collins Street",
"address2": "",
"city": "Melbourne",
"state": "VIC",
"postcode": "3000",
"country": "Australia"
}
]
}
}
FieldWhat it is
LIDThe Location's ID in Microkeeper
third_IDYour software's ID for the Location, or null if none is set
titleThe Location's name
lon, latThe Location's longitude and latitude, for GPS clocking
JIDThe Location's default Job, or 0
manager_eusernameA list of the Location's managers, by username
GIDThe Group of staff who work at the Location
CIDThe client the Location belongs to, or 0
hours_goal, cost_goalThe Location's budgeted hours and labour cost
colorThe Location's colour on the roster, as a hex code
active"1" active, "0" inactive
address1, address2, city, state, postcode, countryThe Location's address. postcode is stored as a number, so a leading zero is dropped (0800 comes back as 800) and a blank postcode comes back as 0. Pad Australian postcodes back to four digits when you read them

Errors

  • The status variable must be included, Location API field status must be set to all: send "status":"all".
  • There are no Locations in Microkeeper yet

Add or update Locations with upsert_locations

Each Location you send is added or updated. Locations you don't send are left as they are.

Example

{
"config": { "write_list": "all" },
"locations": [
{
"LID": 0,
"third_ID": "GEE-01",
"title": "Geelong Cafe",
"active": "1",
"manager_eusername": ["mia_chen"],
"lat": "-38.147800",
"lon": "144.360700",
"address1": "20 Moorabool Street",
"city": "Geelong",
"state": "VIC",
"postcode": "3220"
},
{
"LID": 14228,
"title": "Sydney Restaurant",
"active": "0"
}
]
}

The first Location is added, or updated if GEE-01 is already in Microkeeper. The second makes the Sydney Location inactive.

How each Location is matched

  • A known LID updates that Location. A third_ID sent with it is saved on that Location, unless another Location already has it.
  • LID 0, or no LID, with a third_ID already in Microkeeper, updates that Location.
  • Otherwise a new Location is added.

Use third_ID to match by your own IDs, so you don't need to store Microkeeper's. Send LID 0 with it. Each third_ID belongs to one Location and can appear only once in a request. A blank third_ID leaves the Location's saved one as it is.

Fields

FieldRequiredWhat it is
config.write_listYesall
LID or third_IDOne of themMicrokeeper's ID, 0 for a new Location, or your software's ID, up to 32 characters
titleYesThe Location's name, up to 50 characters
activeYes"1" active, "0" inactive
manager_eusernameNoA list of managers' usernames. It replaces the Location's managers; send [] to remove them all
lon, latNoLongitude and latitude
JIDNoThe default Job
GIDNoThe Group of staff who work at the Location
CIDNoThe client
hours_goal, cost_goalNoBudgeted hours and labour cost
colorNoA hex colour, such as #FF80EA
address1, address2, city, state, postcode, countryNoThe address. address1 and address2 take up to 30 characters, and city, state and country up to 20. postcode is stored as a number

On an update, fields you leave out keep their values. Managers are given access to the Location, and lose it when you take them off the list.

Longer values are cut short to the limits above. In third_ID, title and the address fields, characters other than letters, numbers, spaces and ~ ! @ # / $ ^ * ( ) _ | : > [ ] . - are removed, so characters such as & ' " , % ? and accented letters are lost.

manager_eusername, JID, GID and CID are saved as you send them, without being checked against the account. Take usernames from get_employees, Groups from get_group_config (see API Employee) and Jobs from get_jobs (see API Jobs).

Response

{ "success":"1", "authenticated":"1", "message":"Locations updated", "data":{"LID":[14229,14228]} }

LID lists the Location IDs added or updated, in the order you sent them. Store them if you match by LID.

Errors

An error stops the request, and nothing is changed.

  • The write_list field must be set, Status must be set to all: send "config":{"write_list":"all"}.
  • A list of locations was not supplied: locations is missing, isn't a list, or is empty.
  • Each location must include LID or third_ID as unique ID
  • LID 14300 does not exist: send 0 to add a Location.
  • Duplicate third_ID GEE-01 present: each third_ID appears once in a request, whether or not you send a LID with it.
  • third_ID GEE-01 is already used by LID 14229: you sent a known LID with a third_ID that another Location has. Send that Location's LID, or send LID 0 to match by third_ID.
  • The Location Title must be set
  • active must be set and be either 1 or 0