Marvel API 409 response, "You must provide a user key"

Viewed 2483

Wondering if anyone can help me here:

    private static func getURLRequestData(completion: @escaping (Data?) -> ()) {

    // Gets the raw JSON Data

    let session = URLSession(configuration: .default)
    guard let url = URL(string: urlString) else { return }
    var urlRequest = URLRequest(url: url)

    let headers = [
        "ts" : ts,
        "apikey" : apiKey,
        "hash" : hash,
        "limit" : limit,
        "orderBy" : orderedBy
    ]

    urlRequest.allHTTPHeaderFields = headers

    let task = session.dataTask(with: urlRequest) { (data, response, error) in

        if error != nil {
            print(#line, error!.localizedDescription)
        }

        print(response)
        completion(data)
    }
    task.resume()
}

As you can see, I am setting the headers correctly with my API Key but for some reason I'm getting a 409 return which is a missing "user key".

Has anyone experienced anything like this. For what its worth, the exact same request is working in Paw

1 Answers

You must provide informations according documentation link documentation here

Example:

var publickey = 'you-public-key';
var privatekey = 'you-private-key';
var ts = new Date().getTime();
var stringToHash = ts + privatekey + publickey;
var hash = md5(stringToHash);
var baseUrl = 'https://gateway.marvel.com:443/v1/public/characters';
var limit = 20;
var url = baseUrl + '?limit=' + limit + '&ts=' + ts + '&apikey=' + publickey + '&hash=' + hash;
Related