It took me some time to decide whether to publish this guide or not, as it makes the API use official which I was not sure we wanted. However, many players already decided to go this route and therefore some official guidelines are needed.
WARNING
Really make sure you do not bash the servers too often with your API requests. The increased load on the servers would slow the game experience for everyone and consume a lot of engineering time on my side, as I will have to track you down and rate limit the API endpoints. Or in the worst case, take steps to block API access for everyone.
2nd WARNING - account activities are monitored for non-GET method access. If there is a suspicion of bot being used, the account is served a captcha. Using automation tools gives an unfair advantage, failing to answer captcha in 5 minutes will result in account deletion.
Given the warning you received, here's the guide written by COUP THE POLLUTION CO.!
When I talk to people about my API in game chat, I often get a surge of DM's asking me how I access the API and what I do with it. I've used SimCompanies to teach myself a bit more code, and I feel like I have learnt enough to share some of what I learnt however I know there is far more for me to learn. First though, a quick F.A.Q. where I keep saying no.
Do I need any programming experience?
None. At. All. Some experience with spreadsheets would help but you're here to learn right? I knew less than Jon Snow when I began my API journey and I know… some things.
Will you give me your work? No, my work has far too many bugs in it to share. You honestly wouldn't want it.
Do I need to pay for anything? Nope, I recommend using Google Sheets or Excel, both can do all the work but I will switch between them in this guide.
So let's get on with it shall we? First of all, what on Earth is an API? Well, API is short for Applied Programming Interface and is a way for a website to store data with a URL for reference. Try copy and pasting https://www.simcompanies.com/api/v2/companies/me/ into your browser. Wow! Look at all that meaningless text! You might be able to make out a few things like your company ID, name or level, but it really needs some organisation. Go to http://json2table.com/ and copy paste your data in and hit the arrow. Bam. Suddenly the data is organised and you can make sense of it. Simcompanies holds a huge amount of data in the API, but there is not much in the API that is not already found on the pages of the site. The key to the API is automation.
So what now? Well, we've got to work out how to find more of these links to the API. I really encourage you to take this step by step and do it on your own as knowledge is power, but if you are struggling I will walk you through it. First, open dev tools in this tab. This may be done with the buttons Shift+Ctrl+I or via a menu, depending on your browser. Navigate to the ‘Network' tab and refresh the tab. WOW. Loads of stuff. Try looking through this and finding some API links. No luck? Try search API into the filter. That cuts us down to just a few results. If you visit different parts of the site there will be different API's shown to you. I recommend paying a visit to player profiles and the encyclopaedia, especially for retailers. Some links will require ‘cookies', which will mean they cannot be automated later on. A general rule of thumb is if you can access the link whilst logged out, you can use the API for automation
An exchange price tracker is one of the most simple API tricks we can do whilst being one of the most powerful. There is the link we saw earlier called “me”, and something with a date. Copy paste the URL of the date API and just like that you have the lowest price of every product that has recently had a change in it's lowest price on the exchange. The game uses this data for the market ticker. Why it contains the prices of the products only Patrick knows, and he's not writing this guide. Let's head to Excel and try and sort this data (Google sheets users can skip to later where I talk about how to use =IMPORTJSON). Open up a new PowerQuery search in Excel from the ‘Data>Get Data From Web' tab and paste in that market ticker URL. Click ‘to table', hit ok and expand Column1. Sort the data as you wish and remove any un-needed columns, then hit ‘close and load' and you will find all the lowest exchange values at your disposal in your excel file. Huge amounts of number crunching and math can be done from this single link. For some reason in excel the date and time part of the URL never seem to matter, you always get the most up to date ticker, just hit “refresh all” to get the most recent data. If you can work out why this is, please let me know. It wouldn't be too hard from this point to copy paste the list of prices once a day or so and suddenly you have a tracker of the prices on the exchange! Perhaps try making a macro that records the data, waits a few minutes, then refreshes and restarts the process. If you are feeling ambitious look at Visual Basic (The code language the macros are written in) and edit a couple lines, go wild, see what happens. Remember to save regularly though as crashes will occur if you make certain errors. Now your program is a fully fledged market tracker. Congrats! Give it a zealous over-the-top name and give yourself a pat on the back.
Google Sheets has a clear advantage and disadvantage. The advantage is you can use timers to automate processes so the whole thing works on it's own online without the need for a server. The disadvantage is it doesn't have PowerQuery at it's disposal. Follow the instructions here for how to use a custom command called IMPORTJSON here https://medium.com/@paulgambill/how-to-import-json-data-into-google-spreadsheets-in-less-than-5-minutes-a3fede1a014a AND https://bit.ly/1vO8Frj and get the actual code from here, https://github.com/bradjasper/ImportJSON/blob/master/ImportJSON.gs AND https://bit.ly/30ZqrJY. You only need to copy paste the code into a script and save the script for it to work. *Note for Admins reviewing this- I think the bitly URL's are better but if you wish to avoid those then I have included the full URL's. I suggest only one or the other is included in the final article. End Note* Take a look back now at the steps I go through in the previous paragraph and see if you can use a timer and a macro to automate the process for a bit more advanced usage. You will have to find a way to change the marker ticker date and time, but I will let you find out how to do that on your own. Please do not run the program more than once every 5 minutes as this puts strain on Patricks servers.
So you think you know your stuff now? Well this is where the learning curve goes from a gentle slope to parkouring across city rooftops whilst blindfolded and with your hands tied behind your back. I'm going to talk in varying degrees of technical stuff and stretch the limits of my very limited knowledge here. Let's talk cookies. By using cURL in Command Line or Bash we are able to access URL's that might otherwise be restricted by logins. These included detailed exchange API's with every product, quantity and quality, allowing you to track almost all transactions on the exchange (my personal favourite) or detailed user information such as what buildings a player has, what they have on the exchange and their company values and ranks (Oh I have such a good idea for this one). I'll let you find all these URL's on your own, and I can tell you that there is a collection of dead API links and a couple hidden live ones in the game code that you can go hunting for. If you do start writing in program in Python and wanna chat or get some help then feel free to drop me a PM or ask in game chat and someone will come to your aid (DISCLAIMER: Players may not come to your aid, wait times may exceed 24 hours, consult your doctor before use).
Do you have what it takes to build a successful company? Try Sim Companies business simulation game now!