NetTalk Central

NetTalk Web Server => Web Server - Ask For Help => Topic started by: JHojka on May 10, 2022, 08:32:27 AM

Title: load Webhook POST data load to a queue
Post by: JHojka on May 10, 2022, 08:32:27 AM
How can I access the POST data section and load this into a group.

The data is in json format. I have tried my best to work with p_web.RequestData.

Here is the group

element                  Group,Name('element')
notificationId             STRING(255),Name('notificationId')
eventType                  STRING(255),Name('eventType')
eventDate                  STRING(255),Name('eventDate')
webhookId                  STRING(255),Name('webhookId')
payload                    Group,Name('payload')
responseCode                 Real,Name('responseCode')
authCode                     STRING(255),Name('authCode')
avsResponse                  STRING(255),Name('avsResponse')
authAmount                   Real,Name('authAmount')
invoiceNumber                STRING(255),Name('invoiceNumber')
entityName                   STRING(255),Name('entityName')
id                           STRING(255),Name('id')
                           End
                         End

json                     jsonClass

  json.start()
  json.SetTagCase(jf:CaseAsIs)
  json.Load(element,p_web.RequestData.DataStringTheory) ! Load From a StringTheory object

This code GPF's

This is the POST data

{"notificationId":"1a5bf2dd-e05d-4224-8157-459f0f11f40e","eventType":"net.authorize.payment.authcapture.created","eventDate":"2022-05-06T08:49:50.3674712Z","webhookId":"5f77108b-039f-4c20-9157-b0b9049c4ddf","payload":{"responseCode":1,"authCode":"AQSOEP","avsResponse":"P","authAmount":123.1,"invoiceNumber":"211210110","entityName":"transaction","id":"40091147498"}}

Jeff

Title: Re: load Webhook POST data load to a queue
Post by: Bruce on May 10, 2022, 09:05:57 PM
  json.Load(element,p_web.getvalue('_json_'))
Title: Re: load Webhook POST data load to a queue
Post by: JHojka on May 11, 2022, 04:47:13 AM
I put this exact line of code in my program and I no longer get a GPF. The result is that I now have a empty group without any of the post data. Not the result I had hoped for.

Here is my new code

  json.start()
  json.SetTagCase(jf:CaseAsIs)
  json.Load(element,p_web.getvalue('_json_'))
  json.Save(element,'D:\dev\json\webjson.txt')

Here is my POST

POST / HTTP/1.1
Host: 127.0.0.1:88
Connection: keep-alive
Content-Length: 434
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="101", "Google Chrome";v="101"
sec-ch-ua-mobile: ?0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36
sec-ch-ua-platform: "Windows"
Content-Type: application/json
Accept: */*
Origin: chrome-extension://gmmkjpcadciiokjpikmkkmapphbmdjok
Sec-Fetch-Site: none
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cookie: SESSIONIDX=7jL0Kz8nZLNojwuLMN3hmVMJaV3SxK

{"notificationId":"e73d5945-f462-46aa-b757-37e4635c7fac","eventType":"net.authorize.customer.subscription.expiring","eventDate":"2022-05-11T09:21:04.1574729Z","webhookId":"5f77108b-039f-4c20-9157-b0b9049c4ddf","payload":{"name":"TEST PERSON","amount":100,"status":"active","profile":{"customerProfileId":505297168,"customerPaymentProfileId":508334454,"customerShippingAddressId":507148838},"entityName":"subscription","id":"8119550"}}

Here is my result.

{
   "notificationId" : "",
   "eventType" : "",
   "eventDate" : "",
   "webhookId" : "",
   "payload" : {
      "responseCode" : 0,
      "authCode" : "",
      "avsResponse" : "",
      "authAmount" : 0,
      "invoiceNumber" : "",
      "entityName" : "",
      "id" : ""
   }
}

What am I not understanding

Jeff
Title: Re: load Webhook POST data load to a queue
Post by: JHojka on May 11, 2022, 05:30:19 AM
This is what worked.

 json.LoadString(p_web.getvalue('_json_'))
 json.Load(element)
Title: Re: load Webhook POST data load to a queue
Post by: Bruce on May 11, 2022, 09:53:34 PM
my bad, jFiles takes either a stringtheory object, or a filename as the parameter. so the correct code is

  str.SetValue(p_web.GetValue('_json_'))
  json.Load(element,str)

you forced me to go read the docs; :)
https://www.capesoft.com/docs/jfiles2/jfiles.htm#LoadingJSONString

Cheers
Bruce
Title: Re: load Webhook POST data load to a queue
Post by: JHojka on May 12, 2022, 04:51:55 AM
Reading the docs is where its at!

Is the code I chose wrong? It works so I am curious to know if there is a different reason to use your coding method.

Jeff
Title: Re: load Webhook POST data load to a queue
Post by: Bruce on May 14, 2022, 12:38:26 AM
Your code will work fine. The first line loads the Json file into a Jason "Tree". The second line loads the tree into the Queue.

The reason I posted my code is because in a lot of cases (although not this one) the json text is already in a StringTheory object. And of course then you can load the object straight into the queue. (Internally it does the same 2 steps as you, build the tree, then loads the tree into the queue.)