how to pass value to empty json object in swift using Alamofire

297 Views Asked by At

I have a api whose body has one dictionary key that is empty value.

Eg. { "customer_name": "name" "request_data": {} }

I am using alamofire for this post request. I am not able to understand what should i pass as a value to this key when calling the api.

My code: Network Service -

func KYCRequestWithTemplate(parameters: KYCRequest_WithTemplateModel, completionHandler: @escaping Handler) {
        let authorizationValue = "Basic authorization value"
        
        let headers: HTTPHeaders = [
            "content-type": "application/json",
            "authorization": "\(authorizationValue)"
        ]
        
        AF.request("url", method: .post, parameters: parameters, encoder: JSONParameterEncoder.default, headers: headers).response { response in
            switch response.result {
            case .success(let data):
                do {
                    let json = try JSONDecoder().decode(KYCRequest_WithTemplate.self, from: data!)
                    print(json)
                    if response.response?.statusCode == 200 || response.response?.statusCode == 201 {
                        completionHandler(.success(json))
                    }else {
                        completionHandler(.failure(.custom(message: "Please check your network connectivity")))
                    }
                }catch {
                    print(error.localizedDescription)
                    completionHandler(.failure(.custom(message: "Please try again")))
                }
                
            case .failure(let error):
                print(error.localizedDescription)
                completionHandler(.failure(.custom(message: "Please try again")))
            }
       

} }

Model :

//for post method
struct KYCRequest_WithTemplateModel: Encodable {
    let customer_identifier: String
    let customer_name: String
    let reference_id: String
    let template_name: String
    let notify_customer: Bool
    let request_details: RequestDetails
    let transaction_id: String
    let generate_access_token: Bool
}

struct RequestDetails: Codable {
}

Calling API: I am getting error here. Please help me understand what shall I pass here as a value

let kycTemplateData = KYCRequest_WithTemplateModel(customer_identifier: "\(mobileNo)", customer_name: "\(userName)", reference_id: "id", template_name: "template_name", notify_customer: true, request_details: "**I am getting error here. Please help me understand what shall I pass here as a value**", transaction_id: "id", generate_access_token: true)
0

There are 0 best solutions below