LogIn

Authenticates with the M2M Platform and returns a session token that you can use in subsequent API requests.

Uses and Requirements

Best Practices for Managing Sessions

A session token will remain valid as long as your application continues to use it, but it will expire after 20 minutes of inactivity. The Best Practice to build into your application for using the LogIn API is:

This is more efficient than logging in to get a new token before every API request.

NOTE: The M2M Platform will lock an account after 5 consecutive failed login attempts. You must contact M2M Support to get the account unlocked.

C# Code to Test for Expired Token

Send requests in a try-catch block and use this code to detect when a token is expired.

 catch (FaultException ex)
 {
   if (ex.Code.Name.Contains("SessionToken.Expired"))
   {
     // call your Login() method again
     // then resend the last request
   }
 }

Java Code to Test for Expired Token

Send requests in a try-catch block and use this code to detect when a token is expired.

 catch (AxisFault e1) {
   if (e1.getFaultCode().getLocalPart().contains("SessionToken.Expired")) {
     // call your Login() method again
     // then resend the last request
   } 
 }

Request Parameters

Parameter Type Description
Username
required
string The user name for authentication.
Password
required
string The password for authentication.

Response Parameters

The session token is returned in the token element in the header of the response and in the SessionToken element in the body.

Parameter Type Description
SessionToken string The identifier for the session that was created by the LogIn request.

Example SOAP Request

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:v2="http://nphase.com/unifiedwebservice/v2"
  xmlns:nph="http://schemas.datacontract.org/2004/07/NPhase.UnifiedWebService.APIs.v2.Contract.SessionService">
  <soapenv:Header/>
  <soapenv:Body>
    <v2:LogIn>
      <v2:Input>
        <nph:Username>username</nph:Username>
        <nph:Password>password</nph:Password>
      </v2:Input>
    </v2:LogIn>
  </soapenv:Body>
</soapenv:Envelope>

Example SOAP Response

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Header>
    <token xmlns="http://nphase.com/unifiedwebservice/v2">ef308d7a-790f-4feb-b807-c9e4f890780a</token>
  <soapenv:Header/>
  <soapenv:Body>
    <LogInResponse xmlns="http://nphase.com/unifiedwebservice/v2">
      <Output xmlns:a="http://schemas.datacontract.org/2004/07/NPhase.UnifiedWebService.APIs.v2.Contract.SessionService"
xmlns:i="http://www.w3.org/2001/XMLSchema- instance">
        <a:SessionToken>ef308d7a-790f-4feb-b807-c9e4f890780a</a:SessionToken>
      </Output>
    </LogInResponse>
  </soapenv:Body>
</soapenv:Envelope>

Request Schema Diagram

Response Schema Diagram