Welcome
Login
Sign up
Home
Solutions
Forums
How can we help you today?
Enter your search term here...
Search
Login
or
Signup
to submit a new ticket
Check ticket status
Start a new topic
Discussions
Kinvey Forums
Business Logic
body not sent when use request module with post
J
Jonas
started a topic
over 7 years ago
Hi,
i'm experiencing issues with the following code in the BL:
function onPreSave(request, response, modules)
{
var req = modules.request;
var logger = modules.logger;
logger.info(request.body);
req.request
(
{
uri: 'http://***/api/export',
method: 'POST',
body : "something" //.stringify(request.body)
},
function(error, res, body)
{
logger.info(arguments);
if (error)
{
response.body = {error: error.message};
response.complete(434);
}
else
{
response.body = JSON.parse(body);
response.complete(res.status);
}
}
);
}
i receive the call in my nodejs server, but when i check the request.body, it says it is undefined..
What am i doing wrong?
2 Comments
Oldest First
Popular
Newest First
Sorted by
Oldest First
I
Ivan Stoyanov
said
over 7 years ago
You probably need json:true (or Content-Type: application/json header, which is equivalent). Your node.js server does not know how to deserialize the body.
J
Jonas
said
over 7 years ago
Thanks for the fast reply!
That was indeed the solution, thank you!
Login
or
Signup
to post a comment
More topics in
Business Logic
How do I access query string values for GET and DELETE requests?
Basic Authentication in Business Logic
How do I cascade delete entities from related collections?
All BL failing with Violation Error
How do I send push notifications?
Whenever I try to query by _id, I get zero results
receiving SOCKETTIMEDOUT when requesting external http response
Unique Constraints on a collection column?
Need some help with grouping
Accessing Endpoint from Collection Hook
See all 342 topics
Jonas
i'm experiencing issues with the following code in the BL:
function onPreSave(request, response, modules)
{
var req = modules.request;
var logger = modules.logger;
logger.info(request.body);
req.request
(
{
uri: 'http://***/api/export',
method: 'POST',
body : "something" //.stringify(request.body)
},
function(error, res, body)
{
logger.info(arguments);
if (error)
{
response.body = {error: error.message};
response.complete(434);
}
else
{
response.body = JSON.parse(body);
response.complete(res.status);
}
}
);
}
i receive the call in my nodejs server, but when i check the request.body, it says it is undefined..
What am i doing wrong?