Skip to main content

No project description provided

Project description

Basecamp API

This package allows simple interaction with Basecamp API using Python.

Table of contents

  1. Installation
  2. Initial authentication: Getting your refresh token
  3. Generating and using Basecamp sessions
  4. Uploading files
  5. Additional information

1. Installation

The package can be installed from your terminal by typing:

pip install basecampapi

or

pip3 install basecampapi

2. Initial authentication: Getting your refresh token

To be able to interact with Basecamp's API, we need to provide an access token upon each API request. Basecamp's access tokens are set to expire 2 weeks after being generated, which is why we need to generate a refresh token.

Refresh token allows us to automate the process of generating an access token. We only have to generate the refresh token once and after that we can use it to gain access to Basecamp each time we run our script.

To gain access you need a developer app on Basecamp. App can be created on https://launchpad.37signals.com/integrations, after which you need to use the generated Client ID, Client Secret and the Redirect URI which you provided for initial authentication. You can read more about the authentication process on Basecamp API Authentication page.

To begin the authentication process, you need to create a dictionary with your app credentials and use it in the Authorization object:

import basecampapi as bc

credentials = {
	client_id: "your-client-id",
	client_secret: "your-client-secret",
	redirect_uri: "your-redirect-uri"
}

auth = bc.Authorization(credentials=credentials)

This will open a verification page in your browser. Click on "Yes, I'll allow access":

Verification page

It will redirect you to the link you provided as Redirect URI, but it will have the verification code in the url address. Save that verification code:

Verification code

Use the the verify() method on the previously created Authorization object and add your verification code to generate the refresh token:

# Verification code variable 
my_verification_code = "17beb4cd"

auth.verify(code=my_verification_code)

verify() method will print out your refresh token. Make sure to save it and don't share it with anyone because it allows access to your personal Basecamp account and anyone with this information would be able to impersonate you on Basecamp. You will use this refresh token each time you access the Basecamp API, so make sure you save it somewhere safe.

3. Generating and using Basecamp sessions

To interact with objects on Basecamp you have to initialize a session object. This object will generate your access token and allow you to interact with other Basecamp objects. To do this, you need to pass your credentials and account ID to the Basecamp object.

Your account ID can be found on your Basecamp home page, in the URL address:

  • https://3.basecamp.com/YOUR-ACCOUNT-ID/projects
import basecampapi as bc

credentials = {
	"client_id": "your-client-id",
	"client_secret": "your-client-secret",
	"redirect_uri": "your-redirect-uri",
	"refresh_token": "your-refresh-token"
}

basecamp_session = bc.Basecamp(account_id="your-account-id", credentials=credentials)

After that you will be able to use your session object within other Basecamp objects.

# Initiates a Campfire object using previously created session
my_campfire = bc.Campfire(campfire_id='your-campfire-id', project_id='your-project-id', session=basecamp_session)
# Sends a campfire message with desired content
my_campfire.write(content="Hello from Python!") 

4. Uploading files

When attaching images or other files to Basecamp posts we do this by using Rich text, which means that we will be sending HTML as content to the Basecamp object we want to interact with.

Sending rich text through API is not allowed on all Basecamp objects that have rich text by themselves. Best example are Campfires, when interacting with Basecamp you can upload images and files to a campfire or edit the text style, but Basecamp API does not allow this to be done programatically. Here is a list of Basecamp endpoints that can accept rich text.

To upload a file to Basecamp, first we need upload the file to Basecamp's server and get its attachable_sgid. We can do this by passing the file path to the upload_file() method on our Basecamp session object:

basecamp_session.upload_file("folder/image.png")

After this the file will be on Basecamp's server and it will have an automatically generated attachable_sgid Uploaded files can be accessed through session:

print(basecamp_session.files)

This returns a list of dictionaries that contain information about the files you uploaded:

[{'filename': 'image.png',
  'file_size': '155291',
  'content-type': 'image/png',
  'sgid': 'your-file-sgid'}]

To attach a file inside a Basecamp post, comment or any other object where rich text is accessible through API, we need to send an HTML string as the content parameter of the object we are interacting with, and we need to use the <bc-attachment> tag for any file attachments.

"<bc-attachment sgid='your-file-sgid'></bc-attachment>"

Creating a new Message Board post on Basecamp with our uploaded image will look like this:

# Constructing the content string
content = "Hello world! <br> / 
<bc-attachment sgid='#######'></bc-attachment> <br> /
This is an image sent from python."

# Initiating the message board object (using the previously created session object)
message_board = MessageBoard(project_id=123456, message_board_id=123456, session=basecamp_session)

# Creating a message
message_board.create_message(subject="Test message", content=content)

5. Additional information

Currently available endpoints:

  • Campfire - allows reading campfire messages and writing to campfires
  • MessageBoard - allows reading, creating and updating messages, as well as reading, creating and updating comments on messages

Future upgrades:

  • Vaults (Docs & Files)
  • To-dos

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

basecampapi-0.2.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

basecampapi-0.2.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file basecampapi-0.2.0.tar.gz.

File metadata

  • Download URL: basecampapi-0.2.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.10.2 Darwin/22.2.0

File hashes

Hashes for basecampapi-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7d4ef8c72445d8eb1f0565aba2d6fdb506a31ae655712cb64c64e591d36f0ce4
MD5 2a9d5d7ecd82a6a3ed14384434bde12f
BLAKE2b-256 6a31313e6f7f9ba80e382d773f6cf950d9c2909f40dd41d2bfad18e57e3d1cfb

See more details on using hashes here.

File details

Details for the file basecampapi-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: basecampapi-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.10.2 Darwin/22.2.0

File hashes

Hashes for basecampapi-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82bec0e509ecbc509f6a2ba07871a8f98026d18163e8aca0c153d8fff13e5332
MD5 e846d19d1e28344bca29d38761c3568c
BLAKE2b-256 707c6c89fa89704080b98b822ea5bb2b91167eba28e870ec05a2dd54934c904f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page