Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.