Can't properly format request

Hey team,

I’m using the Function node to build a properly formatted event hit according to Facebook’s documentation.

However, the output is wrapped in an array… I need to return the object directly inside of that array.

Here is the function code:

const json = items[0].json;
const body = json.body;

const results = {};
const user_data = {};
const custom_data = {};
const data = [];

// Build User Data Object
user_data.em = body.sha256;

// Build Custom Data Object
custom_data.source = "IDR";


// Build FB Event
results.event_time = Math.round(Date.now() / 1000);
results.event_name = "IDR Lead";
results.action_source = "system_generated";
results.user_data = user_data;
results.custom_data = custom_data;

console.log('results', results);

data.push(results);

return {data}

Here is the sample output that does NOT work

[
{
"data": [
{
"event_time": 1664381138,
"event_name": "IDR Lead",
"action_source": "system_generated",
"user_data": {
"em": "Test value"
},
"custom_data": {
"source": "IDR"
}
}
]
}
]

This is the result that WOULD work

{
"data": [
{
"event_time": 1664381138,
"event_name": "IDR Lead",
"action_source": "system_generated",
"user_data": {
"em": "Test value"
},
"custom_data": {
"source": "IDR"
}
}
]
}

Any ideas on how I can send the data to Facebook without the extra array wrapper?


Hey @StocktonF,

That looks like we could do with updating that node a bit, Have you tried adding the query options using the Add Options in the node?

Hi @Jon ,

Is that something I can do to get this to work? Or you mean the team would have to modify the Facebook API node?

I don’t think it would work in the params… Facebook wants it in the POST body…

That is annoying, What about using the json to binary node and sending it as binary data does that change anything?

I don’t have a facebook account I can test with sadly so it is a bit of a tricky one to test with. If Facebook expect it in the post body we should maybe have an option to specify the body contents a but like we do for the HTTP Request node.

Got it, yes that would be nice.

So what do I do from here?

Do I need to wait for the team to make that update? If so, how long does that usually take?

Hey @StocktonF,

At some point I will need to set up a Facebook account so I can test it it could be that we clean the data up in the node so I will take a look at the code as well to see what we are doing.

Hey @StocktonF,

Thanks for sending the test credentials, I have now managed to get it working. The workflow below shows what I have done, One thing I did have to do was update em to use a hash as it turns out Facebook doesn’t like the unhashed values being sent (Parameter für Kundeninformationen - Conversions API - Dokumentation - Facebook for Developers)

Wow, thank you so much for diving into this…

My question is WHY?!

How does the binary data work?

Hey @StocktonF,

It is magic :magic_wand:

To be honest I am not sure, I was looking at the nodes code and from what I could see it doesn’t just take the input to post it and needs the binary option which is sent as the body in the request.

I am going to pop open a feature request internally for this node as it took a bit of work to understand what needs to actually happen with it… It could be that I have missed something with it as well but I feel we can do better with this one.