Resolved the issue. I had JSON.stringify in my options_1.body which was not 
needed. Please consider it resolved. I do ont know if there is any option I 
need to click to mark it resolved as in other forums. 



On Wednesday, January 10, 2018 at 9:34:22 PM UTC-5, Lucky Jindal wrote:
>
> How can I make HTTP POST call to a server using array of request-promise 
> objects where URL is same, only data is different each time.
>
> I have array of objects that need to be POST'ed toa server one by one, 
> independently. I created request promise's array and then promise.all () 
> but failed. However, single object (not using array) works.
>
>
>
> Ex: 1. Previous functionality, with 1 object, I use -
>
> *var request = require("request-promise")*
>
>            *options.body ={ "name" : "sdsd"}*
>
> *request (options).then(...).catch(..) -> it works*
>
>
>
> 2. Now with many objects in array, I created objectsArr[],  then I use 
> promise.all() or q package, q.all (), it fails with error message from 
> external server, saying invalid json/JSON parsing error.
>  
>            objArr[] =[{"name":"dsd"},
>                  {{"name":"dsd"},}]
>
> *var reqPromises[];*
>
>  
>
> *objArr.forEach(function(obj){*
> *      options.body= obj*
> *     reqPromises.push(request(options)*
> *}*
>
> then-> 
>
> *q.all(reqPromise).then(..).catch(..)*
>
>
>
> Even if object Array has just 1 object, it is  an array  structure which 
> is causing issues. I do not know how it is working, if it is trying to make 
> 1 http request with arrays in json and henec failing. If in loop, means 
> making multiple POST requests, which I want, it should work. 
>
> Please suggest the right approach. Also if any better way to debug and see 
> what JSON is going to server? I use postman to call my local application 
> which talks and sends json to external server.  Usually console/log 
> statements are useful but with request/promises/chaining, its hard to 
> debug. :-(
>

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/93b4893e-2744-41dc-8df7-37bbd166aadf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to