Private authentication

Source

Generate credentials from the Shopify admin

Source

Private authentication details are utilised by Yaspa with a model.

A factory enables creating them with a single line. However, construction can be done manually if desired.

The example shows making a private key for the store https://johns-apparel.myshopify.com

use Yaspa\Authentication\Factory\ApiCredentials;
use Yaspa\Factory;

$credentials = Factory::make(ApiCredentials::class)
    ->makePrivate(
        'johns-apparel',
        '4478eb7ac138a136852babd861956c19',
        '3e5a6edec71eab039422c6444d02659d'
    );

Perform authenticated requests

Source

Requests in Yaspa are performed by one of two methods. Either directly through a service class method call, or by using a request builder.

The general rule is, if a method call has more than 3 parameters, then a request builder will be used, otherwise all needed data can be passed into the method.

Perform authenticated requests using a service method

The following example demonstrates a simple API call that does not need a request builder.

The API call gets a customer with id 6820000675.

use Yaspa\AdminApi\Customer\CustomerService;
use Yaspa\Factory;

$service = Factory::make(CustomerService::class);
$retrievedCustomer = $service->getCustomer($credentials, 6820000675); // Credentials are set here

Perform authenticated requests using a request builder

The following example demonstrates a more complex API call that utilises a request builder.

The API call involves search for customers with the query "steve" and wanting the Shopify API to only return customer fields "id", "email", and "first_name".

use Yaspa\AdminApi\Customer\Builders\CustomerFields;
use Yaspa\AdminApi\Customer\Builders\SearchCustomersRequest;
use Yaspa\AdminApi\Customer\CustomerService;
use Yaspa\Factory;

$fields = Factory::make(CustomerFields::class)
    ->withId()
    ->withEmail()
    ->withFirstName();
$request = Factory::make(SearchCustomersRequest::class)
    ->withCredentials($credentials) // Credentials are set here
    ->withCustomerFields($fields)
    ->withQuery('steve');

$service = Factory::make(CustomerService::class);
$customers = $service->searchCustomers($request);

results matching ""

    No results matching ""