# WhatsApp. Object data sent to HTTP Function

**URL:** <https://forum.wixstudio.com/t/whatsapp-object-data-sent-to-http-function/55429>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [January 15, 2024, 12:27am UTC](https://forum.wixstudio.com/t/whatsapp-object-data-sent-to-http-function/55429 "2024-01-15T00:27:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan25947](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/dan25947/32/83467_2.png) [@dan25947](https://forum.wixstudio.com/u/dan25947)\
**Post date:** [January 15, 2024, 12:27am UTC](https://forum.wixstudio.com/t/whatsapp-object-data-sent-to-http-function/55429/1 "2024-01-15T00:27:50Z")

</div>

**Question:**  
I have WhatsApp business API set up and running. I’m trying to receive messages to a dataset. I have the HTTP function set up and working, it receives data but when logging the (request) it simply says “[object WixHttpFunctionRequestBody]” and doesn’t seem to offer any useable data.

I have set up using [glitch.com](http://glitch.com) and that shows the object data as you’d expect. Likewise using webhooks with [Make.com](http://Make.com) (Integromat).

Can anyone help??

```javascript
//http-function.js 

export function post_whatsApp(request) {

 console.log(request + " post_whatsApp is accessed");

   

/*
{
  "object": "whatsapp_business_account",
  "entry": [
    {
      "id": "0",
      "changes": [
        {
          "field": "messages",
          "value": {
            "messaging_product": "whatsapp",
            "metadata": {
              "display_phone_number": "16505551111",
              "phone_number_id": "123456123"
            },
            "contacts": [
              {
                "profile": {
                  "name": "test user name"
                },
                "wa_id": "16315551181"
              }
            ],
            "messages": [
              {
                "from": "16315551181",
                "id": "ABGGFlA5Fpa",
                "timestamp": "1504902988",
                "type": "text",
                "text": {
                  "body": "this is a text message"
                }
              }
            ]
          }
        }
      ]
    }
  ]
}
*/

 let options = {
 "headers": {
 "Content-Type": "application/json"
        }
    };
 return request.body.json()
    .then( (body) => {
 return createLine(body, options);
    })
    .catch( (error) => {
        options.body = {
 "error": error
        };
 return serverError(options);
    });
    
    
 
}

function createLine(body, options) {
 let dataInsert = {
 "number" : body.number,  
 "title": body.title,
 "message": body.message,
"media" : body.media,

    };
 return wixData.insert('WhatsApp', dataInsert)
    .then( (result) => {
 let item = result;
        options.body = {
 "status": 201,
 "response": item
        };
 return created(options);
    });
}

```

---

<div class="post-metadata">

**Author:** ![thomasj](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/thomasj/32/30791_2.png) [@thomasj](https://forum.wixstudio.com/u/thomasj)\
**Post date:** [January 16, 2024, 8:23pm UTC](https://forum.wixstudio.com/t/whatsapp-object-data-sent-to-http-function/55429/2 "2024-01-16T20:23:10Z")

</div>

Assuming the object received in the http function is a JSON object, you will need to convert the JSON object into a JavaScript object to access the data.

This is done using the WixHttpFunctionRequestBody [.json() method](https://www.wix.com/velo/reference/wix-http-functions/wixhttpfunctionrequest-obj/wixhttpfunctionrequestbody/json)

Here is a example of what could look like:

```javascript
import {ok} from 'wix-http-functions';

export async function post_myFunction(request) {
    // Parse the request body into a JSON object
    const json = await request.body.json();

    // Log the JSON object to the console (seen in Site Events log monitor)
    console.log(json);

    // Do whatever is necessary with the object and return a response
    return ok();
}

```

_Note: This example uses async syntax but can be done with promise chaining_

---

<div class="post-metadata">

**Author:** ![dan25947](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/dan25947/32/83467_2.png) [@dan25947](https://forum.wixstudio.com/u/dan25947)\
**Post date:** [January 18, 2024, 3:14pm UTC](https://forum.wixstudio.com/t/whatsapp-object-data-sent-to-http-function/55429/3 "2024-01-18T15:14:54Z")

</div>

Thank you!  
It’s so obvious when you see it. 😁
