Shopify SDK for Unity
Public Member Functions | Static Public Attributes | Properties | List of all members
Shopify.Unity.ShopifyClient Class Reference

ShopifyClient is the entry point to communicate with the Shopify Storefront API. ShopifyClient also has functionality to easily generate and send queries to receive information about products, collections, and has the ability to create checkouts. More...

Public Member Functions

 ShopifyClient (string accessToken, string domain, string locale=null)
 ShopifyClient is the entry point to communicate with the Shopify Storefront API. ShopifyClient also has functionality to easily generate and send queries to receive information about products and collections. It also has the ability to create checkouts. More...
 
 ShopifyClient (BaseLoader loader)
 It is possible to instantiate a ShopifyClient by passing an instance that implements BaseLoader . BaseLoaders handle network communication with the Storefront API. This functionality is useful if you'd like to use the Shopify SDK for Unity in a C# environment outside of Unity. The domain string is inferred from BaseLoaders which can be used to request a specific client. More...
 
void UpdateLocale (string locale)
 Overwrites the QueryLoader instance with a new one with the specified locale. More...
 
void products (ProductsPaginatedHandler callback, int? first=null, string after=null)
 Generates a query to receive one page of products from a Shopify store. The generated query will query the following on products: More...
 
void products (ProductsHandler callback, string firstProductId, params string[] otherProductIds)
 Generates a query to receive selected products from a Shopify store. The generated query will query the following on products: More...
 
void products (ProductsHandler callback, List< string > productIds)
 Generates a query to receive selected products from a Shopify store. The generated query will query the following on products: More...
 
void collections (CollectionsPaginatedHandler callback, int? first=null, string after=null)
 Generates a query to receive a page of collections from a Shopify store. The generated query will query the following on collections: More...
 
void collections (CollectionsHandler callback, string firstCollectionId, params string[] otherCollectionIds)
 Generates a query to receive selected collections from a Shopify store. The generated query will query the following on collections: More...
 
void collections (CollectionsHandler callback, List< string > collectionIds)
 Generates a query to fetch the specified collections by id from a Shopify store. The generated query will query the following on collections: More...
 
void Query (QueryRootQuery query, QueryRootHandler callback)
 Allows you to send custom GraphQL queries to the Storefront API. While having utility functions like products collections is useful, the Storefront API has more functionality. This method allows you to access all the extra functionality that the Storefront API provides. More...
 
void Query (QueryRootDelegate buildQuery, QueryRootHandler callback)
 Allows you to build and send custom GraphQL queries to the Storefront API. While having utility functions like products collections is useful, the Storefront API has more functionality. This method allows you to access all the extra functionality that the Storefront API provides. More...
 
void Mutation (MutationQuery query, MutationRootHandler callback)
 Allows you to continuously make a root query, till the response is deemed ready. More...
 
void Mutation (MutationDelegate buildQuery, MutationRootHandler callback)
 Allows you to build and send custom GraphQL mutation queries to the Storefront API. More...
 
Cart Cart (string cartId=null)
 Creates a Cart , which can be used to manage line items for an order and create a web checkout link. One client can have multiple carts, so it's possible to pass in a cartId to reference a specific cart. If no cartId is passed, then a default Cart is used. More...
 

Static Public Attributes

static Dictionary< string, int > DefaultImageResolutions
 This is a dictionary that defines aliases, maxWidth, and maxHeight for images loaded by products and collections . All Products images, Product variant images, and Collection images will be queried using aliases defined by this dictionary's keys and the maxWidth and maxHeight will be this dictionary's values. More...
 

Properties

string AccessToken [get]
 AccessToken is the access token associated with this client to query Shopify. More...
 
string Domain [get]
 Domain is the Shopify store domain associated with this client. More...
 
string Locale [get]
 Locale is the language that supported translated content will be in. More...
 

Detailed Description

ShopifyClient is the entry point to communicate with the Shopify Storefront API. ShopifyClient also has functionality to easily generate and send queries to receive information about products, collections, and has the ability to create checkouts.

Constructor & Destructor Documentation

◆ ShopifyClient() [1/2]

