Created
December 15, 2020 17:17
-
-
Save benstjohn/27f22e69370e8fdaae1de13bbc0d87d4 to your computer and use it in GitHub Desktop.
This is for creating a React Native Jira Issue collector In-App! NOTE: You’ll need to import `import base64 from 'react-native-base64';
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code sample uses the 'node-fetch' library: | |
// https://www.npmjs.com/package/node-fetch | |
const fetch = require("node-fetch"); | |
const bodyData = `{ | |
"update": {}, | |
"fields": { | |
"summary": "Main order flow broken", | |
"parent": { | |
"key": "PROJ-123" | |
}, | |
"issuetype": { | |
"id": "10000" | |
}, | |
"components": [ | |
{ | |
"id": "10000" | |
} | |
], | |
"customfield_20000": "06/Jul/19 3:25 PM", | |
"customfield_40000": { | |
"type": "doc", | |
"version": 1, | |
"content": [ | |
{ | |
"type": "paragraph", | |
"content": [ | |
{ | |
"text": "Occurs on all orders", | |
"type": "text" | |
} | |
] | |
} | |
] | |
}, | |
"customfield_70000": [ | |
"jira-administrators", | |
"jira-software-users" | |
], | |
"project": { | |
"id": "10000" | |
}, | |
"description": { | |
"type": "doc", | |
"version": 1, | |
"content": [ | |
{ | |
"type": "paragraph", | |
"content": [ | |
{ | |
"text": "Order entry fails when selecting supplier.", | |
"type": "text" | |
} | |
] | |
} | |
] | |
}, | |
"reporter": { | |
"id": "5b10a2844c20165700ede21g" | |
}, | |
"fixVersions": [ | |
{ | |
"id": "10001" | |
} | |
], | |
"customfield_10000": "09/Jun/19", | |
"priority": { | |
"id": "20000" | |
}, | |
"labels": [ | |
"bugfix", | |
"blitz_test" | |
], | |
"timetracking": { | |
"remainingEstimate": "5", | |
"originalEstimate": "10" | |
}, | |
"customfield_30000": [ | |
"10000", | |
"10002" | |
], | |
"customfield_80000": { | |
"value": "red" | |
}, | |
"security": { | |
"id": "10000" | |
}, | |
"environment": { | |
"type": "doc", | |
"version": 1, | |
"content": [ | |
{ | |
"type": "paragraph", | |
"content": [ | |
{ | |
"text": "UAT", | |
"type": "text" | |
} | |
] | |
} | |
] | |
}, | |
"versions": [ | |
{ | |
"id": "10000" | |
} | |
], | |
"duedate": "2019-05-11", | |
"customfield_60000": "jira-software-users", | |
"customfield_50000": { | |
"type": "doc", | |
"version": 1, | |
"content": [ | |
{ | |
"type": "paragraph", | |
"content": [ | |
{ | |
"text": "Could impact day-to-day work.", | |
"type": "text" | |
} | |
] | |
} | |
] | |
}, | |
"assignee": { | |
"id": "5b109f2e9729b51b54dc274d" | |
} | |
} | |
}`; | |
fetch("https://your-domain.atlassian.com/rest/api/3/issue", { | |
method: "POST", | |
headers: { | |
Authorization: `Basic ${Buffer.from( | |
"[email protected]:<api_token>" | |
).toString("base64")}`, | |
Accept: "application/json", | |
"Content-Type": "application/json", | |
}, | |
body: bodyData, | |
}) | |
.then((response) => { | |
console.log(`Response: ${response.status} ${response.statusText}`); | |
return response.text(); | |
}) | |
.then((text) => console.log(text)) | |
.catch((err) => console.error(err)); | |
// Notes: | |
// fields, issue-type, project, and summary are mandatory for a basic call. | |
// Issue Type id can be got by inspecting the "issue-type" when creating an issue, | |
// It's under the div id="issue-type-single-select" in the input element | |
// Ex: <input type="text" value="10101" data-container-class="issuetype-ss" class="issuetype-field aui-ss-select" id="issuetype" name="issuetype" style="display: none;"> | |
// You'll need to connect an api token to this. Select "Account Settings" in the top right corner under your avatar. Then "Security" then "create and manager api tokens" | |
// For the projectId, go to project settings, inspect automation and find something like this: | |
// <a draggable="false" class="css-1xfx3ew " href="/plugins/servlet/ac/com.codebarrel.addons.automation/cb-automation-project-config?project.key=AJ&project.id=10000" target="_self"><div class="css-1oyzili"><span class="css-ek7kgj"><span class="css-5mekwu" data-item-title="true">Automation</span></span></div></a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
callMe() { | |
const bodyData = `{ | |
"fields": { | |
"summary": "This was sent from a mobile app", | |
"issuetype": { | |
"id": "10106" | |
}, | |
"project": { | |
"id": "10012" | |
} | |
} | |
}`; | |
// https://domain.atlassian.net/projects/AJ/board | |
fetch('https://domain.atlassian.net/rest/api/3/issue', { | |
method: 'POST', | |
headers: { | |
Authorization: `Basic ${base64 | |
.encode('[email protected]:JGTibcJZo0otv36afUix9DFF') | |
.toString('base64')}`, | |
Accept: 'application/json', | |
'Content-Type': 'application/json', | |
}, | |
body: bodyData, | |
}) | |
.then((response) => { | |
console.log(`Response: ${response.status} ${response.statusText}`); | |
return response.text(); | |
}) | |
.then((text) => console.log(text)) | |
.catch((err) => console.error(err)); | |
} | |
//NOTE: You’ll need to import `import base64 from 'react-native-base64'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@valentinbegnis there is a secondary API endpoint for attachments/files you'll have to hit - and then it'll return an ID of that file and I believe you need to add that into the first endpoint for the ticket:
Step 1. Attachment API
Step 2. Get ID from success
Step 3. New issue API endpoint including the ID from step 2