I'm running into a strange bug, and I'm not sure if it's on my end or not. I'm building a CLI for ZenDesk; one of the things it does is allow the user to list macros, and optionally control the sort order by using an option: -s <sort>
. If this option is not specified, my code defaults to alphabetical
. See below:
console.log(options.sort); // undefined
client.macros.listByParams({
sort_by: options.sort ? options.sort : `alphabetical`
}, (err, req, result) => {
if (err) throw err;
// do something with result
});
Above, no sort
option was passed, and the request URI is built correctly:
{ stores:
{ defaults:
Literal {
type: 'literal',
store: [Object],
mtimes: {},
readOnly: true,
loadFrom: null,
logicalSeparator: ':' } },
sources: [],
headers:
{ 'Content-Type': 'application/json',
Accept: 'application/json',
'User-Agent': 'node-zendesk/1.1.8 (node/5.6.0)',
Authorization: 'Basic <hidden>' },
uri: 'https://vimeo.zendesk.com/api/v2/macros.json?sort_by=alphabetical',
method: 'GET' }
{ statusCode: 200,
result: ... }
However, when the user does pass in a sort value (for example, usage_7d
), something strange happens to the request URI:
console.log(options.sort); // 'usage_7d'
client.macros.listByParams({
sort_by: options.sort ? options.sort : `alphabetical`
}, (err, req, result) => {
if (err) throw err;
// do something with result
});
{ stores:
{ defaults:
Literal {
type: 'literal',
store: [Object],
mtimes: {},
readOnly: true,
loadFrom: null,
logicalSeparator: ':' } },
sources: [],
headers:
{ 'Content-Type': 'application/json',
Accept: 'application/json',
'User-Agent': 'node-zendesk/1.1.8 (node/5.6.0)',
Authorization: 'Basic <hidden>' },
uri: 'https://usage_7d.zendesk.com/api/v2/macros.json?sort_by=usage_7d',
method: 'GET' }
{ statusCode: 404,
result: ... }
Note that the request URI has becomes https://usage_7d.zendesk.com/api/v2/macros.json?sort_by=usage_7d
. The param is appended correctly, but the subdomain has also changed to usage_7d
.
The relevant code can be viewed in context here.
Any help would be much appreciated!