Having issue with the Pot Withdraw API

I’m trying to implement something in typescript to withdraw from a pot

    const MONZO_ENDPOINT = "https://api.monzo.com/";
    const requestURL = `${MONZO_ENDPOINT}/pots/${pot.id}/withdraw`;
    var formData = new FormData();
    formData.append("destination_account_id", ACCOUNT_ID);
    formData.append("amount", "1");
    formData.append("dedupe_id", uniqueStr);
    console.log("Request URL is : ", requestURL);

    const headers2: any = {
        "Authorization": `Bearer ${ACCESS_TOKEN}`,
        "Content-Type": "application/x-www-form-urlencoded"


    const foo = await fetch(requestURL,
            headers: headers2,
            body: formData,
            method: "PUT"

but the response is a failure to parse

  code: 'bad_request',
  message: 'Error parsing request',
  params: {
    source_pot_id: 'pot_XXXXXXXXXXXXXXXX',
    user_id: 'user_XXXXXXXXXXXXXXXXXXX'
  retryable: {}

Can anyone see what I’m doing wrong here

Since you’re using TypeScript, I made a library for Node which is on npm or open source here: github.com/otters/monzo which has already implemented most API routes including withdrawing from a pot. Hopefully that can make things easier for you :slight_smile:

I checked quickly and saw the library was uing axios which unfortunately doesnt work in cloudflare’s worker environment :frowning:

1 Like

Do you have other similar requests working in cloudflare workers with typescript?

I’m not the best programmer but will the forward slash at the end of the monzo_endpoint make it .com//pots ( double forward slash) when calling that variable?

Yeah I have some other requests working (like listing pots). That works with no issue. This one gives the error for some reason. I can try without the extra / just to rule it out though

Removed the / and it didnt help. Still have the same error :frowning:

Request URL is : https://api.monzo.com/pots/pot_XXXXXXX/withdraw

still resulting in the same error

  code: 'bad_request',
  message: 'Error parsing request',
  params: {
    source_pot_id: 'pot_XXXXXXXXXX',
    user_id: 'user_XXXXXXXXXXX'
  retryable: {}

Do you have any other calls working where you move money?
Listing pots is a pretty simple command, but if you want post it anyway.

I haven’t tried any other calls to move money actually. I’ve been trying to withdraw from a pot so i’ll try depositing into a pot and see if that gives a similar error

Same error when trying to deposit into the pot.

Have you set uniqueStr here? :eyes:

yeah. I also tried hardcoding it later on

formData.append("dedupe_id", "DEDEUUUPEE");

just to make sure

Any community members familiar to help with this at all :pray:t3:

@AlanDoe i did raise internally but nobody has reached out, any other ideas or people we can nudge to assist? :crossed_fingers:t3: