Working With Eloquent: API Resources In Laravel
August 27, 2019My Java ExceptionUtil Class
September 16, 2019Note: Sage One has been renamed to Sage Business Cloud.
If you’re looking to integrate into the Sage One API, you will need to get your company id. There is no clear explanation of where to find it, so I hope this helps you.
We will be using curl in this tutorial to talk to the Sage API. If you are looking for more information about the API you can find it on their API help pages.
- https://www.sageone.co.za/developer-zone/
- https://accounting.sageone.co.za/api/2.0.0/Help
- https://www.sageone.co.za/api-methods/
How to get your Company ID:
You will obviously first need to have a company loaded on Sage. And secondly, you will need to have an API key. To get an API key, follow the instruction on link 1. above.
Their API uses basic webforms authentication. You will need to add your username and password, separated by a semi-colon and Base64 encoded to your headers. E.g. example@company.com:Password123 becomes ZXhhbXBsZUBjb21wYW55LmNvbTpQYXNzd29yZDEyMw==Â
Then it’s just a matter of making a single GET request to their get companies endpoint which is currently
curl -g -H 'Authorization: Basic ZXhhbXBsZUBjb21wYW55LmNvbTpQYXNzd29yZDEyMw==' 'https://resellers.accounting.sageone.co.za/api/1.1.3/company/Get?apikey={apiKey}'
The above command is sending a GET request to https://resellers.accounting.sageone.co.za/api/1.1.3/company/Get?apikey={apiKey}
. And it's also setting the headers to Authorization: Basic ZXhhbXBsZUBjb21wYW55LmNvbTpQYXNzd29yZDEyMw=='
This will return a list of all companies on your account. You can get the company id from the body. It's just titled ID
. The results look something like this:
{ "TotalResults": 1, "ReturnedResults": 1, "Results": [ { "ID": 123456, "Name": "Example Company", "CurrencySymbol": "R", "CurrencyDecimalDigits": 2, ... }, .... ] }