Skip to content
This repository has been archived by the owner on Oct 24, 2020. It is now read-only.

Making First Call

Jose Celano edited this page May 5, 2015 · 10 revisions

Once you have completed the Installation, we could make the first call. To write an app that uses the SDK, we will create our first PHP script that will store a Credit Card in our Vault.

Instructions

First, Create file first.php in our project root location. You could alternatively copy the completed file here: first.php

  1. Autoload the SDK Package. This will include all the files and classes to your autoloader. Please note, If your downloaded our SDK using composer, replace php-client with vendor. This applies for all sample code in our SDK.

// 1. Autoload the SDK Package. This will include all the files and classes to your autoloader require DIR . '/php-client/autoload.php';


2. Provide the Token. Optionally, Replace the given one with [[your own Token | https://accounts.blockcypher.com/dashboard]]
    ```php
// After Step 1
$token = 'c0afcccdde5081d6429de37d16166ead';
$apiContext = new \BlockCypher\Rest\ApiContext(new \BlockCypher\Auth\SimpleTokenCredential($token));
  1. Lets try to create a webhook using WebHook API mentioned here

// After Step 2 $webHook = new \BlockCypher\Api\WebHook(); $webHook->setUrl("https://requestb.in/slmm49sl?uniqid=" . uniqid()); $webHook->setEvent('unconfirmed-tx');


4. Make a Create Call and Print the Card
    ```php
// After Step 3
try {
        $webHook->create($apiContext);
        echo $webHook;
}
catch (\BlockCypher\Exception\BlockCypherConnectionException $ex) {
        // This will print the detailed information on the exception. 
        //REALLY HELPFUL FOR DEBUGGING
        echo $ex->getData();
}

    ```

5. Run `php -f first.php` from command line. This will successfully create a webhook. The output would look similar to this:
    ```sh
> php -f first.php
{
    "url": "https://requestb.in/slmm49sl?uniqid=554790ee32b4d",
    "event": "unconfirmed-tx",
    "id": "34784394-bbaa-4303-bd3c-b5773e7d6ca8",
    "token": "c0afcccdde5081d6429de37d16166ead",
    "callback_errors": 0,
    "filter": "event=unconfirmed-tx"
}
    ```

##### NOTE

* To reduce redundant code and minimize security risks, you could create a file `bootstrap.php` and move step 1 and 2 there, and just `include` bootstrap.php.
* All the calls made currently are defaulted to sandbox environment. Sandbox Environment replicates the exact behavior you get from our BlockCypher APIs, but here, it allows you to create dummy accounts and test your integration, before running your code on live BlockCypher APIs. For more information visit [[ Developer Portal | https://dev.blockcypher.com ]]

## Next Step

* [[ Adding Configurations | Adding-Configurations ]]