An example of how to use the FourJaw API in Python.
Please ensure you have completed the first guide to gain an API key and access the interactive API docs before beginning this guide.
Introduction
If you want to automate data gathering using the FourJaw API, writing a custom script in Python is a powerful and quick option. Fortunately, it is simple to get started as our interactive API documentation already generates working Python code that you can copy and paste into your script.
Step 1) Generating the snippet
To generate the Python code snippet for the API, first navigate to the interactive API docs, as discussed in this guide.
When the docs have loaded, use the lefthand menu to navigate to an endpoint of your choice. In this example, I will be working with utilisation data.
On the resulting page, you will see on the righthand side a box showing a "Request Sample". By default, this shows as a Linux command, but if you click the dropdown arrow you'll see options for many different programming languages such as JavaScript, Python and Ruby.
By selecting Python > Requests, you'll see the box change to contain a snippet of Python code that uses the requests library. If you copy and paste this into a Python file and run it, you'll see data printed out from the API!
You can now leverage any other python capabilities to work wonders with the data.
Step 2) Changing the parameters
As a next step, you can change the parameters going into the Python script.
If it's just a single hardcoded request, you can actually change the parameters directly in the interactive docs using the dark box in the top right.
As you change the values in this box, you'll see the code snippet below update in real time.
However, it is likely you will want to change the request parameters programmatically. Fortunately, the snippet gives the parameters as a Python dictionary so you can directly swap out the hard coded strings for variables in your programme.
That should be everything you need to know to get Python pulling data from the API. If you have any questions, feel free to get in touch.