Sample code for 30+ languages & platforms
Swift

SugarCRM Logout

See more SugarCRM Examples

Demonstrates how to logout of a session.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let rest = CkoRest()!

    success = rest.connect(hostname: "your.site.domain", port: 443, tls: true, autoReconnect: true)
    if success != true {
        print("\(rest.lastErrorText!)")
        return
    }

    rest.addHeader(name: "Cache-Control", value: "no-cache")
    rest.addHeader(name: "OAuth-Token", value: "<access_token>")

    let sbReq = CkoStringBuilder()!

    let sbJson = CkoStringBuilder()!
    success = rest.fullRequestSb(httpVerb: "POST", uriPath: "/rest/v10/oauth2/logout", requestBody: sbReq, responseBody: sbJson)
    if success != true {
        print("\(rest.lastErrorText!)")
        return
    }

    if rest.responseStatusCode.intValue != 200 {
        print("Received error response code: \(rest.responseStatusCode.intValue)")
        print("Response body:")
        print("\(sbJson.getAsString()!)")
        return
    }

    let json = CkoJsonObject()!
    json.loadSb(sb: sbJson)

    // The following code parses the JSON response.
    // A sample JSON response is shown below the sample code.

    success = json.bool(of: "success")

    // A sample JSON response body that is parsed by the above code:

    // {
    //   "success": true
    // }

    print("Example Completed.")

}