Sample code for 30+ languages & platforms
Swift

qa.factura1.com.co Obtain Auth Token

See more HTTP Misc Examples

Demonstrates how to send a JSON POST to get an authenticataion token for qa.factura1.com.co

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    let http = CkoHttp()!

    // Build the following JSON
    // {
    //   "password": "MY_PASSWORD",
    //   "username": "MY_USERNAME"
    // }

    let json = CkoJsonObject()!
    json.emitCompact = false
    json.updateString(jsonPath: "password", value: "MY_PASSWORD")
    json.updateString(jsonPath: "username", value: "MY_USERNAME")

    let resp = CkoHttpResponse()!
    success = http.httpJson(verb: "POST", url: "https://qa.factura1.com.co/v2/auth", json: json, contentType: "application/json", response: resp)
    if success == false {
        print("\(http.lastErrorText!)")
        return
    }

    let jsonResp = CkoJsonObject()!
    jsonResp.emitCompact = false
    jsonResp.load(json: resp.bodyStr)

    print("\(jsonResp.emit()!)")

    print("Access token: \(jsonResp.string(of: "token")!)")

}