Membership Contracts
Generate customer portal authentication token
Generates the token that signs the customer in to the Memberships customer portal. It is the token that manage-subscription-link puts in its link, returned on its own. To send a customer to the portal, call manage-subscription-link instead: it returns the full link. Call it from your server, never from a browser, where your API key would be exposed.
Finding the customer:
- Send
customerIdoremail. If you send both,customerIdis used andemailis ignored customerIdtakes a number or agid://shopify/Customer/ID, and isn’t looked up: any customer ID gets a token, so send a Shopify customer ID you knowemailonly finds a customer who has, or had, a membership on the store, using the email saved on that membership. URL-encode it, because+in an address must be sent as%2B- If
emailmatches no membership, or you send neither parameter, the call returns 400
How the token works:
- The response has
customerIdandtoken - The token is opaque: it isn’t a JWT and can’t be decoded
- It is valid for 2 hours from when it was generated, and can be used any number of times until then
- It works for that customer on your store only
- Generate a new token when you need one, and treat tokens like passwords
Authentication: Send a Read & Write API key in the X-API-Key header. A Read only key gets 403.
GET
/
api
/
external
/
v2
/
customer-portal-token
Generate customer portal authentication token
curl --request GET \
--url https://membership-admin.appstle.com/api/external/v2/customer-portal-tokenimport requests
url = "https://membership-admin.appstle.com/api/external/v2/customer-portal-token"
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('https://membership-admin.appstle.com/api/external/v2/customer-portal-token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));const url = 'https://membership-admin.appstle.com/api/external/v2/customer-portal-token';
const options = {method: 'GET'};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://membership-admin.appstle.com/api/external/v2/customer-portal-token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://membership-admin.appstle.com/api/external/v2/customer-portal-token"
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}require 'uri'
require 'net/http'
url = URI("https://membership-admin.appstle.com/api/external/v2/customer-portal-token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body{
"customerId": 6789012345,
"token": "TOKEN"
}{
"errorKey": "invalidCustomer",
"message": "Customer Id or Email does not exist",
"params": "",
"status": 400,
"title": "Customer Id or Email does not exist",
"type": "https://appstle.com/problem/problem-with-message"
}{
"detail": "API key can not be blank.",
"message": "error.http.401",
"path": "/api/external/v2/customer-portal-token",
"status": 401,
"title": "Unauthorized"
}{
"detail": "This API key is read-only and cannot perform write operations.",
"status": 403,
"title": "Forbidden"
}Query Parameters
⌘I
Generate customer portal authentication token
curl --request GET \
--url https://membership-admin.appstle.com/api/external/v2/customer-portal-tokenimport requests
url = "https://membership-admin.appstle.com/api/external/v2/customer-portal-token"
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('https://membership-admin.appstle.com/api/external/v2/customer-portal-token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));const url = 'https://membership-admin.appstle.com/api/external/v2/customer-portal-token';
const options = {method: 'GET'};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://membership-admin.appstle.com/api/external/v2/customer-portal-token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://membership-admin.appstle.com/api/external/v2/customer-portal-token"
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}require 'uri'
require 'net/http'
url = URI("https://membership-admin.appstle.com/api/external/v2/customer-portal-token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body{
"customerId": 6789012345,
"token": "TOKEN"
}{
"errorKey": "invalidCustomer",
"message": "Customer Id or Email does not exist",
"params": "",
"status": 400,
"title": "Customer Id or Email does not exist",
"type": "https://appstle.com/problem/problem-with-message"
}{
"detail": "API key can not be blank.",
"message": "error.http.401",
"path": "/api/external/v2/customer-portal-token",
"status": 401,
"title": "Unauthorized"
}{
"detail": "This API key is read-only and cannot perform write operations.",
"status": 403,
"title": "Forbidden"
}