Shopify.Unity.ShopifyClient.ShopifyClient ( string  accessToken,
string  domain,
string  locale = null 
)
inline

ShopifyClient is the entry point to communicate with the Shopify Storefront API. ShopifyClient also has functionality to easily generate and send queries to receive information about products and collections. It also has the ability to create checkouts.

Parameters
accessTokenthe access token used to query the Shopify Storefront API for a store
domaindomain for the Shopify store
// Example that initializes a new ShopifyClient which will query all products
string accessToken = "b8d417759a62f7b342f3735dbe86b322";
string shopDomain = "unity-buy-sdk.myshopify.com";
ShopifyClient client = new ShopifyClient(accessToken, shopDomain);
client.products((products, error) => {
Debug.Log(products[0].title());
Debug.Log(products[1].title());
});
void products(ProductsPaginatedHandler callback, int? first=null, string after=null)
Generates a query to receive one page of products from a Shopify store. The generated query will quer...
Definition: ShopifyBuy.cs:308
ShopifyClient(string accessToken, string domain, string locale=null)
ShopifyClient is the entry point to communicate with the Shopify Storefront API. ShopifyClient also h...
Definition: ShopifyBuy.cs:206

◆ ShopifyClient() [2/2]

Shopify.Unity.ShopifyClient.ShopifyClient ( BaseLoader  loader)
inline

It is possible to instantiate a ShopifyClient by passing an instance that implements BaseLoader . BaseLoaders handle network communication with the Storefront API. This functionality is useful if you'd like to use the Shopify SDK for Unity in a C# environment outside of Unity. The domain string is inferred from BaseLoaders which can be used to request a specific client.

Parameters
loadera loader which will handle network communication with the Storefront API
// Example that initializes a new ShopifyClient using a custom loader for another C# platform
string accessToken = "b8d417759a62f7b342f3735dbe86b322";
string shopDomain = "unity-buy-sdk.myshopify.com";
CustomLoaderForNonUnityPlatform loader = new CustomLoaderForNonUnityPlatform(accessToken, shopDomain);
ShopifyClient client = new ShopifyClient(loader);
client.products((products, error) => {
Debug.Log(products[0].title());
Debug.Log(products[1].title());
});

Member Function Documentation

◆ Cart()

Cart Shopify.Unity.ShopifyClient.Cart ( string  cartId = null)
inline

Creates a Cart , which can be used to manage line items for an order and create a web checkout link. One client can have multiple carts, so it's possible to pass in a cartId to reference a specific cart. If no cartId is passed, then a default Cart is used.

Parameters
cartIdcan be optionally passed in. This is useful if your application needs multiple carts
// Example that checks how many line items the cart contains
Cart cart = ShopifyBuy.Client().Cart();
Debug.Log("The cart has " + cart.LineItems.All().Count + " line items");
Cart Cart(string cartId=null)
Creates a Cart , which can be used to manage line items for an order and create a web checkout link....
Definition: ShopifyBuy.cs:828

◆ collections() [1/3]

void Shopify.Unity.ShopifyClient.collections ( CollectionsHandler  callback,
List< string >  collectionIds 
)
inline

Generates a query to fetch the specified collections by id from a Shopify store. The generated query will query the following on collections:

  • id
  • title
  • description
  • descriptionHtml
  • updatedAt
  • image
    • altText
    • src
  • products
    • id
Parameters
callbackcallback that will receive responses from server
collectionIdsthe list of collection ids you want to receive from the server
// Example usage querying two collection ids using a List<string>
List<string> collectionIds = new List<string>() {
"Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzk4OTUyNzYwOTk=",
"Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzk4OTUyNzkwNDM="
};
ShopifyBuy.Client().collections((collections, error) => {
Debug.Log(collections[0].title());
Debug.Log(collections[1].title());
}, collectionIds);
void collections(CollectionsPaginatedHandler callback, int? first=null, string after=null)
Generates a query to receive a page of collections from a Shopify store. The generated query will que...
Definition: ShopifyBuy.cs:480

◆ collections() [2/3]

void Shopify.Unity.ShopifyClient.collections ( CollectionsHandler  callback,
string  firstCollectionId,
params string[]  otherCollectionIds 
)
inline

