I am using the following code to do a Post request to Google PubSub API:
pushMessages = async function()
{
//const collection = context.services.get(`mongodb-atlas`).db(`billing`).collection(`projectdata`);
var needle = require('needle');
var postData = {
"message": "hello world"
}
needle
.post('https://pubsub.googleapis.com/v1/projects/topicname:publish', postData, { json: true },
function(err, resp) {
if (err)
console.log('Error: ' + JSON.stringify(err.message));
else
console.log('OK.'+ JSON.stringify(resp.body));
});
}
and I keep getting:
{"error":{"code":400,"message":"Invalid JSON payload received. Unknown name \"message\": Cannot find field.","status":"INVALID_ARGUMENT","details":[{"@type":"type.googleapis.com/google.rpc.BadRequest","fieldViolations":[{"description":"Invalid JSON payload received. Unknown name \"message\": Cannot find field."}]}]}}.
Any hint on how to solve this issue?