The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

I am trying to create a issue from one instance to another

Ankit kharola
Contributor
December 12, 2024

 

 

resolver.define('createIssue', async () => {
//   try {
//     const bodyData = {
//       fields: {
//         project: {
//           key: 'FL', // Project key in the target Jira instance
//         },
//         summary: 'Issue has been created', // Issue summary
//         issuetype: {
//           name: 'Task',
//         },
//         description: 'This issue is related to a Forge integration', // Issue description
//       },
//     };

//     const targetJiraUrl = 'https://forge-learning1.atlassian.net';
//     const authToken = Buffer.from(
//       'ankit.kharola@google.com:my-auth-token'
//     ).toString('base64');

//     const response = await fetch(`${targetJiraUrl}/rest/api/2/issue`, {
//       method: 'POST',
//       headers: {
//         'Accept': 'application/json',
//         'Content-Type': 'application/json',
//         Authorization: `Basic ${authToken}`,
//       },
//       body: JSON.stringify(bodyData),
//     });

//     console.log('Response Status:', response.status);
//     console.log('Response OK:', response.ok);

//     if (response.ok) {
//       const issue = await response.json(); // Parse JSON on success
//       console.log('Created issue:', issue);
//       return issue;
//     }

//     const errorBody = await response.text(); // Handle errors
//     console.error('Error response body:', errorBody);
//     try {
//       const errorDetails = JSON.parse(errorBody);
//       console.error('Parsed error details:', errorDetails);
//     } catch (parseError) {
//       console.error('Failed to parse error response as JSON:', parseError);
//     }
//     throw new Error(`Failed to create issue: ${response.statusText}`);
//   } catch (error) {
//     console.error('Error during issue creation process:', error.message);
//     throw new Error('Failed to create issue in the target Jira instance');
//   }
// });   the issue is being created but when i try to use await repsonse.json() or await response.text() the code block goes to catch block

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
Answer accepted
vikram
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
December 14, 2024

Hi @Ankit kharola 

 

Try to check the application/json is creating correctly or not in content-type.

or is it creating a empty or any errored json. 

Vikram P

Ankit kharola
Contributor
December 15, 2024

@vikram  Thank you it works now

Like vikram likes this
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events