Generates a query to receive selected collections from a Shopify store. The generated query will query the following on collections:

  • id
  • title
  • description
  • descriptionHtml
  • updatedAt
  • image
    • altText
    • src
  • products
    • id
Parameters
callbackcallback that will receive responses or errors from server
firstCollectionIdyou must pass in at least one collection id to query
otherCollectionIdsafter the first collection id you can pass in as many collection ids as you'd like.
// Example usage querying two collection ids using a List<string>
ShopifyBuy.Client().collections((collections, error) => {
Debug.Log(collections[0].title());
Debug.Log(collections[1].title());
}, "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzk4OTUyNzYwOTk=", "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzk4OTUyNzkwNDM=");

◆ collections() [3/3]

void Shopify.Unity.ShopifyClient.collections ( CollectionsPaginatedHandler  callback,
int?  first = null,
string  after = null 
)
inline

Generates a query to receive a page of collections from a Shopify store. The generated query will query the following on collections:

  • id
  • title
  • description
  • descriptionHtml
  • updatedAt
  • image
    • altText
    • src
  • products
    • id

Note that shop.collections is a Connection (GraphQL paginated data structure). collections

Parameters
callbackcallback that will receive responses from server
firstcan be used to limit how many products are returned. For instance 10 would return only 10 collections
afteris used to load subsequent pages. Basically it's a cursor variable to define what page to load next. For example, when used with first: 10 and after: "abc", only the first 10 collections would be loaded after cursor "abc". If no after is passed the first page of collections will be loaded.
// Example that queries all collections on a shop
ShopifyBuy.Client().collections((collections, error) => {
Debug.Log(collections[0].title());
Debug.Log(collections.Count);
});

◆ Mutation() [1/2]

void Shopify.Unity.ShopifyClient.Mutation ( MutationDelegate  buildQuery,
MutationRootHandler  callback 
)
inline

Allows you to build and send custom GraphQL mutation queries to the Storefront API.

Parameters
buildQuerydelegate that will build a query starting at MutationQuery
callbackcallback which will receive a response
// Example that creates a new customer on a store
ShopifyBuy.Client().Mutation(
buildQuery: (mutation) => { mutation
.customerCreate(
buildQuery: (cc) => { cc
.userErrors(
buildQuery: (ue) => { ue
.field()
.message();
}
);
},
input: new CustomerCreateInput(
email: "mikkoh@email.com",
password: "oh so secret"
)
);
},
callback: (data, error) => {
if (error != null) {
Debug.Log("There was an error: " + error.Reason);
} else {
List<UserError> userErrors = data.customerCreate().userErrors();
if (userErrors != null) {
foreach(UserError error in userErrors) {
// field which may have a user error
Debug.Log(error.field());
// error message for the field which had an error
Debug.Log(error.message());
}
} else {
Debug.Log("No user errors the customer was created");
}
}
}
);

◆ Mutation() [2/2]

void Shopify.Unity.ShopifyClient.Mutation ( MutationQuery  query,
MutationRootHandler  callback 
)
inline

Allows you to continuously make a root query, till the response is deemed ready.

