West Wind Internet and Client Tools
POST with JSON request body
Gravatar is a globally recognized avatar based on your email address. POST with JSON request body
  Bob Powell
  All
  Dec 4, 2019 @ 02:23pm

I am trying to use the wwJsonSerializer to POST to the Shopify API to update inventory quantities. I have been told my request is being sent with the body as URL-encoded params. instead of making a POST to "/admin/api/2019-10/inventory_levels/set.json" with a JSON request body, not URL params.

I am not sure what needs to be changed. Here is what I am doing:

lcUrl = gcStoreURL + "/admin/api/2019-10/inventory_levels/set.json"

loLevel = Createobject("EMPTY") AddProperty(loLevel, "location_id", Int(tnLocationID)) AddProperty(loLevel, "inventory_item_id",Int(tnInvItemID)) AddProperty(loLevel, "available",tnAvailable)

lcJson = loSer.Serialize(loLevel) lcUrl = lcUrl + lcJson

loHttp = Createobject("wwHttp")

loHttp.Post(lcUrl, gcApiKey, gcPwdKey )

Gravatar is a globally recognized avatar based on your email address. re: POST with JSON request body
  Bob Powell
  Bob Powell
  Dec 4, 2019 @ 03:21pm

I believe I was able to solve this by using loHttp.AddPostKey(lcJson)

But now I have a problem that it is sending the post with cookies.

Is there a way to prevent cookies being sent?

Gravatar is a globally recognized avatar based on your email address. re: POST with JSON request body
  Rick Strahl
  Bob Powell
  Dec 5, 2019 @ 03:40pm

WinInet automatically caches cookies that are collected from a given site and automatically sends them on subsequent requests.

You can use the INTERNET_FLAG_NO_COOKIES flag to not send cookies or store cookies on return:

#INCLUDE wconnect.h
lcUrl = "..."

loHttp = CREATEOBJECT("wwhttp")
loHttp.nHttpServiceFlags = INTERNET_FLAG_NO_COOKIES
lcResult = loHttp.Get(lcUrl)

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: POST with JSON request body
  Bob Powell
  Rick Strahl
  Dec 6, 2019 @ 10:22am

That works! Thanks for your help!

© 1996-2024