API: Deposit into pot - PUT


(Mark McWhirter) #1

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!


#2

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.


(Mark McWhirter) #3

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.


(Mark McWhirter) #4

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);
?>

#5

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

?


(Mark McWhirter) #6

Same story…

Really doesn’t make sense at all…

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

#7

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


(Mark McWhirter) #8

Absolute hero. Knew it would be something simple.

Thanks so much :slight_smile:


#9

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


#10

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


#11

Certainly this for anything serious/production.