PHP code example of shopifychamp / shopify-api-php-sdk

1. Go to this page and download the library: Download shopifychamp/shopify-api-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/ */

    

shopifychamp / shopify-api-php-sdk example snippets


$ composer 

     
    y\PrivateApp;
    
    $api_params['version'] = '2019-10';
    $client = new Shopify\PrivateApp($shop, $api_key, $password, $api_params);
    
    
     
    plicApp;
    
    $api_params['version'] = '2019-10';
    $client = new Shopify\PublicApp($shop, $api_key, $api_secret_key, $api_params);
    

    if(isset($_GET['code']))
    {
        //get access_token after authorization of public app
        if($access_token = $client->getAccessToken($_GET)){
            //set access_token for api call
            $client->setAccessToken($access_token);
            $response = $client->call('GET','products',['limit'=>250]);
        }
    }else{
        //$redirect_uri (mention in App URL in your public app)
        $redirect_url= isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on"?'https://':'http://';
        if ($_SERVER["SERVER_PORT"] != "80") {
            $redirect_url .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
        } else {
            $redirect_url .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
        }

        header('Location: '.urldecode($client->prepareAuthorizeUrl($redirect_url)));
    }
    

    $response = $client->call('GET','products',['limit'=>250]);
    print_r($response);
    

    $response = $client->call('GET','products',['limit'=>250]);
    

    if($client->hasPrevPage())
    {
        $prev_page_response = $client->call('GET','products',['limit'=>20,'page_info'=>$client->getPrevPage()]);
        print_r($prev_page_response);
    }
    

    $response = $client->callGraphql($graphqlString);
    

     
    use rdx\graphqlquery\Query;
    
    $query = Query::mutation();
    $query->fields('customerCreate');
    $query->customerCreate->attribute('input',['firstName'=>'John','lastName'=> "Tate", 'email'=> "[email protected]"]);
    $query->customerCreate->field('customer');
    $query->customerCreate->customer->field('id');
    $graphqlString = $query->build();
    

    $response = $client->callGraphql($graphqlString);
    

    $response = $client->callGraphql($graphqlString);
    
    

    if(isset($response['data']['products']['edges']) && $last_array = end($response['data']['products']['edges']))
    {
        if(isset($last_array['cursor']))
        {
            //assign cursor value in `last` attribute
            $query = $reserve_query->products->attribute('after', $last_array['cursor']);
            $graphqlString = $reserve_query->build();
            $next_response = $client->callGraphql($graphqlString);
            print_r($next_response);
        }
    }
    

    try
    {
        $client = new Shopify\PrivateApp($shop, $api_key, $password, $api_params);
        $response = $client->call('GET','products',['limit'=>20]);
        print_r($response);
    }
    catch (\Shopify\Exception\ApiException $e)
    {
        echo "Errors: ".$e->getError().'<br> status code: '.$e->getCode();
    }