Library
Some APIs that return data allow you to extend and customise the response format. This is done by defining a object structure, and passing that template object as part of your query. If you do not provide a response format the API will return a default set of values. Overall this lets you request exactly what you require, including, in some cases, related sub data, such as requesting a customer returning the 5 most recent sales.
Quick Example
{
a: "fd1.data",
v: { table: "products" },
qo: {
pid: true,
"Current-Price": price,
"SupplierID" : "spid" ,
"SupplierName": "spid.name"
"SupplierDetails": {
name: "spid.name",
email: "spid.email"
}
"One_Image": "images[best].url"
}
}
Sample Output
{
r: "fd1.data",
data: {
rows: [ {
pid: 4724,
"Current-Price": 10.95,
"SupplierID": 42,
"SupplierName": "Acme Supplies",
"SupplierDetails": {
name: "Acme Supplies",
email: "orders@acme.example.com"
}
"One_Image": "https://example.com/p4724.png"
} ]
}
}
Tip: Mouse over the JSON definition.
A slightly longer explanation of the above is to consider that everything is stored in a "table" or spreadsheet conceptually. So there would be a table
of products that might look like this
| pid | description | price | Price ExTax | supplier id aka spid | alternative spid | department id | Is Raw | Health Standard | Harmonized Code | .... |
| 4724 | Sparkling Water | 10.95 | 9.875 | 42 | 157 | 19 | 0 | AS 441 | 123456 | more data... |
The "qo" request, is simply extracting the columns for each row and placing into the output object. Except when we get to supplier; the product only has a reference, which is an id into the suppliers table.
Suppliers.| spid | name | phone | city | .... | |
| 42 | Acme Supplies | 09 123 4567 | orders@acme.example.com | Suva | more data... |
| 157 | Adams & Collier | 02 9876 3456 | xyz@ac.com | Tullamarine | more data... |
The "SupplierID": "spid" in the qo means, for the current product row, extract the "spid" field and return that.
The "SupplierName": "spid.name" means, extract the "spid" for the current row. We know that id refers to a supplier, so lookup the corresponding supplier row, and return the name field.
The "SupplierDetails": { name: "spid.name", email: "spid.email" } means the same thing as the two rows above, but in the case it has been placed in a sub object. This kicks in when returning an array of sub values, such as all items on a sale.
The "One_Image": "images[best].url" is doing the same operation. Select the "images" table. Reduce that table and select the "best" (single) image for this product, and return the URL. "best" is a selection keyword and has meaning to images. Consider it to be like an SQL where clause reducing the rows. In this case, it will probably select the rank=1 image
Images.| pid | ImageId | url | licence | rank | camera angle | .... |
| 4724 | NJ92183.2 | https://example.com/p4724.png | private | 1 | front oblique | more data... |
| 4724 | KNJ92BCW | https://AWS-bucket/SKBOF$Hjnvheh46.jpeg | supplier | 8 | front | more data... |
Example. A normal request for a purchase order is thus
POST /fd1/purchaseorders/get_purchaseorder_header
{
"a": "purchaseorders.get_purchaseorder_header",
"q": {
"cust_ponum": 12345
}
}
Or the GET equivalent, (GET /fd1/purchaseorders/get_purchaseorder_header?cust_ponum=12345)
This instructs Fieldpine to return the default details about purchase order 12345. Invariably this will always be too much or too little. You can therefore add a "qo" object that defines what you want to receive and how it is structured
POST /fd1/purchaseorders/get_purchaseorder_header
{
"a": "purchaseorders.get_purchaseorder_header",
"q": {
"cust_ponum": 12345
},
"qo": {
"poid": true,
"AnotherNameForId": "poid",
"entrydt": true,
"completeddt": true,
"theSupplier": {
"name": "supplier.name",
"phone": "supplier.phone"
},
"No_of_lines_on_PO": "poline._count"
}
}
You don't really need to learn this for simple use cases, just do this
Simple Example, starting from a "sale"
... qo: {
saleid: true, // Return current sales id#
total_extax: true, // Return total value of this sale, exclusive tax
customer: {
id: "sale.cid", // What is the customers id# (if any)
email: "customer.email", // Lets get their email too
totalsalecount: "customer.sales._count" // Can we also get the total number of sales this customer has ever made
}
}