A simple example of how to get orders, from the shopify-api-php?

doug3
Shopify Partner
8 0 1

I've rolled my own api stuff, I can get orders, fulfill orders, etc etc.  Is there a simple example of what I'd need to do, to get an order, with the api library? Or other function, like get a product, etc?  THe docs at git hub are useless.  I dont see why they have to be so opaque.

include 'the_api.php'
$api = new ApiClass;
$api->init(['apikey'=>'asdfasdf','apipassword'=>'987asdf987']);
$orders = $api->getOrders(['min_date' => '2023-01-01']);

is something like I would expect.

Reply 1 (1)

mikerowave
Shopify Staff (Retired)
22 3 2

Hi @doug3!

The docs for the php library in Github have an example that looks almost identical to your pseudocode for the REST flavor:

use Shopify\Clients\Rest;

$client = new Rest($session->getShop(), $session->getAccessToken());
$response = $client->get('products');

 
And another simple example in the GraphQL usage doc:

// Load current session to get `accessToken`
$session = Shopify\Utils::loadCurrentSession($headers, $cookies, $isOnline);
// Create GraphQL client
$client = new Shopify\Clients\Graphql($session->getShop(), $session->getAccessToken());
// Use `query` method and pass your query as `data`
$queryString = <<<QUERY
    {
        products (first: 10) {
            edges {
                node {
                    id
                    title
                    descriptionHtml
                }
            }
        }
    }
QUERY;
$response = $client->query($queryString);

// do something with the returned data

 

If something there seems unclear, we recommend opening an issue on the Github repo itself. The developers of the library maintain it themselves and that is the best place to advocate for yourself and request changes. 

Mike M (mikerowave) | API Support @ Shopify 
 - Was my reply helpful? Click Like to let me know!
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit shopify.dev or the Shopify Web Design and Development Blog