17

I am trying to make a request to an API using the get method in the https module.

Looking at HTTPS request in NodeJS, I've got a long way, but my request doesn't appear to include the query parameters…

Using the example from above, with my mods:

var $q = require('q'),
    _ = require('lodash'),
    path = require('path'),
    Qs = require('qs'),
    path = require('path'),
    uuid = require('node-uuid'),
    https = require('https');

var params = {
  schema: '1.0',
  form: 'json',
  username: 'name'
}
var options = {
  host: 'openshift.redhat.com',
  port: 443,
  path: '/broker/rest/api',
  query: params
};

var req = https.get(options, function(res) {
insertusernamehere
  • 23,204
  • 9
  • 87
  • 126
mediaashley
  • 342
  • 1
  • 3
  • 8

1 Answers1

29

According to https://nodejs.org/api/https.html#https_https_request_options_callback there is no option called "query". You need to include the query parameters to the "path".

Request path. Defaults to '/'. Should include query string if any. E.G. '/index.html?page=12'.

n1try
  • 1,050
  • 14
  • 23
  • That's great! Don't know where I got that `query` option… Apparently I can't accept your answer yet, but I will! Thank you – mediaashley Jun 01 '16 at 11:08
  • 1
    You could also use https://github.com/ljharb/qs to easily serialize an object to a query string and not have to do that string hacking manually. – n1try Jun 01 '16 at 11:12
  • 2
    We are actually using qs, so from the example above, I have: `+ path: '/broker/rest/api' + Qs.stringify(params)`. – mediaashley Jun 01 '16 at 11:50