All you need to get started working with the FogBugz XML API is an HTTP library and an XML parsing library. We're going to use Python. If you've never used Python before, that's OK. We'll show you everything you need to know to get started.
Install Python and FogBugzPy
Quick installation steps:
Install Python 2.7.10 or Python 3.5.2. On Windows, we recommend the Windows MSI Installer.
- Add Python to your system path.
- Install FogBugzPy.
See Installing Python and FogBugzPy for more detailed instructions.
Python Interpreter Example
Go to the command line, type python, and press Enter. This will bring up the Python interpreter. Type the following code into the interpreter, replacing string values where appropriate to correspond to your FogBugz installation.
First, let's tell Python that we want to use the FogBugz library and create an instance of FogBugz called fb:
Next, log on using your username and password (you can also use an API token):
Let's do a basic search and print the result to the screen. Because we're not specifying any criteria to search, the API is just going to return the cases in our currently active filter. The prettify method makes the XML response easier to read.
What if I want to see all cases assigned to me? Use the q parameter to specify a FogBugz search. You can use any search axis that you would normally use in FogBugz:
When I return a list of something, I usually want to do something with each item in the list. This time, we'll use the cols parameter to specify which columns we want returned with our filter. Note that resp.cases.childGenerator() is one way to return a list of elements.
Here's another example of iterating through a list of cases, this time using resp.findAll('case')
Let's make an edit to a case. We'll use the FogBugz edit method. Note how we use the ixBug parameter to specify which bug we want to edit and the sEvent parameter to specify what text to include in the edit to the case.
Python Script Example
In the above example, we explored the FogBugz XML API using the interactive Python interpreter from the command line. This example will show how to save a script to a file and execute it from the command line.
Create a file called example.py. Copy the code below into that file, replacing the values at the top of the file to match your installation.
From the command line (in the directory that contains example.py), type the following to run the script:
Are you interested in learning more about Python? Start here:
- Python 2.7.10 documentation - the official documentation for Python 2.7.10
- Learn Python The Hard Way - a free online book (PDF and print versions also available) to get started programming in Python. Although it's called "the hard way," following along is very easy, requiring you to type out the code for each exercise. We highly recommend it if you're new to Python or programming in general.