Monday 25 March 2019

noob question re request, qs and passing params

hi guys​I"m new to node and using nodejs request & qs to query a rest API call to retrieve products. For exampledomain/products/?searchCriteria[filter_groups][0][filters][0][field]=sku&searchCriteria[filter_groups][0][filters][0][value]=24-MB06 ​I'm trying to build this call as a promise call & also use "qs" to handle the param part.I can convert the above to something like this params = {searchCriteria: { "filterGroups":[{"filters":[{"field":"sku","value":'24-MB06'}]}]}} and pass it to qs like thisconst qs = require('qs'); const request = require('request'); return new Promise((resolve, reject) => { request({ uri: uri, method: method, headers: headers, rejectUnauthorized: false, qs: params, body: JSON.stringify(data) }, (err, response, body) => {.... ... }​However, I can't really figureout if say I need to add another param to the params string &fields=items[sku,name]while still maintain the above promise & qs approach (like the above)(A test postman call like the one below works just fine)domain/products/?searchCriteria[filter_groups][0][filters][0][field]=sku&searchCriteria[filter_groups][0][filters][0][value]=24-MB06&fields=items[sku,name] I'm hoping to get some tips from the communityThank you​​

Submitted March 25, 2019 at 11:43AM by duyth

No comments:

Post a Comment