Can I make external api call(it is post api call to trigger jenkins job) from atlasin jira?
Asked by Kindinti Anumanthu:

I would like to trigger jenkins job remotely from Atlasian jira page.

I'm getting 500 interal server or connection refused errors.

```
But when try this from Postman from local system with my corporate vpn it works fine

Here is the forge UI code:

import ForgeUI, { render, Fragment, Text, Button, Strong, Form, Select, Option, IssuePanel, useProductContext, useState } from '@forge/ui'; import api, { route,fetch } from '@forge/api'; import qs from 'qs'; const App = () => { const [selectedValues, setSelectedValues] = useState([]); const [buttonClicked, setButtonClicked] = useState(false); const context = useProductContext(); const issueKey = context.platformContext.issueKey; const projectKey = context.platformContext.projectKey; const handleClick = async () => { try { console.log("Starting application with values:", selectedValues); setButtonClicked(true); await triggerJenkinsJob(selectedValues); } catch (error) { console.error('Error executing the app:', error); } }; const onSubmit = (formData) => { setSelectedValues(formData.options || []); }; return (          {selectedValues.length > 0 && You selected: {selectedValues.join(', ')}}  {buttonClicked && Test has been triggered. Results will be sent to your mail.}  ); }; export const run = render(    ); const triggerJenkinsJob = async (selectedValues) => { console.log("Starting Jenkins job"); const jenkinsUrl = "https://cilas.blackline.corp/job/Execute_SAP_Smart_Close_ComponentTestingTests"; const jenkinsToken = "11a41681dec535c7651a374d6ad9f1dc3b"; const username = "kindinti.anumanthu"; const categories = ["sap-smartclose-entity", ...selectedValues]; await executeJenkinsJob(jenkinsUrl, username, jenkinsToken, categories); }; const executeJenkinsJob = async (jenkinsUrl, jenkinsUser, jenkinsToken, categories) => { const buildUrl = `${jenkinsUrl}/buildWithParameters`; console.log("Inside Jenkins method"); let parameters = { DataCenter: 'LAS', EnvironmentType: 'T - Test', Environment: 'T6', Branch: 'master', Filter: 'category=sap-smartclose-entity', SapSystem: 'P5D', Browser: 'Chrome', Language: 'en-US', CaptureScreenshots: 'false', TestRetry: 'Disable', CloseTestRun: 'false', NetworkLogging: 'false', Rerun: 'true', MailList: 'kindinti.anumanthu@blackline.com', ToolsBranch: 'master' }; const auth = Buffer.from(`${jenkinsUser}:${jenkinsToken}`).toString('base64'); console.log(`Request URL: ${buildUrl}`); console.log(`Autorization code: ${auth}`); console.log(`Parameters: ${new URLSearchParams(parameters).toString()}`); console.log(`Parameters qs: ${qs.stringify(parameters)}`); try { const response = await api.fetch(buildUrl, { method: 'POST', headers: { 'Authorization': `Basic ${auth}`, 'Content-Type': 'application/x-www-form-urlencoded' }, body: new URLSearchParams(parameters).toString() }); console.log(`Request URL: ${buildUrl}`); console.log(`Response: ${response.status} - ${response.statusText}`); const responseData = await response.json().catch(() => { }); if (responseData) { console.log(`Response Content: ${JSON.stringify(responseData)}`); } else { console.log('No response data received.'); } if (response.status >= 200 && response.status < 300) { console.log('Jenkins job triggered successfully.'); } else { console.log(`Failed to trigger Jenkins job: ${response.status} - ${response.statusText}`); } } catch (error) { console.error('Exception occurred:', error.message); } };
 
```

<br />

<br />

<br />

This is my manfest fie:  

<br />

modules: jira:issuePanel: - key: jiraprtesting1-hello-world-issue-panel function: main title: JiraPRTesting1 icon: <https://developer.atlassian.com/platform/forge/images/icons/issue-panel-icon.svg> function: - key: main handler: index.run permissions: scopes: - storage:app - read:jira-work - write:jira-work external: fetch: backend: - "cilas.blackline.corp" app: id: ari:cloud:ecosystem::app/8320d2d9-b00d-41f1-818f-1c4be718ed78 runtime: name: nodejs18.x


Answers:
author: Trudy Claspill
body: Hello [@Kindinti Anumanthu](/t5/user/viewprofilepage/user-id/5538696)

Welcome to the Atlassian community.

Is the API you are calling accessible from the internet? Jira Cloud is running in the internet, so the API you are trying to reach will need to be accessible from the internet.

comments: author: Kindinti Anumanthu
body: Yes it is accessible  

<br />

<br />


author: Trudy Claspill
body: Have you researched the root causes of 500 errors and worked through the debugging suggestions related to that?

You said you tried it from a local system on the corporate VPN.

Have you tried it while not on the corporate VPN?

Have you tried it from a generic system on the internet, like your personal system?


Tags: cloud

jira-service-management

jira-service-management-cloud