Chilkat Online Tools

Android / Salesforce Platform APIs / Passwordless Login - Initialize

Back to Collection Items

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    CkHttp http = new CkHttp();
    boolean success;

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "username": "<username>",
    //   "recaptcha": "<recaptcha-token>",
    //   "verificationmethod": "email or sms"
    // }

    CkJsonObject json = new CkJsonObject();
    json.UpdateString("username","<username>");
    json.UpdateString("recaptcha","<recaptcha-token>");
    json.UpdateString("verificationmethod","email or sms");

    CkHttpResponse resp = http.PostJson3("https://login.salesforce.com{{site}}/services/auth/headless/init/passwordless/login","application/json",json);
    if (http.get_LastMethodSuccess() == false) {
        Log.i(TAG, http.lastErrorText());
        return;
        }

    Log.i(TAG, String.valueOf(resp.get_StatusCode()));
    Log.i(TAG, resp.bodyStr());


  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

Curl Command

curl -X POST
	-d '{
    "username": "<username>",
    "recaptcha": "<recaptcha-token>",
    "verificationmethod": "email or sms"
}'
https://login.salesforce.com{{site}}/services/auth/headless/init/passwordless/login

Postman Collection Item JSON

{
  "name": "Passwordless Login - Initialize",
  "protocolProfileBehavior": {
    "disabledSystemHeaders": {
      "content-type": true
    }
  },
  "request": {
    "auth": {
      "type": "noauth"
    },
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"username\": \"<username>\",\n    \"recaptcha\": \"<recaptcha-token>\",\n    \"verificationmethod\": \"email or sms\"\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{url}}{{site}}/services/auth/headless/init/passwordless/login",
      "host": [
        "{{url}}{{site}}"
      ],
      "path": [
        "services",
        "auth",
        "headless",
        "init",
        "passwordless",
        "login"
      ]
    },
    "description": "Submits the passwordless login data to the init/passwordless/login endpoint and returns a request identifier. At the same time, an OTP is sent out to the end users via email or sms. Passwordless login data is passed in the request body, and is formatted with JSON, with 3 keys: `username`, `recaptcha`, and `verificationmethod`. All 3 keys are strings.\n\nThis request returns JSON, and includes an identifier (request identifier)."
  },
  "response": [
  ]
}