Is Wix stripping out the body of a POST request being made from Google?

I have implemented Real Time Developer Notifications (RTDN) for my Android App within the Google Developer Console as specified here . In doing so, I made my backend http-functions.js file include a POST section to receive the POST request to which Google sends when purchase activity is performed within my Android mobile app.

I have validated that the connection is correct by sending a test notification from the Google Developer Console, and also when a test user makes a purchase from within the app (which is using v 4.0.0 of the Play Billing API).

However, in both cases, the body of the POST on my back-end is empty. According to the Google docs, it should contain a json block in this format:

{
  "message": {
    "attributes": {
      "key": "value"
    },
    "data": "eyAidmVyc2lvbiI6IHN0cmluZywgInBhY2thZ2VOYW1lIjogc3RyaW5nLCAiZXZlbnRUaW1lTWlsbGlzIjogbG9uZywgIm9uZVRpbWVQcm9kdWN0Tm90aWZpY2F0aW9uIjogT25lVGltZVByb2R1Y3ROb3RpZmljYXRpb24sICJzdWJzY3JpcHRpb25Ob3RpZmljYXRpb24iOiBTdWJzY3JpcHRpb25Ob3RpZmljYXRpb24sICJ0ZXN0Tm90aWZpY2F0aW9uIjogVGVzdE5vdGlmaWNhdGlvbiB9",
    "messageId": "136969346945"
  },
  "subscription": "projects/myproject/subscriptions/mysubscription"
}

I am getting an empty {} block instead. For example here is the console output I use to see what is being passed to my POST handler within http-functions.js:

console.log("Got a post for sitsubscriptionstatus: " + JSON.stringify(request, null, 2));

And here is the relevant portion of the POST request that I get:

 functionName: utils,
 path: [
 sitsubscriptionstatus
 ],
 url: https://www.stayingintouch.com/_functions/utils/sitsubscriptionstatus,
 baseUrl: https://www.stayingintouch.com/_functions,
 method: POST,
 body: {},
 headers: {
 host: www.stayingintouch.com,
 user-agent: APIs-Google; (+https://developers.google.com/webmasters/APIs-Google.html),
 transfer-encoding: chunked,
 accept: application/json,
 accept-encoding: gzip, deflate, br,
 authorization: Bearer <LONG ENCODED TEXT STRING HERE>,
 cid: ,
 content-type: application/json,
 from: noreply@google.com,
 geoip_country_code: CA,
 geoip_country_code3: CAN,

Notice that the body is empty. Is Wix/Velo doing something to strip out the POST body behind the scenes for some reason?

The body in the request is a WixHttpFunctionRequestBody object so try calling request.body.json() to get your data.

Thanks - but I got the same result. I implemented this in the backend:

console.log("Body of push message is: " + JSON.stringify(request.body,null,2));
console.log("Body of push message via Wix is: " + JSON.stringify(request.body.json(),null,2));

Performed another test message push and the result was:

"["Body of push message is: {}"]"
"["Body of push message via Wix is: {}"]"

Other ideas?

Very strange. Another thing to try is that the body.json() function is a promise, so you’ll need to await it or read the value on the .then. Something like request.body.json().then((body) => { console.log(body) });

That did it!

Updated code:

const wixBodyResult = await request.body.json();
console.log("Body of push message is: " + JSON.stringify(request.body,null,2));

Relevant portion of updated result:

Body of push message is: {
 message: {
 data: <ENCODED DATA RESULT WAS HERE>,
 messageId: 3527252121436771,
 message_id: 3527252121436771,
 publishTime: 2021-12-18T21:24:21.67Z,
 publish_time: 2021-12-18T21:24:21.67Z
 },
 subscription: <SUBSCRIPTION DATA WAS HERE>
}

Thanks!

Btw for future reference, how would I know that the body of the POST needed to be pulled in this manner, i.e. where is this documented? Any other things like this (i.e. having to do with parsing data from either a POST or GET) that would be useful to know?

Awesome! Glad it is working. This info is buried in the documentation. Here is the link: https://www.wix.com/velo/reference/wix-http-functions/wixhttpfunctionrequest-obj/wixhttpfunctionrequestbody

Good to hear!

await / .then() is required for request.body.json() OR request.body.text()