I'm trying to use JAMF Pro API.
In order to use it is required to generate an authentication token that will be passed with request.
I am coding this in Swift for an App. I have done this successfully with Classic API but can’t get it to work in JAMF Pro API
I am having difficulty generating this authentication token and have not found documentation to help.
Here is what I did find.
Thread that gives a basic outline of how it is done. discussion
In the discussion this is how it said that it should be done.
We're working to get some official documentation up on the Developer Portal for the Jamf Pro API. In the meantime, you can request a token by sending a POST to _uapi_auth/tokens with the header “Authorization: Basic YOUR_CREDENTIALS” where YOUR_CREDENTIALS is base64 encoded credentials for an appropriate Jamf Pro server account. You'll receive a response back containing a token and an expiration epoch. You can use the generated token to make calls to any other Jamf Pro API endpoint by including it in a header using the format “Authorization: jamf-token <TOKEN_VALUE>”.
I followed the instructions
- Do a POST request
- The url is https://xxxeval.jamfcloud.com/uapi/auth/tokens
- I did the Authorization: Basic YOUR_CREDENTIALS” where YOUR_CREDENTIALS is base64 encoded credentials for an appropriate Jamf Pro server account.
Here is the Swift code
let credentialData = "(user):(password)".data(using: String.Encoding.utf8)!
let base64Credentials = credentialData.base64EncodedString()
let sessionConfig = URLSessionConfiguration.default
let session = URLSession(configuration: sessionConfig, delegate: nil, delegateQueue: nil)
guard let url = URL(string: "https://xxxeval.jamfcloud.com/uapi/auth/tokens") else {return}
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.addValue("Authorization: Basic (base64Credentials)", forHTTPHeaderField: "Authorization")
I get back a 401 - Authentication failed. Verify the credentials being used for the request.
If anyone can help with a working example or point me where I can find documentation or just offer some information, I would greatly appreciate it.
As it is now I am at my wits end.
Thanks
