Skip to main content

Customer Lookup

This endpoint queries the customer record in the XGate database.


Endpoint​

  • Method: GET
Endpoint URL
https://api.xgateglobal.com/customer/CUSTOMER_ID
Important

The CUSTOMER_ID value refers to the _id returned when creating a customer.

Integration Tip: Retrieving an ID

The XGate API uses the name field as a validation key for customers. If you lost a user's _id, submit a Create Customer request using the same name. The server will detect the existing name and return a friendly error containing the existing record's _id, allowing you to update your internal database.


Integration Test​

Simulate creating a customer now. The result will show the generated _id.

🔍

Test: Consult Customer

1. Your Credentials

2. Query Data
Don't have a client? Click here to create

Request​

Required Headers​

HeaderValueDescription
AuthorizationBearer <your_token>JWT authentication token.

Responses​

Success (200 OK)​

Customer data was found.

{
"_id": "697e15******************",
"name": "Client Name",
"email": "email@domain.com",
"document": "123********",
"version": 1,
"createdDate": "202****************",
"updatedDate": "202****************"
}

Common Errors​

StatusMessageLikely Reason
401Unauthorized• Invalid or expired token.
• Missing or invalid header.
• IP not allowed.
• You are not authorized to perform this action.
404Not Found• Provided ID is not valid.
The customer does not exist.
500Internal Server ErrorInternal server error. Contact support.

How to use​

The customer query route is a read-only endpoint. Use it to retrieve and verify the current data of a user already registered in your XGate database.

Common Use Cases​

Unlike payment routes, there is no complex flow here. Use this endpoint mainly for:

  1. Audit and Verification: Confirm that the document (CPF/CNPJ) or email linked to the customer are correct.
  2. Pre-Update Validation: Fetch the user's current registration data to pre-fill an "Edit Profile" screen in your front-end.
  3. Database Synchronization: Ensure your internal database remains up-to-date and in sync with XGate.

Practical Example​

The primary purpose is quick, secure data viewing. By requesting the customer using its _id, you will receive the complete customer object.

1. What you receive when querying the customer:

Note in the example below how the route returns the vital information, allowing you to verify the document (highlighted line):

{
"_id": "697e15******************",
"name": "Client Name",
"email": "email@domain.com",
"document": "123********",
"version": 1,
"createdDate": "202****************",
"updatedDate": "202****************"
}

Integration​

The integration example uses the Axios library in Node.js.

Installing Axios:

npm install axios

JavaScript example:

const axios = require("axios");

(async () => {
const email = "your_email@domain.com";
const password = "**********";
const customerId = "***********";

try {
const url_api = "https://api.xgateglobal.com"
const login = await axios.post(`${url_api}/auth/token`, { email, password });
const { data } = await axios.get(`${url_api}/customer/${customerId}`, {
headers: {
"Authorization": `Bearer ${login.data.token}`
}
});
console.log(data); // Response
} catch (error) {
console.log(error.response.data.message) // Error
}
})()