0

This is my api request:

{
"billDetails": {
           "billerId":"EPDCLOB00AN232",
            "customerParams":[{"name":"Service Number","value":"116515M025033"}]
             }
}

here is code:

func billerFetchService(){

let parameters = ["billDetails": {
    "billerId" : "EPDCLOB00ANP01",
    "customerParams" : [{"name":"Service Number","value":"116515M025007621"}]
                                 }
                  ] as [String : Any]


let url = URL(string: "https://app.com/Fetch/fetch")
var req =  URLRequest(url: url!)
req.httpMethod = "POST"
req.addValue("application/json", forHTTPHeaderField: "Contet-Type")
req.addValue("application/json", forHTTPHeaderField: "Accept")

guard let httpBody = try? JSONSerialization.data(withJSONObject: parameters, options: .prettyPrinted) else {return}
req.httpBody = httpBody
let session = URLSession.shared
session.dataTask(with: req, completionHandler: {(data, response, error) in
    if response != nil {
        // print(response)
    }
    if let data = data {
        do{
            var json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as! [String: Any]
            print("fetching json \(json)")

        }catch{
            print("error")
        }
    }
}).resume()
}

if i add like this in parameters error

Consecutive statements on a line must be separated by ';'
Insert ';' Expected expression

Where i did mistake, please help me in code

2 Answers 2

1

You need

let parameters = ["billDetails": [
    "billerId" : "EPDCLOB00ANP01",
    "customerParams" : [["name":"Service Number","value":"116515M025007621"]]]]
Sign up to request clarification or add additional context in comments.

Comments

1

Please make your parameter as this

 let parameters = ["billDetails":
         [
          "billerId": "EPDCLOB00ANP01",
         "customerParams" : ["name":"Service Number","value":"116515M025007621"]
        ]
        ] as [String : Any]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.