I'm not clear on how to form headers to list transactions

My code is in Python but you should be able to follow it regardless of which language you use.

I have successfully authenticated my user via OAuth and I can now successfully query the Who Am I API using the following command:

    url = 'https://api.monzo.com/ping/whoami'
    headers = {
    "Authorization": "Bearer "+user.access_token,
    }
    r = requests.get(url, headers=headers)

I’m now trying to query the List Transactions api. But I don’t understand how exactly I should form the header to pass the account_id. This is what the Monzo documentation says:

http "https://api.monzo.com/transactions" \
"Authorization: Bearer $access_token" \
"account_id==$account_id"

This is what I’ve tried:

url = 'https://api.monzo.com/transactions'
headers = {
"Authorization": "Bearer "+user.access_token,
"account_id": account.monzo_account,
}
r = requests.get(url, headers=headers)

Looking at the Monzo documentation, the account_id header is formed differently. Notice the == sign instead of the colon below. What does this mean?

http "https://api.monzo.com/transactions" \
"Authorization: Bearer $access_token" \
"account_id==$account_id"

I’ve not tried it, but the documentation you’re referring to suggests they use https://github.com/httpie/httpie in the examples. It looks like that means that the account_id variable above should be a request parameter, rather than a header.

Ah yes of course you’re right, it should be a get parameter. Will try that tonight.

That worked, so rookie mistake, I put the account ID in the headers instead of the URL.

1 Like