0

I've got this function to fetch a JSON API, but I need to set custom parameters.

Here is the function:

func fetchTipsJson(completion: @escaping (Result<Root, Error>) -> ()) {
        let urlString = "http://telemedapi_dev.assistcard.com/Api/Config/GetConfigGroupList"
        guard let url = URL(string: urlString) else { return }

        URLSession.shared.dataTask(with: url) { (data, resp, err) in
            // Error
            if let err = err {
                completion(.failure(err))
                return
            }

            // Successful
            do {
                let tips = try JSONDecoder().decode(Root.self, from: data!)
                completion(.success(tips))

                print(tips)
            } catch let jsonError {
                completion(.failure(jsonError))
            }
        }.resume()
    }

And here are the parameters:

{
    "Parameters": {
        "CountryCode": 540,
        "ConfigurationPath": "TelemedGlobalConfig>Tips",
        "LogApiCallsStatus": 2
    },
    "VisitorIp": null,
    "ApplicationName": null,
    "CurrentUICulture": "es-ES"
}

How can I do this? I can't find anything. Notice that I'm using the new Result from Swift 5, don't know if that changes anything.

vukurigusi
  • 17
  • 6
  • Those are parameters that you need to send with the request? – dan Jun 12 '19 at 20:46
  • If so, see: https://stackoverflow.com/questions/31937686/how-to-make-http-post-request-with-json-body-in-swift – dan Jun 12 '19 at 20:47
  • 1
    Possible duplicate of [How to make HTTP Post request with JSON body in Swift](https://stackoverflow.com/questions/31937686/how-to-make-http-post-request-with-json-body-in-swift) – Kyle Willmon Jun 12 '19 at 21:31

0 Answers0