Parameters
isReadyA Delegates.PollUpdatedHandler that determines if polling should stop by returning true
queryThe query to be queried continuously
// Example that uses polling
QueryRootQuery query = new QueryRootQuery();
query.node(
buildQuery: node => node
.onCheckout(checkout => checkout.ready()),
id: "someCheckoutID""
);
PollUpdatedHandler isReadyHandler = (updatedQueryRoot) => {
var expectedNode = (Checkout) updatedQueryRoot.node();
return expectedNode.ready();
};
PollQuery(isReadyHandler, query, (response, error) => {
if (error == null) {
var checkout = (Checkout) response.node();
// checkout.ready() is true
}
})
public void PollQuery (PollUpdatedHandler isReady, QueryRootQuery query, QueryRootHandler callback) {
const float POLL_DELAY_SECONDS = 0.5f;
Query (query, (QueryRoot response, ShopifyError error) => {
if (error != null) {
callback (response, error);
} else {
if (isReady (response)) {
callback (response, null);
} else {
UnityTimeout.Start (POLL_DELAY_SECONDS, () => {
PollQuery (isReady, query, callback);
});
}
}
});
}
<summary>
Allows you to send custom prebuilt GraphQL mutation queries to the Storefront API.
</summary>
<param name="query">a query to be sent to the Storefront API</param>
<param name="callback">callback which will receive a response</param>
\code
// Example that creates a custom mutation query
MutationQuery mutation = new MutationQuery();
mutation.customerCreate(
buildQuery: (cc) => { cc
.userErrors(
buildQuery: (ue) => { ue
.field()
.message();
}
);
},
input: new CustomerCreateInput(
email: "mikkoh@email.com",
password: "oh so secret"
)
);
ShopifyBuy.Client().Mutation(
query: mutation,
callback: (data, error) => {
if (error != null) {
Debug.Log("There was an error: " + error.Reason);
} else {
List<UserError> userErrors = data.customerCreate().userErrors();
if (userErrors != null) {
foreach(UserError error in userErrors) {
// field which may have a user error
Debug.Log(error.field());
// error message for the field which had an error
Debug.Log(error.message());
}
} else {
Debug.Log("No user errors the customer was created");
}
}
}
);

◆ products() [1/3]

void Shopify.Unity.ShopifyClient.products ( ProductsHandler  callback,
List< string >  productIds 
)
inline

Generates a query to receive selected products from a Shopify store. The generated query will query the following on products:

  • id
  • title
  • descriptionHtml
  • images (with aliases defined by ShopifyClient.defaultImageResolutions)
    • altText
    • src
  • options
    • name
    • values
  • variants
    • id
    • available
    • price
    • title
    • weight
    • weightUnit
    • selectedOptions
      • name
      • values
    • image (with aliases defined by ShopifyClient.defaultImageResolutions)
      • altText
      • src
  • collections
    • image (with aliases defined by ShopifyClient.defaultImageResolutions)
      • altText
      • src
    • title
    • updatedAt
Parameters
callbackcallback that will receive responses from server
productIdsa list of product ids you'd like to query
// Example usage querying two product ids using a List<string>
List<string> productIds = new List<string>() {
"Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzk4OTUyNzYwOTk=",
"Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzk4OTUyNzkwNDM="
};
ShopifyBuy.Client().products((products, error) => {
Debug.Log(products[0].title());
Debug.Log(products[1].title());
}, productIds);

◆ products() [2/3]

void Shopify.Unity.ShopifyClient.products ( ProductsHandler  callback,
string  firstProductId,
params string[]  otherProductIds 
)
inline

Generates a query to receive selected products from a Shopify store. The generated query will query the following on products:

  • id
  • title
  • descriptionHtml
  • images (with aliases defined by ShopifyClient.defaultImageResolutions)
    • altText
    • src
  • options
    • name
    • values
  • variants
    • id
    • available
    • price
    • title
    • weight
    • weightUnit
    • selectedOptions
      • name
      • values
    • image (with aliases defined by ShopifyClient.defaultImageResolutions)
      • altText
      • src
  • collections
    • image (with aliases defined by ShopifyClient.defaultImageResolutions)
      • altText
      • src
    • title
    • updatedAt
Parameters
callbackcallback that will receive responses or errors from server
firstProductIdyou must pass in at least one product id to query
otherProductIdsafter the first product id you can pass in as many product ids as you'd like.
// Example usage querying two product ids
ShopifyBuy.Client().products((products, error) => {
Debug.Log(products[0].title());
Debug.Log(products[1].title());
}, "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzk4OTUyNzYwOTk=", "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzk4OTUyNzkwNDM=");

◆ products() [3/3]

void Shopify.Unity.ShopifyClient.products ( ProductsPaginatedHandler  callback,
int?  first = null,
string  after = null 
)
inline

Generates a query to receive one page of products from a Shopify store. The generated query will query the following on products:

Note that shop.products is a Connection (GraphQL paginated data structure).

first will define the page size. after will be the cursor for the next page.

