Skip to main content

Create Customer

This endpoint creates a new customer record in the XGate database.

Creating a customer is the first step in the integration, as it returns the Customer ID (_id), which is required for:

  1. Registering Pix keys.
  2. Generating collection QR Codes.
  3. Performing Withdrawals.

💡 Note: When creating a customer, the system automatically and in parallel generates all individualized cryptocurrency wallet addresses for them.


Endpoint​

  • Method: POST
Endpoint URL
https://api.xgateglobal.com/customer

Integration Test​

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

👤

Test: Create New Customer

1. Your Credentials

2. New Customer Data

Request​

Required Headers​

HeaderValueDescription
AuthorizationBearer <your_token>JWT authentication token.

Request Body​

FieldTypeRequiredDescription
namestringYesCustomer full name.
documentstringYesCPF or CNPJ.
emailstringNoCustomer email for notifications.
phonestringNoCustomer phone number.

Responses​

Success (201 Created)​

The customer was created successfully and is available for use.

{
"message": "Novo cliente criado com sucesso",
"customer": {
"_id": "696d1f3331117************",
"name": "Name Client",
"email": "email@domain",
"document": "123***********"
}
}

Customer Already Registered (200 OK)​

A customer with the same name and/or document already exists. When the server returns this response, it includes the existing customer's _id.

{
"message": "Cliente já está cadastrado na base de dados",
"customer": {
"_id": "68e7b8f0dbed************"
}
}

Common Errors​

StatusMessageLikely Reason
400Bad RequestCustomer name and/or document is required.
401Unauthorized• Invalid or expired token.
• Missing or invalid header.
• IP not allowed.
• You are not authorized to perform this action.
409Conflict• The provided name is already registered.
• The provided document is already registered.
500Internal Server ErrorInternal server error. Contact support.

How to use​

The Customer ID (_id) is the unique identifier that links the user to all financial and management operations within the platform.

You will need this ID for:

  1. Transactions: Identify source/destination in Deposits and Withdrawals.
  2. Pix Keys: Create, list, or remove keys linked to the customer.
  3. Management: Update the customer's registration data.

Integration Flow​

  1. Generate token: Obtain a token at the authentication route (POST /auth/token) to be authorized to create customers.
  2. Create the customer: Send the request payload to the route (POST /customer) providing the name and document fields.

Practical Example​

To credit funds (Deposit), include the customer ID in the customerId field of the payload.

1. What you receive when creating the customer:

{
"message": "Novo cliente criado com sucesso",
"customer": {
"_id": "696d1f3331117************",
"name": "Name Client",
"email": "email@domain",
"document": "123***********"
}
}

2. How to use the Deposit route (POST /deposit):

{
"amount": 0.2,
"customerId": "696d1f3331117************",
"currency": {
"_id": "6728f0a2cba3**************",
"name": "BRL",
"type": "PIX",
"createdDate": "2024-11-04T16:04:50.019Z",
"updatedDate": "2024-11-07T02:23:38.606Z",
"__v": 0,
"symbol": "R$"
}
}

The customer ID is passed as customerId to create a deposit request.

Integration Tip

Always store the customer's _id immediately after creation. You will use it in 100% of future calls related to this user.


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 customer = {
name: "Name client",
phone: "119*******",
email: "your_email@domain.com",
document: "000000*******"
}

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