Web Connection
API PUT to Shopify.com
Gravatar is a globally recognized avatar based on your email address. API PUT to Shopify.com
  Joel Aiken
  All
  Aug 8, 2018 @ 07:15pm

I am having trouble sending an inventory Adjustment to Shopify using API's This is the first PUT API I have created, and it doesn't work. I have several GET API's that work fine, all written in VFP WebConnect ver 6.15 I can't seem to make a successful PUT API.

I am trying to follow the WebConnect DOCs technique for making the API PUT but the code below fails. Does anyone see a reason I can't make this work? Thanks, Joel Aiken

*------------------------------------------------
*    API_PUT_test1.prg
*    8-8-18
*
*
*------------------------------------------------

  lcUsername_Holly= "abcdefghi"
  lcPassword_Holly="jklmnopqrst" 

DO wwHttp
DO wwJsonSerializer

lcUsername=lcUsername_Holly
lcPassword=lcPassword_Holly

loSer = CREATEOBJECT("wwJsonSerializer")
*lcJsonIn = loSer.Serialize(loPostObject)    && Some object or value to serialize
lcJsonIn=[{"location_id": 49532627,"inventory_item_id": 1138602311699,"available_adjustment": 5}]

loHttp = CREATEOBJECT("wwHttp")
loHttp.cContentType = "application/json"
loHttp.cHTTPVerb = "PUT"  && Use any HTTP verbs POST/PUT/DELETE/GET etc.
loHttp.AddPostKey(lcJsonIn)  && raw post data
lcURL="https://hollyaiken.myshopify.com/admin/inventory_levels/adjust.json"
lcJsonResult=loHTTP.HTTPGet(lcURL,lcusername,lcPassword)

? "lcJsonResult="+lcJsonResult
wait

** WHICH OF THE FOLLOWING ??
*loResultObject1 = loSer.DeserializeJson(lcJsonResult)
loResultObject2 = loSer.FormatJson(lcJsonResult)

? loResult.Object2

*wait

*** Do something with the result object
*? loResultObject.status
*? loResultObject.Data.SummaryValue


USE holly\api_puts IN 0
INSERT into api_puts(time,URL) values(DATETIME(),lcURL)
replace api_puts.result with lcJsonResult
replace api_puts.oData with loResultObject
SELECT  api_puts
GO BOTTOM 
browse

CLOSE DATABASES ALL
RETURN
*================================

Gravatar is a globally recognized avatar based on your email address. re: API PUT to Shopify.com
  Rick Strahl
  Joel Aiken
  Aug 9, 2018 @ 12:19pm

That should work fine.

You should check the result code and error message from the service to see what's failing. Lots of other things than could be wrong there - authentication, how auth is passed etc. Shopify should probably send you some info in the response.

When in doubt look at the request as it goes over the wire with Fiddler.

+++ Rick ---

© 1996-2024