PHP code example of misisipy / php-sdk

1. Go to this page and download the library: Download misisipy/php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

misisipy / php-sdk example snippets




$code = $_GET['code'];

$auth = new Misisipy\Auth(CLIENT_ID, CLIENT_SECRET);
$access_info = $auth->request_access_token($code);

var_dump($access_info);
//array (size=5)
//  'expires_in' => int '1234' (Seconds),
//  'expiration_date_time' => int '12312311' (Unix Timestamp) 
//  'access_token' => string 'a2b544abbba560688a6ee7815926bd02dfc8d7bd784e2e016b422ebbbaa222',
//  'refresh_token' => string '560688a6ee7815926bd02dfc8d7bd784'

$auth = new Misisipy\Auth(CLIENT_ID, CLIENT_SECRET);
if($auth->is_token_expired($access_info)){
    $access_info = $auth->renew_access_token($access_info["refresh_token"]);
}
var_dump($access_info);
//array (size=5)
//  'expires_in' => int '1234' (Seconds),
//  'expiration_date_time' => int '12312311' (Unix Timestamp) 
//  'access_token' => string 'a2b544abbba560688a6ee7815926bd02dfc8d7bd784e2e016b422ebbbaa222',
//  'refresh_token' => string '560688a6ee7815926bd02dfc8d7bd784'

$auth = new Misisipy\Auth(CLIENT_ID, CLIENT_SECRET);

//You can use one of these to obtain a url to login to your app
$url = $auth->login_url(ACCOUNT_ID);


//Redirect to $url

$api = new Misisipy\API(ACCOUNT_ID, ACCESS_TOKEN, 'Awesome App ([email protected])');
$response = $api->get("products");
var_dump($response->body);

var_dump(isset($response->headers['X-Total-Count']));
//boolean true

var_dump($response->headers['X-Total-Count']);
//string '48' (length=2)

//Create a product
$response = $api->post("products", [
    'name' => 'Snowboard',
]);
$product_id = $response->body->id;

//Change its name
$response = $api->put("products/$product_id", [
    'name' => 'Snowboard',
]);

//And delete it
$response = $api->delete("products/$product_id");

//You can also send arguments to GET requests
$response = $api->get("invoices", [
    'since_id' => 10000,
]);

$response = $api->get('products');
while($response != null){
    foreach($response->body as $product){
        var_dump($product->id);
    }
    $response = $response->next();
}

try{
    $auth->request_access_token($code);
} catch(Misisipy\Auth\Exception $e){
    var_dump($e->getMessage());
    
}

try{
    $api->get('products');
} catch(Misisipy\API\Exception $e){
    var_dump($e->getMessage());
    //string 'Returned with status code 401: Invalid access token' (length=43)
    
    var_dump($e->response->body);
    //object(stdClass)[165]
    //  public 'code' => int 401
    //  public 'message' => string 'Unauthorized' (length=12)
    //  public 'description' => string 'Invalid access token' (length=20)
}