Jira Cloud: Create an Issue
See more Jira Examples
Create an issue and capture its key and ID for later requests. First use creation metadata to choose an issue type and discover required fields. The sample assumes the selected project/type permits summary and description without additional required fields; add any required values reported by your site's metadata.
Running the example creates a real issue and can trigger notifications and automation. A successful create returns HTTP 201. If a network failure leaves the outcome uncertain, check Jira before retrying so you do not create a duplicate.
The code uses an Atlassian account email and an API token without scopes with the site URL. For a scoped API token, keep Basic authentication and change baseUrl to https://api.atlassian.com/ex/jira/YOUR_CLOUD_ID. For OAuth2, use that gateway URL, omit Login/Password/BasicAuth, and set http.AuthToken to the access token. See API token authentication and OAuth2 authorization. The account must have permission for the operation; OAuth scopes do not grant additional Jira permissions.
Targets Jira Cloud. Jira Data Center has a separate REST API and may require different paths, authentication, or payloads.
Atlassian REST API documentation
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoHttp
String sBaseUrl
Handle hoUrl
Variant vResp
Handle hoResp
Handle hoReply
Variant vRequest
Handle hoRequest
String sTemp1
Integer iTemp1
Integer iTemp2
Boolean bTemp1
Move False To iSuccess
// Assumes Chilkat is unlocked. See Global Unlock Sample.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Set ComRequireSslCertVerify Of hoHttp To True
Set ComBasicAuth Of hoHttp To True
// Read these credentials from private application configuration.
Set ComLogin Of hoHttp To "YOUR_ATLASSIAN_EMAIL"
Set ComPassword Of hoHttp To "YOUR_API_TOKEN"
Move "https://your-domain.atlassian.net" To sBaseUrl
Set ComAccept Of hoHttp To "application/json"
Get Create (RefClass(cComChilkatStringBuilder)) To hoUrl
If (Not(IsComObjectCreated(hoUrl))) Begin
Send CreateComObject of hoUrl
End
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
If (Not(IsComObjectCreated(hoResp))) Begin
Send CreateComObject of hoResp
End
Get Create (RefClass(cComChilkatJsonObject)) To hoReply
If (Not(IsComObjectCreated(hoReply))) Begin
Send CreateComObject of hoReply
End
Get Create (RefClass(cComChilkatJsonObject)) To hoRequest
If (Not(IsComObjectCreated(hoRequest))) Begin
Send CreateComObject of hoRequest
End
Get ComUpdateString Of hoRequest "fields.project.key" "PROJECT" To iSuccess
// Use the issue type ID returned for this project, not a universal hard-coded ID.
Get ComUpdateString Of hoRequest "fields.issuetype.id" "YOUR_ISSUE_TYPE_ID" To iSuccess
Get ComUpdateString Of hoRequest "fields.summary" "Example issue" To iSuccess
// Jira v3 rich text is an Atlassian Document Format (ADF) document.
Get ComUpdateString Of hoRequest "fields.description.type" "doc" To iSuccess
Get ComUpdateInt Of hoRequest "fields.description.version" 1 To iSuccess
Get ComUpdateString Of hoRequest "fields.description.content[0].type" "paragraph" To iSuccess
Get ComUpdateString Of hoRequest "fields.description.content[0].content[0].type" "text" To iSuccess
Get ComUpdateString Of hoRequest "fields.description.content[0].content[0].text" "An issue created through the REST API." To iSuccess
Get ComSetString Of hoUrl sBaseUrl To iSuccess
Get ComAppend Of hoUrl "/rest/api/3/issue" To iSuccess
Get ComGetAsString Of hoUrl To sTemp1
Get pvComObject of hoRequest to vRequest
Get pvComObject of hoResp to vResp
Get ComHttpJson Of hoHttp "POST" sTemp1 vRequest "application/json" vResp To iSuccess
Get ComStatusCode Of hoResp To iTemp1
If (iTemp1 = 0) Begin
Showln "No HTTP response was received. Check connectivity and TLS settings."
Procedure_Return
End
Get ComStatusCode Of hoResp To iTemp1
Get ComStatusCode Of hoResp To iTemp2
If ((iSuccess <> True) Or (iTemp1 < 200) Or (iTemp2 >= 300)) Begin
Get ComStatusCode Of hoResp To iTemp1
Showln "Request failed. HTTP " iTemp1
Get ComStatusCode Of hoResp To iTemp1
If (iTemp1 = 429) Begin
Get ComGetHeaderField Of hoResp "Retry-After" To sTemp1
Showln "Rate limited. Retry-After: " sTemp1
End
// Inspect this response locally; it can contain private Jira data.
Get ComBodyStr Of hoResp To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComBodyStr Of hoResp To sTemp1
Get ComLoad Of hoReply sTemp1 To iSuccess
If (iSuccess <> True) Begin
Showln "Expected a JSON object in the response."
Procedure_Return
End
Get ComJsonTypeOf Of hoReply "key" To iTemp1
Get ComStringOfEquals Of hoReply "key" "" True To bTemp1
If ((iTemp1 <> 1) Or (bTemp1 = True)) Begin
Showln "Missing value: key"
Procedure_Return
End
Get ComStringOf Of hoReply "key" To sTemp1
Showln "Created issue: " sTemp1
Get ComStringOf Of hoReply "id" To sTemp1
Showln "Issue ID: " sTemp1
End_Procedure