Proper syntax for sending a HTTP GET request
Is this the correct syntax for sending a HTTP GET request in a JavaScript workflow to send, for example:
http://example.test/api/method?foo=bar
const entities = require('@jetbrains/youtrack-scripting-api/entities');
const http = require('@jetbrains/youtrack-scripting-api/http');
…
exports.rule = entities.Issue.onChange({
…
action: (ctx) => {
const connection = new http.Connection('http://example.test/api/method');
const queryParams = [{'name': 'foo', 'value': 'bar}];
const response = connection.getSync(connection, queryParams);
if (response && response.code === 200) {
console.log(response.response);
}
}
…
Please sign in to leave a comment.
Hi G. K.,
I'm Sergey from the YouTrack Team. Thanks for reaching out!
Your original code passes
connectionas the first parameter, butgetSyncexpects a URI string. The correct syntax is:For self-signed certificates, import the certificate into YouTrack's third-party certificates.
To log response errors, use
response.toString():Let me know if you have any questions!
I see an error when I try this:
Okay, my first mistake was passing connection as the first parameter to getSync. Obviously that's not correct. It should be a URI string which is then concatenated with the one passed to http.Connection.
With that fixed, I can access a test endpoint on HTTP.
When I try the real one via HTTPS, however, nothing happens; there is no response, it remained ‘undefined’ and no other indication of error is shown. When I test the HTTPS endpoint using wget, it's necessary to use the --no-check-certificate option since it's a self-signed certificate.
How can I see if that's the problem here, that the HTTPS connection cannot be established?
What's the right way to handle this in YouTrack's http? Is that what the sslKeyName parameter to Connection is for? If so, what's supposed to go in there, the certificate serial number or something else?
It does appear the SSL certificate is the problem, though it's odd how I had to learn of this.
console.log(response) gives:
console.log(response.exception) should return an object according to your docs, but returns:
Why?
How do I ignore the certificate in this case?