Documents

For more information, please see the official Basecamp API documentation on documents

class basecamp.documents.Document(account_url, access_token, refresh_token=None)

Actions on a document

create(project_id, title, content)

Create a new document.

Parameters:
  • project_id – project id to create the document in.
  • title – title of the document.
  • content – content of the new document.
Rtype dictionary:
 

dictionary representation of the new document.

>>> import basecamp.api
>>> url = 'https://basecamp.com/1/api/v1'
>>> token = 'foo'
>>> refresh_token = 'bar'
>>> documents = basecamp.api.Document(url, token, refresh_token)
>>> documents.create(22, 'Cole Porter Songs', 'My favorite songs.')

Note

The JSON response will look similar to getting details of a document from fetch()

fetch(document_id=None, project_id=None)

Get a specific document, or a list of documents, either by project, or all documents a user has access to in the basecamp account.

Parameters:
  • document_id – integer of document
  • project_id – integer of project
Rtype dictionary:
 

Dictionary of documents, or a single document.

Note

There are three methods of document retrieval.

  1. Global for the account. document_id and project_id kwargs are omitted
  2. Documents limited to a specific project. The project_id kwargs is passed to the method call.
  3. Details on a specific document. The project_id and document_id kwargs are passed to the method call.

Warning

Passing a document_id but no project_id will cause a BasecampAPIError exception to be raised.

Examples:

All documents in the account:

>>> import basecamp.api
>>> url = 'https://basecamp.com/1/api/v1'
>>> token = 'foo'
>>> refresh_token = 'bar'
>>> documents = basecamp.api.Document(url, token, refresh_token)
>>> documents.fetch()

Get documents within a project:

>>> import basecamp.api
>>> url = 'https://basecamp.com/1/api/v1'
>>> token = 'foo'
>>> refresh_token = 'bar'
>>> documents = basecamp.api.Document(url, token, refresh_token)
>>> documents.fetch(project_id=123)

Get details on a single document:

>>> import basecamp.api
>>> url = 'https://basecamp.com/1/api/v1'
>>> token = 'foo'
>>> refresh_token = 'bar'
>>> documents = basecamp.api.Document(url, token, refresh_token)
>>> documents.fetch(document_id=123, project_id=123)
remove(project_id, document_id)

Delete a document from the project/account

Parameters:
  • project_id – integer of project id
  • document_id – integer of document id to remove
Rtype boolean:

True if the document is removed.

>>> import basecamp.api
>>> url = 'https://basecamp.com/1/api/v1'
>>> token = 'foo'
>>> refresh_token = 'bar'
>>> documents = basecamp.api.Document(url, token, refresh_token)
>>> documents.remove(22, 244)

Note

If the document is not removed, or if a problem occurs, a :class::BasecampAPIError exception will be raised.

update(project_id, document_id, title, content)

Update a document.

Parameters:
  • project_id – integer of project id
  • document_id – integer of document id
  • title – string of title
  • content – string of document content
Rtype dictionary:
 

Document information

>>> import basecamp.api
>>> url = 'https://basecamp.com/1/api/v1'
>>> token = 'foo'
>>> refresh_token = 'bar'
>>> documents = basecamp.api.Document(url, token, refresh_token)
>>> documents.update(22, 244, 'foo title', 'bar content')

Note

The JSON response will look similar to getting details of a document from fetch()