Two-way Strong ¦ Sign In ¦ New User

Application Programming Interface (API)

 

Introduction

User Account

API Key

Test Environment

Web Application

Login

Token

Session Check

Session Check (Static)

Logout

Logout (Static)

Mobile Application

Mobile Login Check

Key Data Fields

Response Messages

Demo Examples

Powered By (Credit)

Technical Support

 

Logout Function

The software developer can either create an HTML-based logout function or create a new function in their Web server script. For the Web server script implementation, the software developer creates a new function that is similar to the session check function. Data must be sent by form POST method. You need to submit both your API key and a Session ID. These are the two variables that you will prepare and send. The link to the logout function must include the Session ID variable.

Use this URL address to connect to the Test Environment:

https://www.2waystrong.com/ApiUsr/LogoutV01Test

Use this URL address to connect to the Live Environment:

https://www.2waystrong.com/ApiUsr/LogoutV01Live

The logout function will return one of five messages. The software developer would write program code to execute an action according to the message. The following messages are:

  1. User has logged out.
  2. Session ID must be provided.
  3. API Key is not valid.
  4. API Key must be provided.
  5. User ID is not valid.

If the message is "User has logged out.", the recommended action is to return the user to the user login page. The other messages would return an error page.

The provided example is for an ASP.NET MVC application.

        private String UserLogout(string sessionID)
        {
            string postApiURL = "https://www.2waystrong.com/ApiUsr/LogoutV01Live";
            string postApiString = "";
            string requestOutput = "";

            Dictionary postValues = new Dictionary();
            postValues.Add("apiKey", "INSERT API KEY");
            postValues.Add("sessionID", sessionID);

            foreach (KeyValuePair postValue in postValues)
            {
                postApiString += postValue.Key + "=" + postValue.Value + "&";
            }

            postApiString = postApiString.TrimEnd('&');

            try
            {
                WebRequest requestSend = WebRequest.Create(postApiURL);
                requestSend.Method = "POST";
                requestSend.ContentType = "application/x-www-form-urlencoded";
                byte[] byteApiString = Encoding.UTF8.GetBytes(postApiString);
                requestSend.ContentLength = byteApiString.Length;

                Stream requestData = requestSend.GetRequestStream();
                requestData.Write(byteApiString, 0, byteApiString.Length);
                requestData.Close();

                WebResponse requestReceive = requestSend.GetResponse();

                using (requestData = requestReceive.GetResponseStream())
                {
                    StreamReader readData = new StreamReader(requestData);
                    requestOutput = readData.ReadToEnd();
                }

                requestReceive.Close();

                return requestOutput;
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }

Download the complete source code.