Search code examples
iosswiftalamofire

Having issues with Alamofire and api keys


I am trying to connect my app with an api (https://collegescorecard.ed.gov/data/documentation/) and I do not know why I am getting this error with Alamo thanks!

"Cannot convert value of type 'String' to expected argument type 'HTTPHeaders?' (aka 'Optional>')"

func callAPI() {
        let url = URL(string:URLStr)
        let key = "Key redacted"
        Alamofire.request(url!, method: .get, parameters: nil, headers:key)

        }

Solution

  • Key should be with your url

    let key = "Key redacted"
    let url = URL(string:"\(urlStr)?key=\(key)") 
    Alamofire.request(url!, method: .get, parameters: nil, headers:[:])