<p>Your code is close to what you need:</p>

<pre><code>&lt;?php

$guid="xxxxxxxxx";
$main_password="xxxxxxxxx";

$json_url = "https://blockchain.info/merchant/$guid/balance?password=$main_password";

$json_data = file_get_contents($json_url);

$json_feed = json_decode($json_data);

$balance = $json_feed-&gt;balance;

echo $balance;
?&gt;
</code></pre>

<p>The response looks like this (Wallet Balance in Satoshi):</p>

<pre><code>{ "balance": 1000}
</code></pre>

<p>So you need to fetch the balance object not the message one.
Then add an echo to print out the balance.</p>

CC BY-SA 3.0
2014-07-18T19:24:04.727Z
balance; echo $balance; ?> this is the result I got. Don't know why.
rahulgarg12342
CC BY-SA 3.0
2014-07-18T19:27:25.773Z
just tested it with my own wallet it worked perfectly fine, maybe your put in the wrong credentials
Dennis Kriechel
CC BY-SA 3.0
2014-07-18T19:28:11.040Z
is the guid the wallet identifier?
rahulgarg12342
CC BY-SA 3.0
2014-07-18T19:28:19.453Z
yes its is, maybe you missed out a semicolon or an php tag, seems like an syntax error in your php maybe try to copy paste again
Dennis Kriechel
CC BY-SA 3.0
2014-07-18T19:34:01.960Z
ahh got it. The 2 factor auth was messing it up. Figured it out. Thanks. Just a little curious. How could I modify this to be performed after a certain time interval?
rahulgarg12342
CC BY-SA 3.0
2014-09-04T08:23:38.940Z
@rahulgarg12342 How did you bypass the 2 factor authenticator?
I am using the block chain api to do exactly the same thing, it is working but for 2 factor authenticator enabled wallets I am getting the error. How do I deal with that?
Criesto
CC BY-SA 3.0
2014-07-18T19:19:18.450Z
2014-07-18T19:19:18.450Z
Dennis Kriechel
<p>I am a complete noob to PHP. But I just wanted to know how can you use the BlockChain API to get your wallet balance. I tried but could get no result. I do not even know how to print it. Please help. This is my current code :-</p>

<pre><code>    &lt;?php

    $guid="xxxxxxxxx";
    $main_password="xxxxxxxxx";

    $json_url = "https://blockchain.info/merchant/$guid/balance?password=$main_password";

    $json_data = file_get_contents($json_url);

    $json_feed = json_decode($json_data);

    $message = $json_feed-&gt;message;

    ?&gt;
</code></pre>

<p>And what exactly is the guid? Is it the wallet identifier?</p>

<blockchain.info><php>
How to use BlockChain API?
rahulgarg12342
# How to use BlockChain API?

(Asked by: username_0 on 2014-07-18)

I am a complete noob to PHP. But I just wanted to know how can you use the BlockChain API to get your wallet balance. I tried but could get no result. I do not even know how to print it. Please help. This is my current code :-

```
    <?php

    $guid="xxxxxxxxx";
    $main_password="xxxxxxxxx";

    $json_url = "https://blockchain.info/merchant/$guid/balance?password=$main_password";

    $json_data = file_get_contents($json_url);

    $json_feed = json_decode($json_data);

    $message = $json_feed->message;

    ?>

```

And what exactly is the guid? Is it the wallet identifier?

**Tags:** blockchain.info, php


---

## 1 answers

### Answer by username_1 on 2014-07-18. Score: 4 | Accepted answer

Your code is close to what you need:

```
<?php

$guid="xxxxxxxxx";
$main_password="xxxxxxxxx";

$json_url = "https://blockchain.info/merchant/$guid/balance?password=$main_password";

$json_data = file_get_contents($json_url);

$json_feed = json_decode($json_data);

$balance = $json_feed->balance;

echo $balance;
?>

```

The response looks like this (Wallet Balance in Satoshi):

```
{ "balance": 1000}

```

So you need to fetch the balance object not the message one.
Then add an echo to print out the balance.

> **Comments:**
> **username_0**: balance; echo $balance; ?> this is the result I got. Don't know why.  
> **username_1**: just tested it with my own wallet it worked perfectly fine, maybe your put in the wrong credentials  
> **username_0**: is the guid the wallet identifier?  
> **username_1**: yes its is, maybe you missed out a semicolon or an php tag, seems like an syntax error in your php maybe try to copy paste again  
> **username_0**: ahh got it. The 2 factor auth was messing it up. Figured it out. Thanks. Just a little curious. How could I modify this to be performed after a certain time interval?  
> **username_2**: @username_0 How did you bypass the 2 factor authenticator? I am using the block chain api to do exactly the same thing, it is working but for 2 factor authenticator enabled wallets I am getting the error. How do I deal with that?  

---

