Skip to content

Instantly share code, notes, and snippets.

@NickJosevski
Last active April 8, 2016 11:53
Show Gist options
  • Save NickJosevski/a2b5a4c63ee9cdacb58bb3ee9576004a to your computer and use it in GitHub Desktop.
Save NickJosevski/a2b5a4c63ee9cdacb58bb3ee9576004a to your computer and use it in GitHub Desktop.
Cookie based authentication with JIRA (F# and RestSharp)
open RestSharp
type PostData = {
body: string
}
type Login = {
username : string
password : string
}
let uname = "admin"
let pw = "your-password"
let restClient = RestSharp.RestClient("https://your-account.atlassian.net")
let authReq =
RestSharp
.RestRequest("/rest/auth/1/session")
.AddJsonBody({ username = uname; password = pw })
let authResponse = restClient.Post authReq
printfn "response StatusCode: %A" authResponse.StatusCode
let cookiesToAdd =
authResponse.Cookies
|> Seq.map (fun x -> (x.Name, x.Value))
let addCommentReq =
RestSharp
.RestRequest("/rest/api/2/issue/Issue-Id/comment")
.AddJsonBody({ body = "a new comment" })
for (name, value) in cookiesToAdd do
printfn "cookie name: %s value: %s" name value
addCommentReq.AddCookie(name, value) |> ignore
let commentResp = restClient.Post addCommentReq
printfn "add comment StatusCode: %A" commentResp.StatusCode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment