In this article, we will show you how you can get started setting up an API call using the Python client library. We will cover the most basic steps you need to be able to set up an API call.
In some cases, you might want to extract data from GetFeedback Digital or structure the data in a certain way, different from the default GetFeedback Digital reports that you can generate from your GetFeedback Digital account. In that case, you can use our API to extract the data you need.
Requirements:
- Basic understanding of the Terminal
- Basic understanding of the concept of an API
- A code editor (we will be using Visual Studio Code)
Table of content:
- Check if Python 2.7 is already installed
- Install Python 2.7
- Test if everything works
- Install GetFeedback Digital API
- Execute GetFeedback Digital API calls
1. Check if Python 2.7 is already installed
To make anything work, we first need to make sure that Python is installed on your computer. Some computers already have Python pre-installed. Let’s first check if you already have Python installed:
- Open Terminal on your computer
- Type:
python
Based on the output, we can see that Python 2.7 is installed. If you have version 2.7 (or 2.7.x), you’re lucky and you can continue to step 3! If not, we will have to install Python 2.7 before we can proceed.
If you’re on a Windows computer, you might first have to navigate to the folder where Python is installed for the Python interpreter to work.
2. Install Python 2.7
- Navigate to www.python.org/downloads
- Click on the download link for version 2.7
- Follow the installation instructions
- Open your Terminal and type the command
python
again. The Python interpreter should respond with the version number.
3. Test if everything works
Now, let’s create a Python file that we can use to test if everything is set up correctly.
1. Create a working directory (folder) we can store all our Python code in
2. Open Visual Studio Code and create a new file
3. In the Visual Studio Code editor for the new file type: print(“Hello World!”)
4. Save the file as test.py
in your Python folder we created in step 1.
5. Open Terminal and move into the folder where we saved our Python test file
Note: You can move from one directory to another one by typing cd
followed by the path to move into the specific folder: cd full_path
6. Execute the Python file by typing: python test.py
7. If everything has been set up correctly you should get Hello World! printed out in your terminal output:
4. Install GetFeedback Digital API
Now that you have Python installed, it’s time to install the GetFeedback Digital python library on your computer.
1. Open Terminal
2. Install pip on by running easy_install pip
3. Type pip install usabilla-api
Note: If you're using a Windows OS or have difficulties installing pip in step 2, then follow the guidelines here: https://pip.pypa.io/en/stable/installing. If you're running into issues in step 3, then type sudo pip install usabilla-api
on Mac. For Windows, run the terminal as Administator and then try again.
5. Execute GetFeedback Digital API calls
To get you started with doing API calls towards our servers, we will walk you through an example on how you can retrieve all GetFeedback Digital buttons from your account.
1. Start by creating a file in your Python folder which we will name getAllButtons.py
2. In the code editor, paste this code into your file:
"Python API - List out all GetFeedback Digital buttons with ID and name"
import usabilla as ub
import json
# Create an API client with access key and secret key
api = ub.APIClient('ACCESS-KEY', 'SECRET_KEY')
# Get all buttons in account
buttons = api.get_resource(
api.SCOPE_LIVE, api.PRODUCT_WEBSITES, api.RESOURCE_BUTTON, '*', iterate=True)
parsed_json = json.loads(json.dumps([item for item in buttons]))
# Print out all buttons with ID and name
for record in parsed_json[:]:
btn_id = record['id']
btn_nm = record['name']
print("Button ID: " + btn_id + " || Button name: " + btn_nm)
3. Change the access key and secret key and then save the file.
4. Open Terminal and move into the Python folder by using cd
5. Once you’re in your python folder with the getAllButtons.py
file, you can execute it from the Terminal by typing: python getAllButtons.py
in the Terminal window.
Congratulations: Here's your trophy for making your API call! We have several example codes on our GitHub page that you now can start experimenting with: https://github.com/usabilla/api-python/tree/master/example