I am trying to make a POST call between my rocketchat server and Jira server. However it seems that I might be missing a step as in rocketchat logs it say the executionar ran succesfully, but when I check Jira server, no new activity has happend
curl -u username:password -X POST --data “my_data_goes_here”
-H “Content-Type: application/json”
This curl works perfectly in CMD so I am trying to replicate it within my rocketchat app. The code is:
import fetch from ‘node-fetch’;
IHttp,
IModify,
IRead,
} from '@rocket.chat/apps-engine/definition/accessors';
import {
ISlashCommand,
SlashCommandContext,
} from '@rocket.chat/apps-engine/definition/slashcommands';
import axios from 'axios';
export class test implements ISlashCommand {
public command = 'test';
public i18nParamsExample = '';
public i18nDescription = '';
public providesPreview = false;
public async executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp): Promise<void> {
const user = 'user';
const pass = 'password';
const url1 = 'http://localhost:8080/rest/api/2/issue/';
const data1 ={ "fields": { "project": { "key": "HUS" },"summary": "1", "description": "2","issuetype": { "name": "Bug" }}};
var btoa = require('btoa');
const resp = fetch('http://hdahash-02:8080/rest/api/2/issue/',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic ' + btoa('user:password')
},
body: data1
}).then(response => {
console.log(response.json())})
.then(data => {
console.log(data);
});
console.log(resp.data);
}
};```
The return from response.json is :
Promise {
[Symbol(async_id_symbol)]: 514811,
[Symbol(trigger_async_id_symbol)]: 514809,
[Symbol(destroyed)]: [Object]}
AND resp.data comes back as undefined
Also if there are any files within rocketchat that creates POST calls as such, please let me know so I can use it for learning purposes