Skip to main content
POST
/
platform
/
v1
/
sessions
cURL
curl --request POST \
  --url https://api.moonpay.com/platform/v1/sessions \
  --header 'Content-Type: application/json' \
  --header 'X-Api-Key: <api-key>' \
  --data '
{
  "deviceIp": "0.0.0.0",
  "externalCustomerId": "<string>",
  "email": "jsmith@example.com",
  "phoneNumber": "<string>"
}
'
import requests

url = "https://api.moonpay.com/platform/v1/sessions"

payload = {
    "deviceIp": "0.0.0.0",
    "externalCustomerId": "<string>",
    "email": "jsmith@example.com",
    "phoneNumber": "<string>"
}
headers = {
    "X-Api-Key": "<api-key>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
  method: 'POST',
  headers: {'X-Api-Key': '<api-key>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    deviceIp: '0.0.0.0',
    externalCustomerId: '<string>',
    email: 'jsmith@example.com',
    phoneNumber: '<string>'
  })
};

fetch('https://api.moonpay.com/platform/v1/sessions', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.moonpay.com/platform/v1/sessions",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'deviceIp' => '0.0.0.0',
    'externalCustomerId' => '<string>',
    'email' => 'jsmith@example.com',
    'phoneNumber' => '<string>'
  ]),
  CURLOPT_HTTPHEADER => [
    "Content-Type: application/json",
    "X-Api-Key: <api-key>"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.moonpay.com/platform/v1/sessions"

	payload := strings.NewReader("{\n  \"deviceIp\": \"0.0.0.0\",\n  \"externalCustomerId\": \"<string>\",\n  \"email\": \"jsmith@example.com\",\n  \"phoneNumber\": \"<string>\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("X-Api-Key", "<api-key>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.moonpay.com/platform/v1/sessions")
  .header("X-Api-Key", "<api-key>")
  .header("Content-Type", "application/json")
  .body("{\n  \"deviceIp\": \"0.0.0.0\",\n  \"externalCustomerId\": \"<string>\",\n  \"email\": \"jsmith@example.com\",\n  \"phoneNumber\": \"<string>\"\n}")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://api.moonpay.com/platform/v1/sessions")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-Api-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"deviceIp\": \"0.0.0.0\",\n  \"externalCustomerId\": \"<string>\",\n  \"email\": \"jsmith@example.com\",\n  \"phoneNumber\": \"<string>\"\n}"

response = http.request(request)
puts response.read_body
{
  "sessionToken": "<string>"
}
{
  "code": 400,
  "type": "<string>",
  "message": "<string>"
}

Authorizations

X-Api-Key
string
header
required

Secret key authentication via the X-Api-Key header.

Example: X-Api-Key: <secretKey>

Body

application/json
deviceIp
required

The IP address of the user's device to ensure the integrity of the session. Both IPv4 and IPv6 values are supported.

Example:

"0.0.0.0"

externalCustomerId
string

A unique identifier for the customer from your system.

Required string length: 1 - 255
Example:

"user_01AN4Z07BY"

email
string<email>

The customer's email address. Must be a valid email. If provided, enables email OTP authentication.

Required string length: 5 - 255
Example:

"user@example.com"

phoneNumber
string

The customer's phone number in E.164 format. If both email and phone are provided, enables phone OTP authentication for returning customers.

Pattern: ^\+[1-9]\d{1,14}$
Example:

"+14155551234"

Response

The request has succeeded.

sessionToken
string
required

An opaque session token used to set up a connection on your frontend. This token is single-use and must be generated each time the customer visits your app.

Token expires 24 hours after issuance.

Required string length: 1 - 8192
Example:

"c2Vzc2lvbi50b2tlbg"