FoxPro Programming
Technique question
Gravatar is a globally recognized avatar based on your email address. Technique question
  Joel Aiken
  All
  Jun 2, 2018 @ 08:34am

I have an app which receives data via webhooks from Shopify.com The data is received on my server in JSON format.

When sending the data to me, Shopify expects a HTML 200 response right away. They caution against attempting to receive the data AND simultaneously processing the newly received data into the client's system, which might delay the webhook from completing quickly or even fail. If the webhook fails, it sets in motion attempts to re-transmit the data. Shopify wants clients to break this process into two steps:

  1. Receive their webhook data and see their HTML 200 response indicating success.
  2. Then clients are free to process the data as needed.

I'm looking for a technique to trigger the data processing in a separate program after the webhook data is received. I'm likely overlooking an obvious solution. I would like minimal delay after receiving the data and before processing it. I could set up a "listener" exe which ran all the time, and kept checking for newly received data (and processed it when it found new data). Is that the best solution?

Joel Aiken

Gravatar is a globally recognized avatar based on your email address. re: Technique question
  FoxInCloud Support - Thierry N.
  Joel Aiken
  Jun 2, 2018 @ 10:53am

You can send the HTTP 200 response back asynchronously and continue with your data processing.

Gravatar is a globally recognized avatar based on your email address. re: Technique question
  Joel Aiken
  FoxInCloud Support - Thierry N.
  Jun 2, 2018 @ 01:04pm

thanks. that'll do it. Joel

Gravatar is a globally recognized avatar based on your email address. re: Technique question
  Rick Strahl
  FoxInCloud Support - Thierry N.
  Jun 2, 2018 @ 04:46pm

Not quite sure how you would send back a response 'asynchronously' and then continue processing. That's generally not the way Web Connection's server side handling works as response data is cached and not written to output until the request completes.

There are a couple of ways to approach this.

How long does your order update process take? Does it take a fraction of a second or even a second or two? If so - screw Shopify and what they want you to do, just do it all in one pass and call it a day 😃

If your order processing does in fact take a bit longer, capture the request from the Webhook, and then from within that request issue an async HTTP request to your own server. You can save whatever information the WebHook passed in some quick way (maybe store the raw JSON in a DB record), then generate an id to look that value up by in another request.

Something like this:

************************************************************************
FUNCTION ShopifyHook()
****************************************

lcId = GetUniqueId()
lcJson = Request.Form() && capture json sent
lcFile  = ADDBS(SYS(2023)) + lcId + ".json"
STRTOFILE(lcJson,lcFile)

loHttp = CREATEOBJECT("wwHttp")
loHttp.HttpGetAsync("http://localhost/wconnect/ShopifyHookProcessing.wwd?id=" + lcId)

Response.Status = "204 No Content"
RETURN
ENDFUNC
*   ShopifyHook


************************************************************************
FUNCTION ShopifyHookProcessing()
****************************************
lcId = Request.QueryString("id")
lcFile  = ADDBS(SYS(2023)) + lcId + ".json"
lcJson = FILETOSTR(lcFile)
ERASE (lcFile)

Response.Write("OK")
ENDFUNC
*   ShopifyHookProcessing

+++ Rick ---

© 1996-2024