ScriptTag

Source

Retrieve a list of all scripttags

Source

All retrieval examples utilise the Yaspa\AdminApi\ScriptTag\ScriptTagService::getScriptTags method, which returns a Yaspa\Builders\PagedResultsIterator that will provide an iterate-able list of Yaspa\AdminApi\ScriptTag\Models\ScriptTag models.

The getScriptTags method accepts a Yaspa\AdminApi\ScriptTag\Builders\GetScriptTagsRequest instance, which is a request builder that will provide hints to what options are available assuming one is using an IDE such as PHPStorm.

Get a list of all script tags for your shop

Source

The example demonstrates how to get all script tags for your store.

The response is a Yaspa\Builders\PagedResultsIterator that will provide an iterate-able list of Yaspa\AdminApi\ScriptTag\Models\ScriptTag models.

use Yaspa\AdminApi\ScriptTag\Builders\GetScriptTagsRequest;
use Yaspa\AdminApi\ScriptTag\ScriptTagService;
use Yaspa\Authentication\Factory\ApiCredentials;
use Yaspa\Factory;

// Create request parameters
$credentials = Factory::make(ApiCredentials::class)
    ->makeOAuth('johns-apparel', 'a190000000000000000000000000046a');
$request = Factory::make(GetScriptTagsRequest::class)
    ->withCredentials($credentials);

// Get script tags
$service = Factory::make(ScriptTagService::class);
$scriptTags = $service->getScriptTags($request);

Get a list of all script tags after the specified ID

Source

The example demonstrates how to get all script tags after a provided id.

The response is a Yaspa\Builders\PagedResultsIterator that will provide an iterate-able list of Yaspa\AdminApi\ScriptTag\Models\ScriptTag models.

use Yaspa\AdminApi\ScriptTag\Builders\GetScriptTagsRequest;
use Yaspa\AdminApi\ScriptTag\ScriptTagService;
use Yaspa\Authentication\Factory\ApiCredentials;
use Yaspa\Factory;

// Create request parameters
$credentials = Factory::make(ApiCredentials::class)
    ->makeOAuth('johns-apparel', 'a190000000000000000000000000046a');
$request = Factory::make(GetScriptTagsRequest::class)
    ->withCredentials($credentials)
    ->withSinceId(668809255);

// Get script tags
$service = Factory::make(ScriptTagService::class);
$scriptTags = $service->getScriptTags($request);

Get script tags with a particular URL

Source

The example demonstrates how to get all script tags with a particular url.

The response is a Yaspa\Builders\PagedResultsIterator that will provide an iterate-able list of Yaspa\AdminApi\ScriptTag\Models\ScriptTag models.

use Yaspa\AdminApi\ScriptTag\Builders\GetScriptTagsRequest;
use Yaspa\AdminApi\ScriptTag\ScriptTagService;
use Yaspa\Authentication\Factory\ApiCredentials;
use Yaspa\Factory;

// Create request parameters
$credentials = Factory::make(ApiCredentials::class)
    ->makeOAuth('johns-apparel', 'a190000000000000000000000000046a');
$request = Factory::make(GetScriptTagsRequest::class)
    ->withCredentials($credentials)
    ->withSrc('https://js-aplenty.com/foo.js');

// Get script tags
$service = Factory::make(ScriptTagService::class);
$scriptTags = $service->getScriptTags($request);

Get a count of all script tags for your shop

Source

The example demonstrates how to get a count of script tags.

As the count endpoint accepts parameters, the request is a Yaspa\AdminApi\ScriptTag\Builders\CountScriptTagsRequest object. The object provides methods for setting available parameters such as withSrc.

The response is an integer representing the script tags count that matches the parameters provided.

use Yaspa\AdminApi\ScriptTag\Builders\CountScriptTagsRequest;
use Yaspa\AdminApi\ScriptTag\ScriptTagService;
use Yaspa\Authentication\Factory\ApiCredentials;
use Yaspa\Factory;

// Create request parameters
$credentials = Factory::make(ApiCredentials::class)
    ->makeOAuth('johns-apparel', 'a190000000000000000000000000046a');
$request = Factory::make(CountScriptTagsRequest::class)
    ->withCredentials($credentials);

// Get count
$service = Factory::make(ScriptTagService::class);
$result = $service->countScriptTags($request);

Get a single script tag by its ID

Source

The example demonstrates how to get a single script tag by its ID.

As the count endpoint accepts parameters, the request is a Yaspa\AdminApi\ScriptTag\Builders\CountScriptTagsRequest object. The object provides methods for setting available parameters such as withSrc.

