<p>The first one is correct.<br>
<a href="https://blockchain.info/tobtc?api_code=000my0-api00-code-0000-000000000&amp;currency=USD&amp;value=1" rel="nofollow">https://blockchain.info/tobtc?api_code=000my0-api00-code-0000-000000000&amp;currency=USD&amp;value=1</a></p>

<p>However, the particular call you are using (/tobtc) is public and thus needs no api_code attached.</p>

<p><a href="https://blockchain.info/tobtc?currency=USD&amp;value=1" rel="nofollow">https://blockchain.info/tobtc?currency=USD&amp;value=1</a></p>

CC BY-SA 3.0
2014-10-06T22:47:48.047Z
2014-10-10T13:16:45.000Z
2014-10-10T13:16:45.000Z
siliconsys
<p>You should always use api code, even if it's not required. Otherwise if you generate too much traffic, block chain will ban your ip for a day. You will not be able to use web wallet.</p>

CC BY-SA 3.0
2016-03-02T00:04:39.183Z
2016-03-02T00:04:39.183Z
Pavel Niedoba
<pre><code>function convert_amount_to_btc($currency_from,$amount,$api_code) {

    $url = "https://blockchain.info/tobtc?api_code=".$api_code."&amp;currency=".$currency_from."&amp;value=".$amount;
    try 
    {
        $ch = curl_init();
        curl_setopt ($ch, CURLOPT_URL, $url);
        curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)");
        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 20);
        curl_setopt ($ch, CURLOPT_TIMEOUT, 20);
        $rawdata = curl_exec($ch);
        curl_close($ch);
        if(is_numeric($rawdata)){
            return array('status' =&gt; TRUE,'response' =&gt; $rawdata);
        }else{
            return array('status' =&gt; FALSE,'response' =&gt; $rawdata);
        }
    } 
    catch (Exception $e){
        return array('status' =&gt; FALSE,'response' =&gt; $e-&gt;Message());
    }
}

$app_api_key = "your-blockchain-api-key";//Your Own APIKey received from Blockchain

//BELOW AMOUNT IS CONVERTED FROM USD TO BTC 
$app_currency = "USD"; //App Local Currency - please always refer to the blockain docs for supported currencies

$usd_amount = "28";//USD
$convert = convert_amount_to_btc($app_currency,$usd_amount,$app_api_key);
//the response from convert can either be TRUE/FALSE | 
// $convert['status'] (True means the amount was converted, False meaning there was an error/issue 'reason like not a supported currency or your call server IP being blocked') 
// $convert['response'] - carries amount convert - on error carries blockchain call reponse message
if((bool)$convert['status']){
    $amount = $convert['response'];//Amount converted from fiat currency to BTC
}else{
    //here for error purposes it up to your App what to do
    //your can display a message or ask the user to try again
}
</code></pre>

CC BY-SA 3.0
2017-09-17T10:30:30.147Z
I hope this function and usability above helps a few people, converting from the local currency to bitcoin
gabisajr
CC BY-SA 3.0
2017-09-17T10:29:32.817Z
2017-09-17T10:29:32.817Z
gabisajr
<p>I make a JSON call to</p>

<p><a href="https://blockchain.info/tobtc?currency=USD&amp;value=1" rel="nofollow">https://blockchain.info/tobtc?currency=USD&amp;value=1</a></p>

<p>This is a free api with a request limit.</p>

<p>I have just received my api_code via email. This is blockchain.info's example of how to use it</p>

<blockquote>
  <p>Once approved the API Code can be passed to all requests in the "api_code" parameter e.g. <a href="https://blockchain.info?api_code=" rel="nofollow">https://blockchain.info?api_code=</a>$your_code</p>
</blockquote>

<p>I am guessing that they mean with PHP (because of the dollar sign) as when I type into my address bar</p>

<pre><code>https://blockchain.info/tobtc?api_code=000my0-api00-code-0000-000000000&amp;currency=USD&amp;value=1
</code></pre>

<p>The data does not any look different when I use the api code with the dollar</p>

<pre><code>https://blockchain.info/tobtc?api_code=$000my0-api00-code-0000-000000000&amp;currency=USD&amp;value=1
</code></pre>

<p>Though I am unsure of how to tell what is the correct way as I can access this free api with and without an api code (with a request limit). How do I tell if I am adding it correctly?</p>

<blockchain.info>
using blockchain.info api_code
Ben Muircroft
# using blockchain.info api_code

(Asked by: username_0 on 2014-10-05)

I make a JSON call to

<https://blockchain.info/tobtc?currency=USD&value=1>

This is a free api with a request limit.

I have just received my api\_code via email. This is blockchain.info's example of how to use it

> Once approved the API Code can be passed to all requests in the "api\_code" parameter e.g. <https://blockchain.info?api_code=>$your\_code

I am guessing that they mean with PHP (because of the dollar sign) as when I type into my address bar

```
https://blockchain.info/tobtc?api_code=000my0-api00-code-0000-000000000&currency=USD&value=1

```

The data does not any look different when I use the api code with the dollar

```
https://blockchain.info/tobtc?api_code=$000my0-api00-code-0000-000000000&currency=USD&value=1

```

Though I am unsure of how to tell what is the correct way as I can access this free api with and without an api code (with a request limit). How do I tell if I am adding it correctly?

**Tags:** blockchain.info


---

## 3 answers

### Answer by username_1 on 2014-10-06. Score: 2

The first one is correct.  
<https://blockchain.info/tobtc?api_code=000my0-api00-code-0000-000000000&currency=USD&value=1>

However, the particular call you are using (/tobtc) is public and thus needs no api\_code attached.

<https://blockchain.info/tobtc?currency=USD&value=1>


---

### Answer by username_2 on 2016-03-02. Score: 0

You should always use api code, even if it's not required. Otherwise if you generate too much traffic, block chain will ban your ip for a day. You will not be able to use web wallet.


---

### Answer by username_3 on 2017-09-17. Score: 0

```
function convert_amount_to_btc($currency_from,$amount,$api_code) {

    $url = "https://blockchain.info/tobtc?api_code=".$api_code."&currency=".$currency_from."&value=".$amount;
    try 
    {
        $ch = curl_init();
        curl_setopt ($ch, CURLOPT_URL, $url);
        curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)");
        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 20);
        curl_setopt ($ch, CURLOPT_TIMEOUT, 20);
        $rawdata = curl_exec($ch);
        curl_close($ch);
        if(is_numeric($rawdata)){
            return array('status' => TRUE,'response' => $rawdata);
        }else{
            return array('status' => FALSE,'response' => $rawdata);
        }
    } 
    catch (Exception $e){
        return array('status' => FALSE,'response' => $e->Message());
    }
}

$app_api_key = "your-blockchain-api-key";//Your Own APIKey received from Blockchain

//BELOW AMOUNT IS CONVERTED FROM USD TO BTC 
$app_currency = "USD"; //App Local Currency - please always refer to the blockain docs for supported currencies

$usd_amount = "28";//USD
$convert = convert_amount_to_btc($app_currency,$usd_amount,$app_api_key);
//the response from convert can either be TRUE/FALSE | 
// $convert['status'] (True means the amount was converted, False meaning there was an error/issue 'reason like not a supported currency or your call server IP being blocked') 
// $convert['response'] - carries amount convert - on error carries blockchain call reponse message
if((bool)$convert['status']){
    $amount = $convert['response'];//Amount converted from fiat currency to BTC
}else{
    //here for error purposes it up to your App what to do
    //your can display a message or ask the user to try again
}

```

> **Comments:**
> **username_3**: I hope this function and usability above helps a few people, converting from the local currency to bitcoin  

---

