Visual FoxPro
Visual FoxPro
Shopify Query a variant for its inventory item ID
See more Shopify Examples
Query a product variant to find the ID of its inventory item.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL loResp
LOCAL loJsonResponse
LOCAL lnId
LOCAL lnProduct_id
LOCAL lcTitle
LOCAL lnInventory_item_id
LOCAL lcAdmin_graphql_api_id
lnSuccess = 0
* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loHttp = CreateObject('Chilkat.Http')
loHttp.Login = "SHOPIFY_PRIVATE_API_KEY"
loHttp.Password = "SHOPIFY_PRIVATE_API_KEY"
loHttp.Accept = "application/json"
loResp = CreateObject('Chilkat.HttpResponse')
lnSuccess = loHttp.HttpNoBody("GET","https://{shop}.myshopify.com/admin/api/2020-04/products/{product_id}/variants/{variant_id}.json",loResp)
IF (lnSuccess = 0) THEN
? loHttp.LastErrorText
RELEASE loHttp
RELEASE loResp
CANCEL
ENDIF
? "Response Status Code: " + STR(loResp.StatusCode)
loJsonResponse = CreateObject('Chilkat.JsonObject')
loJsonResponse.Load(loResp.BodyStr)
loJsonResponse.EmitCompact = 0
? loJsonResponse.Emit()
IF (loResp.StatusCode <> 200) THEN
? "Failed."
RELEASE loHttp
RELEASE loResp
RELEASE loJsonResponse
CANCEL
ENDIF
* Sample output...
* (See the parsing code below..)
*
* Use the this online tool to generate parsing code from sample JSON:
* Generate Parsing Code from JSON
* {
* "id": 12195009364024,
* "product_id": 1321541042232,
* "title": "xs",
* ...
* "inventory_item_id": 12250274365496,
* ...
* "admin_graphql_api_id": "gid://shopify/ProductVariant/12195009364024"
* }
*
lnId = loJsonResponse.IntOf("id")
lnProduct_id = loJsonResponse.IntOf("product_id")
lcTitle = loJsonResponse.StringOf("title")
lnInventory_item_id = loJsonResponse.IntOf("inventory_item_id")
lcAdmin_graphql_api_id = loJsonResponse.StringOf("admin_graphql_api_id")
RELEASE loHttp
RELEASE loResp
RELEASE loJsonResponse