Doshii uses Strings over Integers when available
It's a fine balance between stability and flexibility. As such, there are some fields where Integers and Strings are both accepted as valid for a number.
Flexibility is good, right?
It is, if you're aware of the gotchas involved in this method of accepting data.
Let's look at a common example of the Partner endpoint POST /orders
. Specifically the order.items
property.
The first object in the array contains a property called quantity
. This is a field that accepts either a String or an Integer.
Here's a sample body.
{
"consumer": {
"name": "Tony T",
"phone": "01234567890"
},
"order": {
"type": "pickup",
"surcounts": [],
"items": [
{
"name": "Toasted Sourdough Bread & Eggs",
"description": "Just ye old classic",
"unitPrice": "1100",
"totalBeforeSurcounts": "1100",
"totalAfterSurcounts": "1100",
"posId": "toasted_eggs",
"quantity": 1, // <=========
"surcounts": [],
"options": []
}
]
}
}
This all seems fine, why are we talking about this?
Ah, well, this is where the catch resides. If you send us an Integer, the API will send you back an integer.
Here's the order you just sent up from GET /orders/:id
{
"id": "16",
"phase": null,
"notes": null,
"requiredAt": null,
"status": "pending",
"type": "pickup",
"checkinId": null,
"locationId": "MV8YOY6w",
"items": [
{
"name": "Toasted Sourdough Bread & Eggs",
"posId": "toasted_eggs",
"options": [],
"quantity": 1, // <======= Hi, I'm an Integer
"surcounts": [],
"unitPrice": "1100",
"description": "Just ye old classic",
"totalAfterSurcounts": "1100",
"totalBeforeSurcounts": "1100"
}
],
"surcounts": [],
"consumer": {
"name": "Tony T",
"phone": "01234567890"
},
"updatedAt": "2017-01-04T04:03:18.068Z",
"transactions": [],
"version": "gAjPndlnXaSdePpqALeJCgBYzjyKKvHP0RRrjjKw",
"uri": "http://localhost:2001/partner/v3/orders/16"
}
Still seems fine, why are we still talking about this?
Because inversely, if you send us quantity
as a String, we'll also respond to you with a String.
What we're trying to say here is that if you send a type, expect the same type back for these fields.
All in all, we'd prefer if you send these fields that accept either Strings or Integers, as Strings. The fields themselves are marked in the API Reference.
This only affects Partner Applications.