Customers | Check Customer exists

Checking Customer Existence

This document provides guidance on using the get_customer_exists API endpoint to verify the existence of a customer in the database. This is particularly useful for login validation and checking if an email is already registered.

Using the get_customer_exists Endpoint

To check whether a customer exists, use the get_customer_exists endpoint. This is primarily used for login forms to verify customer existence based on their email address.

Endpoint and Method

  • Endpoint: https://easycms.fi/public_api/get_customer_exists/
  • Method: POST

Required Parameters | Payload

To perform a check, the following parameters are required:

  • TOKEN (api_key): Your unique API key for authentication. How to Create API Credentials.
  • username: Your API username.
  • password: Your API password.
  • account: Your API account.
  • email: The email address to check for existing customer accounts.

Purpose of the Check

  • Login Validation: To determine if a customer with the given email address exists, which is essential for login processes.
  • Email Registration Check: To verify if a customer's email is already registered in the system. The endpoint returns the total number of accounts found for the email (usually, there is only one account per email).

Notes

  • No additional filters are available for this endpoint.
  • The primary argument required is the email of the customer.



Call Examples in Different Languages


curl -X POST 'https://easycms.fi/public_api/get_customer_check' \
-H 'Authorization1: TOKEN' \
-d 'username=USERNAME&password=PASSWORD&account=ACCOUNT_ID&email=customer@mail.com'

$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => "https://easycms.fi/public_api/get_customer_check",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_POST => true,
  CURLOPT_POSTFIELDS => http_build_query(['username' => 'USERNAME', 'password' => 'PASSWORD', 'account' => 'ACCOUNT_ID', 'email' => 'customer@mail.com']),
  CURLOPT_HTTPHEADER => array("Authorization1: TOKEN"),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;

import requests
url = "https://easycms.fi/public_api/get_customer_check"
headers = {"Authorization1": "TOKEN"}
payload = {'username': 'USERNAME', 'password': 'PASSWORD', 'account': 'ACCOUNT_ID', 'email': 'customer@mail.com'}
response = requests.post(url, headers=headers, data=payload)
print(response.text)

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://easycms.fi/public_api/get_customer_check"))
    .headers("Authorization1", "TOKEN")
    .POST(HttpRequest.BodyPublishers.ofString("username=USERNAME&password=PASSWORD&account=ACCOUNT_ID&email=customer@mail.com"))
    .build();
HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());

const https = require('https');
const data = new URLSearchParams({ 
  username: 'USERNAME', 
  password: 'PASSWORD', 
  account: 'ACCOUNT_ID',
  email: 'customer@mail.com'
}).toString();
const options = {
  hostname: 'prolasku.fi',
  path: '/public_api/get_customer_check',
  method: 'POST',
  headers: {
    'Authorization1': 'TOKEN',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Content-Length': data.length
  }
};
const req = https.request(options, (res) => {
  let data = '';
  res.on('data', (chunk) => { data += chunk; });
  res.on('end', () => { console.log(data); });
});
req.on('error', (e) => { console.error(e); });
req.write(data);
req.end();

import React, { useEffect, useState } from 'react';
function App() {
  const [categoryData, setCategoryData] = useState('');
  useEffect(() => {
    const fetchData = async () => {
      try {
        const response = await fetch('https://easycms.fi/public_api/get_customer_check', {
          method: 'POST',
          headers: {'Authorization1': 'TOKEN', 'Content-Type': 'application/x-www-form-urlencoded'},
          body: new URLSearchParams({username: 'USERNAME', password: 'PASSWORD', account: 'ACCOUNT_ID', email: 'customer@mail.com'}).toString()
        });
        const data = await response.text();
        setCategoryData(data);
      } catch (error) {
        console.error(error);
      }
    };
    fetchData();
  }, []);
  return (
{categoryData}
); } export default App;

// Kotlin example requires using a third-party library like OkHttp for POST requests with a body
// Kotlin Example using OkHttp for POST request
import okhttp3.OkHttpClient
import okhttp3.FormBody
import okhttp3.Request

fun main() {
    val client = OkHttpClient()

    val formBody = FormBody.Builder()
        .add("username", "USERNAME")
        .add("password", "PASSWORD")
        .add("account", "ACCOUNT_ID")
        .add("email", "customer@mail.com")
        .build()

    val request = Request.Builder()
        .url("https://easycms.fi/public_api/get_customer_check")
        .post(formBody)
        .addHeader("Authorization1", "TOKEN")
        .build()

    client.newCall(request).execute().use { response ->
        if (!response.isSuccessful) throw IOException("Unexpected code $response")

        println(response.body?.string())
    }
}

using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
    static async Task Main()
    {
        var token = "TOKEN";
        var content = new FormUrlEncodedContent(new[]
        {
            new KeyValuePair("username", "USERNAME"),
            new KeyValuePair("password", "PASSWORD"),
            new KeyValuePair("account", "ACCOUNT_ID"),
            new KeyValuePair("email", "customer@mail.com")
        });
        using (var httpClient = new HttpClient())
        {
            httpClient.DefaultRequestHeaders.Add("Authorization1", token);
            var response = await httpClient.PostAsync("https://easycms.fi/public_api/get_customer_check", content);
            if (response.IsSuccessStatusCode)
            {
                var responseData = await response.Content.ReadAsStringAsync();
                Console.WriteLine(responseData);
            }
            else
            {
                Console.WriteLine($"Error: {response.StatusCode}");
            }
        }
    }
}




Handling Endpoint Results

When you make a request to the endpoint, you receive a JSON response containing various keys and values. Here's an explanation of the response keys and their meanings:


# Interpretation of `get_customer_exists` Endpoint Response
This section explains how to interpret the response from the `get_customer_exists` API endpoint, which is crucial for understanding whether a customer exists in the database.

## Understanding the Response
When you query the `get_customer_exists` endpoint, the response will include a key named `"TOTAL_COUNT"`. This key provides the count of customer accounts associated with the provided email address.

### Response Format
The response will be in the following format:

json
{
  "TOTAL_COUNT": integer [0 or 1]
}

    

{
    "INFO": {
        "start": 0,
        "limit": 50,
        "count": 1,
        "total_count": 0,
        "tip": "if customer exists, then OUTPUT > TOTAL_COUNT will return a number more than 0"
    },
    "OUTPUT": {
        "TOTAL_COUNT": 1
    }
}
    

Error Handling

Here are the possible error messages and their meanings:

  • UN-AUTHORIZED - _user_name_password_is_set_but_wrong_value!: Incorrect username or password.
  • this_account_does_not_exist_or_your_credentials_do_not_match_this_account: The account doesn't exist or mismatched credentials.
  • UN-AUTHORIZED - header is set but the header value is not correct!: Incorrect authorization header value.
  • Maximum query size is 50 rows per query: Exceeded maximum limit of 50 rows per query.