How to get body in post request to HTTPS Endspoint in atlas function?

I have created a function in Atlas function and created an HTTPS Endpoint to insert some data,
but how to get the body in the post request. I am getting query parameter in the request but body is not there.

import moment from "moment";
exports = function ({ query, headers, body }, response) {  
	return {
		status: "ok",

This is the response I am getting when hitting Post request with body.

    "status": "ok",
    "bodyy": {
        "Subtype": 0,
        "Data": "ew0KICAgICJwYXJ0eV9uYW1lIjoiUmFodWwgVlMgUGlua2kiDQp9"
    "query": {},
    "response": {}

This is the screenshot of my postman post request with simple body and response I am getting.

Read operation is working fine. But with post request body is having subtype and data with encoded string.

Kindly help on this as I googled so much but not getting any help.


Hello @Zubair_Rajput ,

Please confirm if my understanding of your use-case is correct? You are sending a Post request to your function in Atlas and it has a return statement where the body of the request should be returned but instead you are getting a base64 encoded value of the parameter in body.

If yes, then, can you please confirm if you want to just insert data or you also want to read inserted data from the Post request?

Additionally, the response you shared in the bodyy. It consists of binary datatype whose Canonical representation is as below

{ "$binary":
      "base64": "<payload>",
      "subType": "<t>"

Where the values are as follows:

  • "<payload>"
    • Base64 encoded (with padding as “=”) payload string.
  • "<t>"
    • A one- or two-character hex string that corresponds to a BSON binary subtype. See the extended bson documentation BSON (Binary JSON): Specification for subtypes available.

If you change the return statement to below, you will be able to see the body sent in your POST request

		status: "ok",


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.