Fork me on GitHub

Project Notes

#296 PT Backup

How to script a simple Pivotal Tracker backup with python and the RESTful API

Notes

Pivotal Tracker does not have a built-in feature for direct project backups, but you can use its API to fetch and store project data.

See pt_backup.py for an example of a script to perform such a backup. It covers:

  • epics
  • stories
  • story comments including file attachments
  • story tasks
  • story activity
  • project memberships

Method/Algorithms

Epics

Stories

Story activity

  • Get all stories for a project
  • https://www.pivotaltracker.com/help/api/rest/v5#Activity
  • GET /projects/{project_id}/activity
  • supports pagination (required for most real-world projects)
  • history is limited:
    • most recent six months for any non-Enterprise subscription plan
    • last 25 months of activity for an Enterprise subscription plan
  • Note: I originally tried to download attachments based on activity until I noted the limited horizon

Story Comments

  • Get all comments for all stories in a project
  • https://www.pivotaltracker.com/help/api/rest/v5#Comments
  • GET /projects/{project_id}/stories/{story_id}/comments
  • does not support pagination
  • attachment ids are not included in the response by default. Request fields=:default,attachments to get full attachment details in the response
    • download attachments based on the attachments collection for each comment

Story Tasks

Project memberships

Running the Script

Install the required packages using pip:

pip install -r requirements.txt

The script expects the Pivotal Tracker API token and project ID to be provided as environment variables:

export PIVOTAL_TRACKER_API_TOKEN='your_api_token_here'
export PIVOTAL_TRACKER_PROJECT_ID='your_project_id_here'

To run the script:

$ PIVOTAL_TRACKER_API_TOKEN=my-token PIVOTAL_TRACKER_PROJECT_ID=my-id ./pt_backup.py /MyBackups
Data saved to /MyBackups/memberships.json
Data saved to /MyBackups/epics.json
Data saved to /MyBackups/stories.json
Data saved to /MyBackups/tasks.json
Data saved to /MyBackups/comments.json
Data saved to /MyBackups/activities.json
Backup complete!

Credits and References

About LCK#296 toolspython

This page is a web-friendly rendering of my project notes shared in the LittleCodingKata GitHub repository.

Project Source on GitHub Return to the LittleCodingKata Catalog
About LittleCodingKata

LittleCodingKata is my collection of programming exercises, research and code toys broadly spanning things that relate to programming and software development (languages, frameworks and tools).

These range from the trivial to the complex and serious. Many are inspired by existing work and I'll note credits and references where applicable. The focus is quite scattered, as I variously work on things new and important in the moment, or go back to revisit things from the past.

This is primarily a personal collection for my own edification and learning, but anyone who stumbles by is welcome to borrow, steal or reference the work here. And if you spot errors or issues I'd really appreciate some feedback - create an issue, send me an email or even send a pull-request.

Follow the Blog follow projects and notes as they are published in your favourite feed reader