A few examples of retrieving invoices and using OData to filter for specific results.
Simple GET examples:
- Here is a sample call to the API requesting all the invoices from the Company File to be returned in the response:
- Here is a sample call to the API requesting a specific invoice using the invoice's unique ID:
domain/GUID/Sale/Invoice/INVOICE_UID
Using ODATA in the GET Request :
- The following will return all Suppliers sorted in ascending order by Company Name
domain/GUID/Contact/Supplier?$orderby=CompanyName asc
- The following will return all sorted in descending order by Company Name
domain/GUID/Contact/Supplier?$orderby=CompanyName desc
- The following will query the Payroll advice report by specific PayPeriodStartDate
domain/GUID/Report/Payroll/EmployeePayrollAdvice/?$filter=PayPeriodStartDate eq datetime'2015-03-22'
If your want to see a few more examples on OData filtering tips and tricks read this very informative Knowledgebase article. You may also want to have a look at this Knowledgebase article which helps you to dig a bit deeper into OData for MYOBapi.
Useful Tips and Tricks
- Filtering Addresses
Filtering addresses is something that is a bit tricky. The addresses are stored as an array so you need to do something like this:
?$filter=Addresses/any(x: x/City eq 'Melbourne')
The 400 bad request
The 400 bad request is a result of small mistakes in your query string. For example, getting the case of a letter wrong when referring to a specific field when you are trying to filter. Here's an example: domain/GUID/Sale/Invoice/Item/?$orderby=Number asc.Here the letter N in Number should be lowercase n.
The same principle applies to any of the other letters, they are case sensitive!
- Specify the API Version!
Sometimes the most obvious of things can cause the most grief. A perfect example of this is the very common mistake of forgeting to specify the version of the API when making a call. You MUST always specify the version to be version 2 i.e. v2 in your headers, regardless of whether you are working locally or on the cloud. The reason for this is that by not specifying it will defualt to v1 and v1 does not have GUIDs, and that right there is something you don't want, you will get a "bunch" of grief. In other words, pay special attention to this section of the documentation.
- Last Created Data or Last Modified Query
A request that has been popping up a bit more often lately is "Is there any way to fetch last inserted data or last modified?".
The short answer to this is that for the AccountsRight API, the Contact objects have a LastModified field which we can use to query Contacts which have been updated by the user and retrieve them. As for the other endpoint, LastModified or equivalent is not available just yet, we are looking to gradually roll them out among other endpoints as we go so essentially incremental releases.
In the meantime, you may want to use our implementation of E-tags. Using the e-tag gives you the ability to query a resource collection or individual one to determine if anything has been modified. these are available on all endpoints and returned as part of the response headers.
Comments
0 comments
Article is closed for comments.