Parameters
callbackcallback that will receive responses from server. This callback also can receive ShopifyError or null if no error happened. The callback also receives after will be the cursor for the next page. If the callback's after parameter is null, there are no more pages to fetch.
firstcan be used to limit how many products are returned. For instance 10 would return only 10 products
afteris used to load subsequent pages. Basically it's a cursor variable to define what page to load next. For example, when used with first: 10 and after: "abc", only the first 10 products would be loaded after cursor "abc". If no after is passed the first page of products will be loaded.
// Example usage querying one page of products after the cursor "abc":
ShopifyBuy.Client().products((products, error, after) => {
Debug.Log(products[0].title());
Debug.Log(products[1].title());
Debug.Log(products.Count);
if (after != null) {
// more products could be loaded here
}
}, after: "abc");

◆ Query() [1/2]

void Shopify.Unity.ShopifyClient.Query ( QueryRootDelegate  buildQuery,
QueryRootHandler  callback 
)
inline

Allows you to build and send custom GraphQL queries to the Storefront API. While having utility functions like products collections is useful, the Storefront API has more functionality. This method allows you to access all the extra functionality that the Storefront API provides.

Parameters
buildQuerydelegate that will build a query starting at QueryRootQuery which will be sent to the Storefront API
callbackcallback which will receive a response
// Example that builds a query that queries a Shop's name
ShopifyBuy.Client().Query(
query: q => q
.shop(s => s
.name()
),
callback: (data, error) => {
if (error != null) {
Debug.Log("There was an error: " + error.Reason);
} else {
Debug.Log(data.shop().name());
}
}
);

◆ Query() [2/2]

void Shopify.Unity.ShopifyClient.Query ( QueryRootQuery  query,
QueryRootHandler  callback 
)
inline

Allows you to send custom GraphQL queries to the Storefront API. While having utility functions like products collections is useful, the Storefront API has more functionality. This method allows you to access all the extra functionality that the Storefront API provides.

Parameters
querya GraphQL query to be sent to the Storefront API
callbackcallback which will receive a response from the query
// Example that queries a Shop's name
QueryRoot query = new QueryRootQuery();
query.shop(s => s
.name()
);
ShopifyBuy.Client().Query(
query: query,
callback: (data, error) => {
if (error != null) {
Debug.Log("There was an error: " + error.Reason);
} else {
Debug.Log(data.shop().name());
}
}
);

◆ UpdateLocale()

void Shopify.Unity.ShopifyClient.UpdateLocale ( string  locale)
inline

Overwrites the QueryLoader instance with a new one with the specified locale.

Parameters
localelocale for fetching translated content of supported types and fields
// Example usage for updating the locale to French:
ShopifyBuy.Client(shopDomain).UpdateLocale("fr")

Member Data Documentation

◆ DefaultImageResolutions

Dictionary<string, int> Shopify.Unity.ShopifyClient.DefaultImageResolutions
static
Initial value:
= new Dictionary<string, int> () { { "pico", 16 }, { "icon", 32 }, { "thumb", 50 }, { "small", 100 }, { "compact", 160 }, { "medium", 240 }, { "large", 480 }, { "grande", 600 }, { "resolution_1024", 1024 }, { "resolution_2048", 2048 }
}

This is a dictionary that defines aliases, maxWidth, and maxHeight for images loaded by products and collections . All Products images, Product variant images, and Collection images will be queried using aliases defined by this dictionary's keys and the maxWidth and maxHeight will be this dictionary's values.

// Returns an image source url whose dimensions are never greater than 100px
string srcSmallImage = productVariant.image().transformedSrc("small");
// Returns an image source url whose dimensions are never greater than 1024px
string src1024Image = productVariant.image().transformedSrc("resolution_1024");

Property Documentation

◆ AccessToken

string Shopify.Unity.ShopifyClient.AccessToken
get

AccessToken is the access token associated with this client to query Shopify.

◆ Domain

string Shopify.Unity.ShopifyClient.Domain
get

Domain is the Shopify store domain associated with this client.

◆ Locale

string Shopify.Unity.ShopifyClient.Locale
get

Locale is the language that supported translated content will be in.


The documentation for this class was generated from the following file: