BaseGQL
Handles interactions with the BigCommerce GraphQL API, including token management, making authenticated requests, and handling store-related information.
- Full name:
\BigCommerce\GraphQL\BaseGQL
Constants
| Constant | Visibility | Type | Value |
|---|---|---|---|
GQL_BASE | public | string | ’https://store-%s-%s.mybigcommerce.com/graphql' |
GQL_ACCEPT | public | string | ’application/json’ |
TOKEN_EXPIRATION | public | string | ’bigcommerce_gql_expire_at’ |
GQL_TOKEN | public | string | ’bigcommerce_gql_token’ |
GQL_IMPERSONATION_TOKEN | public | string | ’bigcommerce_gql_im_token’ |
GQL_BASE_URL | public | string | ’https://api.bigcommerce.com/stores/%s/v3/storefront/api-token' |
GQL_IMPERSONATION_URL | public | string | ’https://api.bigcommerce.com/stores/%s/v3/storefront/api-token-customer-impersonation' |
Properties
token
protected string $tokenimpersonation_token
protected string $impersonation_tokenconfig
protected \BigCommerce\Api\v3\Configuration $configMethods
__construct
Constructor.
public __construct(\BigCommerce\Api\v3\Configuration $config): mixedInitializes the BaseGQL instance with the provided configuration and retrieves the tokens.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$config | \BigCommerce\Api\v3\Configuration | The configuration object used for API requests. |
get_channel_id
Retrieves the current channel ID from the site transient or connections.
protected get_channel_id(): intReturn Value:
The channel ID.
get_token
Retrieves the current GraphQL token, requesting a new one if necessary.
protected get_token(): mixedReturn Value:
The current token.
get_impersonation_token
Retrieves the current impersonation token, requesting a new one if necessary.
protected get_impersonation_token(): mixedReturn Value:
The current impersonation token.
request_im_token
Requests a new impersonation token from the API and stores it in a transient.
protected request_im_token(): voidrequest_token
Requests a new GraphQL token from the API and stores it in a transient.
protected request_token(): voidmake_request
Makes a POST request to the GraphQL API with the provided data, headers, and URL.
public make_request(mixed $data, array $headers = [], string $url = ''): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$data | mixed | The data to send in the request body. |
$headers | array | The headers for the request. |
$url | string | The URL for the request. |
Return Value:
The parsed response data.
Throws:
If the request fails or the response is invalid.
parse_response
Parses the response from the GraphQL API.
protected parse_response(array $result): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$result | array | The raw response data. |
Return Value:
The parsed response data.
Throws:
If the response is invalid.
get_store_hash
Retrieves the store hash from the configuration host URL.
protected get_store_hash(): stringReturn Value:
The store hash.
get_endpoint_url
Retrieves the endpoint URL for the GraphQL request.
protected get_endpoint_url(): stringReturn Value:
The full GraphQL endpoint URL.
get_origin
Retrieves the origin (site URL) for the request.
protected get_origin(): stringReturn Value:
The origin URL.
get_auth_bearer
Constructs the authorization bearer string for the request.
protected get_auth_bearer(bool $impersonation = false): stringParameters:
| Parameter | Type | Description |
|---|---|---|
$impersonation | bool | Whether to use the impersonation token. |
Return Value:
The authorization header value.
validate_token
Validates whether the current token is still valid and not expired.
protected validate_token(): boolReturn Value:
Whether the token is valid.
get_headers
Constructs the headers for the GraphQL request, including authorization.
protected get_headers(bool $impersonation = false): arrayParameters:
| Parameter | Type | Description |
|---|---|---|
$impersonation | bool | Whether to use the impersonation token. |
Return Value:
The request headers.
Automatically generated on 2025-01-21