Skip to main content

Update Customer

This endpoint allows updating the customer record in the XGate database.


Endpoint​

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

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


Integration Test​

Simulate updating a customer now.

🔄

Test: Update Customer

1. Your Credentials

2. Which customer do you want to update?
Don't have a client? Click here to create

3. New Registration 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 (200 OK)​

Customer data was updated successfully.

{
"message":"Cliente alterado com sucesso"
}

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 update route is a data-modification endpoint. It allows changing the registration information of a user that already exists in your XGate database.

Common Use Cases​

Use this endpoint primarily for user account maintenance scenarios:

  1. Data Correction: Fix typos in name or correct the document (CPF/CNPJ) if the user provided it incorrectly during registration.
  2. Contact Update: Modify the customer's email or phone strictly for notification and communication purposes, keeping administrative contact data up to date.
  3. Profile Synchronization: Ensure that whenever the customer updates profile data in your app or site, the change is reflected automatically in the XGate ecosystem.

Practical Example​

The primary purpose of this route is to apply changes and confirm the success of the operation without returning large volumes of data. By requesting the update with the customer's _id in the URL and sending the new information in the body, the API will process the change and return a simple confirmation.

1. What you receive when updating the customer successfully:

{
"message":"Cliente alterado com sucesso"
}

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 = "***********";
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.put(`${url_api}/customer/${customerId}`, customer, {
headers: {
"Authorization": `Bearer ${login.data.token}`
}
});
console.log(data); // Response
} catch (error) {
console.log(error.response.data.message) // Error
}
})()