Update Customer
This endpoint allows updating the customer record in the XGate database.
Endpoint
- Method: PUT
https://api.xgateglobal.com/customer/CUSTOMER_ID
The CUSTOMER_ID value refers to the _id returned when creating a customer.
Integration Test
Simulate updating a customer now.
Test: Update Customer
Request
Required Headers
| Header | Value | Description |
|---|---|---|
Authorization | Bearer <your_token> | JWT authentication token. |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Customer full name. |
document | string | Yes | CPF or CNPJ. |
email | string | No | Customer email for notifications. |
phone | string | No | Customer phone number. |
Responses
Success (200 OK)
Customer data was updated successfully.
{
"message":"Cliente alterado com sucesso"
}
Common Errors
| Status | Message | Likely Reason |
|---|---|---|
| 400 | Bad Request | Customer name and/or document is required. |
| 401 | Unauthorized | • Invalid or expired token. • Missing or invalid header. • IP not allowed. • You are not authorized to perform this action. |
| 409 | Conflict | • The provided name is already registered. • The provided document is already registered. |
| 500 | Internal Server Error | Internal 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:
- Data Correction: Fix typos in
nameor correct thedocument(CPF/CNPJ) if the user provided it incorrectly during registration. - Contact Update: Modify the customer's
emailorphonestrictly for notification and communication purposes, keeping administrative contact data up to date. - 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
- Node.js
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
}
})()