Query the Mercury Bank API

Quadratic sample sheet: https://app.quadratichq.com/file/305e49d1-bd36-4b8f-b0d6-1eadf602a80b

Mercury Bank API docs: https://docs.mercury.com/reference/welcome-to-mercury-api

To get started, view your transaction history directly with the following code (note: this is a sandbox example, follow the docs if you'd like to set this up in production).

import requests
import pandas as pd
from datetime import datetime

# Sandbox token - create your own 
mercury_token = "<your_token_here>"

# Make the API request
response = requests.get(
  "https://proxy.cors.sh/https://api-sandbox.mercury.com/api/v1/account/<account_here>c/transactions?limit=5000&offset=0&start=2020-01-01",
    headers = {
        'x-cors-api-key': 'temp_2ed7d641dd52613591687200e7f7958b',
        "Content-type":"application/json", 
        "Authorization": "Bearer {}".format(mercury_token)
	}
)

# Fix type and put it into a DataFrame 
response = response.json()['transactions']
df = pd.DataFrame(response)

# Filter for the columns we want and prettify 
output_df = df[['amount', 'counterpartyName', 'createdAt', 'status']]
output_df = output_df.rename(columns={"amount": "Amount", "counterpartyName": "Counterparty", "createdAt": "Date", "status": "Status"})
output_df['Date']=pd.to_datetime(output_df['Date']).dt.strftime('%Y-%m-%d')

# Output to the sheet 
output_df

Need help making this connection? Feel free to reach out to support@quadratichq.com for help.

Quadratic logo

The infinite canvas spreadsheet with code.

Try it now