API: Deposit into pot - PUT

Hi.

I’m trying to do a PUT request to transfer money from my main account into a POT.

This is all I can get in response - regardless of what I try.

{“code”:“bad_request.bad_param.amount”,“message”:“must be greater than 0”}

Has anyone had any luck with this; wonder if I’m missing something. But as far as I can see I’m transferring all the correct variables in the request body etc.

This is the body (i’ve changed the source account id for security reasons).

‘[‘amount’=>‘11’,‘source_account_id’=>‘acc_0000xxxxxxxxxxxxxx’, ‘dedupe_id’=>‘112’];’

Thanks!

I wonder if it’s an issue with transfers below £1 with the API? Have you tried a value greater than 11p?

You are providing amount as a string, try removing the quotes. Amount is a 64bit integer.

1 Like

Yep - tried that. Still nothing!

Just tried to transfer 111 (i.e. 1.11) and that’s not working neither.

I’m transferring my authorization key as a header, and the params in the body. But I’ve tried to also pass the params in the header and that’s not working either.

I’ve also just posted some source-code on Slack.

{POTID} and {ACCOUNTID} removed below.

    <?php

$url = 'https://api.monzo.com/pots/{POTID}/deposit';
$data = ['amount'=>11,'source_account_id'=>'{ACCOUNTID}', 'dedupe_id'=>'112'];
$data_json = json_encode($data);

echo $data_json;

$post_data = $data;

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_PUT, 1);

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
	'Authorization: Bearer ' . $token));

curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

$output = curl_exec($ch);

curl_close($ch);
?>

I’ve just tried this and it works fine for me. What if you just send the raw data:

source_account_id=acc_000etc&amount=11&dedupe_id=121

?

Same story…

Really doesn’t make sense at all…

Full _REQUEST dump: {"code":"bad_request.bad_param.amount","message":"must be greater than 0"}

Ah, you’re using cURL. You need to convert the POST data into a string and send that in CURLOPT_POSTFIELDS.

To your code add:

$data_string = http_build_query($data, '', '&');

and change CURLOPT_POSTFIELDS to:

curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);

Edit: I’ve tested this and it works. See https://pastebin.com/F9afYrUH

2 Likes

Absolute hero. Knew it would be something simple.

Thanks so much :slight_smile:

Glad you got it sorted, happy coding! :slightly_smiling_face:

Consider using a sane HTTP client library which will do all this request body encoding automatically for you in the future. :wink:

2 Likes

Certainly this for anything serious/production.

1 Like