Shopify Java SDK for Orders and Gift Cards.
Generate the JAR from this repository then include it in your project libs folder. Now, follow the below steps to use the generated Jar in your project:
The following properties will be used to create the Shopify API Context:
accessToken=
apiVersion=2024-07
username=
password=
shopSubdomain=
-
Set Gift Card Object
// Set Gift Card Object GiftCard giftCard = new GiftCard(); giftCard.setCode("12345678901234"); giftCard.setNote("Not for gift card"); giftCard.setInitialValue("10.00"); giftCard.setBalance("10.00");
-
Create Gift Card Request
// Create Gift Card Request GiftCardRequest giftCardRequest = new GiftCardRequest(); giftCardRequest.setGiftCard(giftCard);
-
Create API Context
// Create API Context ApiContext apiContext = new ApiContext(); apiContext.setUsername("username"); apiContext.setPassword("password"); apiContext.setShopSubdomain("shopSubdomain"); apiContext.setApiVersion("apiVersion");
-
Gift Card API Resource
// Gift Card API Resource GiftCardResource cardResource = new GiftCardResource(apiContext); try { // Execute the request GiftCardResponse cardResponse = cardResource.createGiftCard(giftCardRequest); System.out.println("GiftCard created"); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); }
This example demonstrates how to create a Gift Card in Shopify using the Shopify Java SDK. Adjust username
, password
, shopSubdomain
, and apiVersion
with your actual Shopify API credentials. The GiftCard
object is set with its properties, and then a GiftCardRequest
is created. The API context is configured with the necessary credentials, and the Gift Card API Resource is used to execute the request and handle the response.