Skip to main content

Unity Buy SDK

Deprecated

As of July 1, 2023 the Unity Buy SDK is no longer supported. For more information, please see the SDK Alternatives section below.

You can use the Unity Buy SDK to integrate physical products directly into games and apps made with the Unity game engine.



Anchor to Step 1: Generate an access tokenStep 1: Generate an access token

To generate an access token, you can generate one in the Shopify admin. Alternatively, you can create a custom app and use authorization code grant.


Anchor to Step 2: Make your products and collections availableStep 2: Make your products and collections available

After you've generated an access token, you need to make products and collections available to your custom app to access them from your app. After the products and collections are available, you can retrieve them using their respective IDs.

Tip

If you have many products or collections, then you can use bulk actions to make them available in one step.

Anchor to Make a product availableMake a product available

  1. From your Shopify admin, go to Products.
  2. From the Products page, click the product you want to make available.
  3. Next to SALES CHANNELS AND APPS click Manage.
  4. In the Sales channels and apps dialog box, select the box next to the name of your custom app.

Anchor to Make a collection availableMake a collection available

  1. From your Shopify admin, go to Products and click Collections.
  2. From the Collections page, click the collection you want to make available.
  3. Next to SALES CHANNELS AND APPS click Manage.
  4. In the Sales channels and apps dialog box, select the box next to the name of your custom app.

Anchor to Step 3: Access the Unity Buy SDKStep 3: Access the Unity Buy SDK

Using the Unity Buy SDK, you can do the following:

  • Fetch information about products on your Shopify store
  • Create an in-game shopping cart where customers can add products
  • Generate a checkout for customers to purchase products
Note

This SDK is compatible with Unity versions up to 2019.x.

When you're ready to start building, explore the examples in GitHub to see how to implement the SDK in your app.

View the Unity Buy SDK on GitHub

The Unity engine provides robust APIs for performing HTTP requests which you can use with our Storefront GraphQL API. Below is an example of performing a simple GraphQL query.

using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
using System.Text;

public class StorefrontGraphQLAPI : MonoBehaviour {
void Start() {
StartCoroutine(PerformQuery());
}

IEnumerator PerformQuery() {
string query = "{\"query\": \"query MyQuery { shop { name } }\"}";

UnityWebRequest request = new UnityWebRequest(
"https://example.myshopify.com/api/2023-04/graphql", "POST");

request.SetRequestHeader("Accept", "application/json");
request.SetRequestHeader("Content-Type", "application/json");

request.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(query));
request.downloadHandler = new DownloadHandlerBuffer();

yield return request.SendWebRequest();

if (request.result == UnityWebRequest.Result.Success) {
byte[] results = request.downloadHandler.data;
}
else {
// handle error
}
}
}

Visit our forums to connect with the community and learn more about the Shopify API and App development.

Find a Shopify Partner for hire in our ecosystem of talented development agencies.


Was this page helpful?