Monday 13 July 2020

Creating an OAUTH2 token for a Basecamp App using python

I had trouble following some of the guides, so used the following approach (July-2020).

Step 1

In a browser, go to https://webhook.site/ and click "Copy to clipboard" on the unique URL. Leave this page open in your browser.

Step 2

Create a new Application at https://launchpad.37signals.com/integrations. Tick the Basecamp 3 checkbox in Products. Paste the URL from step 1 into the Redirect URI.

Step 3

Go to a browser, and enter the following URL:

https://launchpad.37signals.com/authorization/new?type=web_server&client_id=<the_client_id_of_the_app_from_step_2>a&redirect_uri=<the_redirect_uri_of_the_app_from_step_2>

The browser will open a page asking you to authenticate with Basecamp. Click "Yes, I'll allow access".

Step 4

Go back to the browser page from step 1. The web hook should now show a Query String, with an 8 digit 8. Use this code in the following step.

Step 5

Start a Python3 session and enter:

>>> import requests
>>> response = requests.post("https://launchpad.37signals.com/authorization/token?type=web_server&client_id=<the_client_id_of_the_app_from_step_2>&redirect_uri=<the_redirect_uri_of_the_app_from_step_2>&client_secret=<the_client_secret_of_the_app_from_step_2>&code=<the_8_digit_code_from_step_4>")
>>> response
<Response [200]>

If you do not get a response code of 200, type  

>>> response.content 

to see the error.

In the python session, type:

 >>> response.content.decode("utf-8")

The returned string is the OAUTH2 access_token and refresh_token then your app can use to log into the Basecamp 3 API.