I tried adding a key for my API but there's a problem with implementing it into my application's code.
I keep on getting a message = Forbidden;
I tried different methods but none of them seems to be working.
I can't really figure out the problem here!
if let jsonData = try? JSONSerialization.data(withJSONObject: dict, options: .prettyPrinted) {
let url = NSURL(string: "\(APIAddress)")!
let request = NSMutableURLRequest(url: url as URL)
request.httpMethod = "PATCH"
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("\(APIKey)", forHTTPHeaderField: "Authorization")
request.httpBody = jsonData
let task = URLSession.shared.dataTask(with: request as URLRequest) { data, response, error in
if error != nil {
print(error?.localizedDescription as Any)
return
}
do {
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary
if let parseJSON = json {
let resultValue = parseJSON["success"]
print("result: \(String(describing: resultValue))")
print(parseJSON)
}
} catch let error as NSError {
print(error)
}
}
task.resume()
}
Please note the method was working before activating the API key on API Gateway