Hello all,
I am running into some strange issues with a few GET requests when trying to use them in Xcode.
Here’s an example:
func getAllNFTs(contractAddress:String,completion:@escaping (Int) -> ()) {
let url = URL(string: "https://deep-index.moralis.io/api/v2//nft/0x3686b85EBA862553546bB8735f225008cc597238?chain=mumbai&format=decimal")
var request = URLRequest(url: url!)
request.httpMethod = "GET"
request.setValue("application/json", forHTTPHeaderField: "accept")
request.setValue("My-API-Key", forHTTPHeaderField: "X-API-Key")
URLSession.shared.dataTask(with: request) {(data, response, error) in
if let responseData = try? JSONDecoder().decode(GetAllNFTResponse.self, from: data!) {
let total = responseData.total
print("\(total)")
}
}
.resume()
}
When I run the function, I’m met with the error “{“message”:“API KEY missing from x-api-key header”}” in the console.
The equivalent curl request works just fine:
curl -X 'GET' \
'https://deep-index.moralis.io/api/v2/nft/0x3686b85EBA862553546bB8735f225008cc597238?chain=mumbai&format=decimal' \
-H 'accept: application/json' \
-H 'X-API-Key: My-API-Key'
I can run POST requests and pass the through to a view without a problem.:
Has anyone else run into this?