I am building an app that checks domain availability. Right now, I am using the goDaddy API; according to goDaddy, the way to check URL availability is by the following cURL command:
curl -X GET -H "Authorization: sso-key {API_KEY}:{API_SECRET}" "https://api.godaddy.com/v1/domains/available?domain=example.guru"
Right now, I am trying to translate that cURL command to Swift. I am using Alamofire; however, when I make a request, an error as the following shows up:
Credentials must be specified
I was wondering how to solve this problem. Here is my current code:
class ViewController: UIViewController {
let key = "KEYKEYKEY"
let secret = "SECRETSECRET"
var headers: HTTPHeaders = [:]
override func viewDidLoad() {
super.viewDidLoad()
let credential = URLCredential(user: key, password: secret, persistence: .forSession)
Alamofire.request("https://api.godaddy.com/v1/domains/available?domain=example.guru")
.authenticate(usingCredential: credential)
.responseJSON { response in
debugPrint(response)
}
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}