Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,555,779
Community Members
 
Community Events
184
Community Groups

Using REST API to edit issue - CURL succeeds, programmatically fails

Janene Pappas
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 Leaders.
Sep 17, 2020

I'm trying to use the Jira REST API to update issues programmatically via a MacOS program, written in Swift. I have a Jira API Token and have succeeded using CURL. Here is the command: 

curl --request PUT \
  --url 'https://xxxx.atlassian.net/rest/api/2/issue/SAN-2' \
  --user 'xxx@yyy.com:zzz' \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{
"update": {
"timetracking": [
{
"edit": {
"originalEstimate": "1w 1d"
}
}
]
}
}'

Where zzz is the API Token. This works and the field is updated correctly. 

The code version mirrors this as closely as I can, but fails with the error 

Response: {"errorMessages":["Issue does not exist or you do not have permission to see it."],"errors":{}}

Here is the Swift code: 

        let tokenString = "xxx@yyy.com:zzz"

        guard let encodedTokenString = tokenString.data(using: .utf8)?.base64EncodedData() else { fatalError("Can't encode token") }

        let authString = String("Token token=\(encodedTokenString)")

        guard let url = URL(string: "https://xxxx.atlassian.net/rest/api/2/issue/SAN-2")

        else {
            fatalError("Couldn't create a static URL")
        }

        let request = NSMutableURLRequest(url: url)

        request.addValue(authString, forHTTPHeaderField: "Authorization")

        request.addValue("application/json", forHTTPHeaderField: "Content-Type")

        request.httpMethod = "PUT"

        let dataString = "{\"update\": {\"timetracking\": [{\"edit\": {\"originalEstimate\": \"1w 1d\"}}]}}".utf8

        let body = Data(dataString)    

        request.httpBody = body

        let session = URLSession.shared

        session.dataTask(with: request as URLRequest) { (data, response, error) -> Void in

            guard let data = data, let responseString = NSString(data: data, encoding: String.Encoding.utf8.rawValue) as String?, !responseString.isEmpty else {
                print("No valid response!")
                return
            }
            print("Response: " + responseString)

       
}.resume()

What am I missing? 

1 answer

1 accepted

0 votes
Answer accepted
DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 17, 2020

@Janene Pappas I'm not a Swift expert but your 'authString' have some issues.

let authString = String("Token token=\(encodedTokenString)")

This should be (in my opinion)

let authString = String("Basic \(encodedTokenString)")
Janene Pappas
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 Leaders.
Sep 18, 2020

ahhhh thank you!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events