The response is a Yaspa\AdminApi\ScriptTag\Models\ScriptTag model.

use Yaspa\AdminApi\ScriptTag\ScriptTagService;
use Yaspa\Authentication\Factory\ApiCredentials;
use Yaspa\Factory;

// Create request parameters
$credentials = Factory::make(ApiCredentials::class)
    ->makeOAuth('johns-apparel', 'a190000000000000000000000000046a');

// Get count
$service = Factory::make(ScriptTagService::class);
$retrievedScriptTag = $service->getScriptTagById($credentials, 596726825);

Create a new script tag

Source

Creating a new script tag involves creating and populating a Yaspa\AdminApi\ScriptTag\Models\ScriptTag instance.

The method Yaspa\AdminApi\ScriptTag\ScriptTagService::createNewScriptTag will generally return a script tag model back. Although it seems redundant, one should still use the Shopify returned script tag model as the trusted version of the created script tag given that Shopify is the source of truth.

Trying to create a script tag without a src and event will return an error

Source

The example demonstrates an invalid creation attempt.

The result is a Guzzle exception. Although it may vary depending on how the Guzzle client is configured. See Guzzle http_errors options for more information.

use Yaspa\AdminApi\ScriptTag\Models\ScriptTag;
use Yaspa\AdminApi\ScriptTag\ScriptTagService;
use Yaspa\Authentication\Factory\ApiCredentials;
use Yaspa\Factory;

// Create request parameters
$credentials = Factory::make(ApiCredentials::class)
    ->makeOAuth('johns-apparel', 'a190000000000000000000000000046a');

// Create request parameters
$scriptTag = (new ScriptTag())->setEvent('onload')
    ->setDisplayScope('online_store');

// Create new Script Tag
$service = Factory::make(ScriptTagService::class);
$service->createNewScriptTag($credentials, $scriptTag);

Create a new script tag

Source

The example demonstrates how to create a new script tag.

The response is a Yaspa\AdminApi\ScriptTag\Models\ScriptTag model.

use Yaspa\AdminApi\ScriptTag\Models\ScriptTag;
use Yaspa\AdminApi\ScriptTag\ScriptTagService;
use Yaspa\Authentication\Factory\ApiCredentials;
use Yaspa\Factory;

// Create request parameters
$credentials = Factory::make(ApiCredentials::class)
    ->makeOAuth('johns-apparel', 'a190000000000000000000000000046a');

// Create request parameters
$scriptTag = (new ScriptTag())->setEvent('onload')
    ->setEvent('onload')
    ->setSrc('https://djavaskripped.org/fancy.js');

// Create new Script Tag
$service = Factory::make(ScriptTagService::class);
$service->createNewScriptTag($credentials, $scriptTag);

Modify an existing script tag

Source

The example demonstrates how to update a script tag's URL.

The response is a Yaspa\AdminApi\ScriptTag\Models\ScriptTag model.

use Yaspa\AdminApi\ScriptTag\Builders\ModifyExistingScriptTagRequest;
use Yaspa\AdminApi\ScriptTag\Models\ScriptTag;
use Yaspa\AdminApi\ScriptTag\ScriptTagService;
use Yaspa\Authentication\Factory\ApiCredentials;
use Yaspa\Factory;

// Create request parameters
$credentials = Factory::make(ApiCredentials::class)
    ->makeOAuth('johns-apparel', 'a190000000000000000000000000046a');
$scriptTagUpdate = (new ScriptTag())
    ->setId(596726825)
    ->setSrc('https://somewhere-else.com/another.js');
$request = Factory::make(ModifyExistingScriptTagRequest::class)
    ->withCredentials($credentials)
    ->withScriptTag($scriptTagUpdate);

// Update the script tag
$service = Factory::make(ScriptTagService::class);
$updatedScriptTag = $service->modifyExistingScriptTag($request);

Remove a script tag from the database

Source

The example demonstrates how to remove an existing script tag from a shop.

The response is an empty object.

use Yaspa\AdminApi\ScriptTag\Models\ScriptTag;
use Yaspa\AdminApi\ScriptTag\ScriptTagService;
use Yaspa\Authentication\Factory\ApiCredentials;
use Yaspa\Factory;

// Create request parameters
$credentials = Factory::make(ApiCredentials::class)
    ->makeOAuth('johns-apparel', 'a190000000000000000000000000046a');

// Delete a script tag by id
$service = Factory::make(ScriptTagService::class);
$result = $service->deleteScriptTagById($credentials, 596726825);

results matching ""

    No results matching ""