Skip to main content

Add Pix Key

This endpoint allows registering a new Pix key (Email, CPF, CNPJ, Phone or Random) for your end customer.


Endpoint​

  • Method: POST
Endpoint URL
https://api.xgateglobal.com/pix/customer/CLIENT_ID/key
Important

The CLIENT_ID field refers to the customer ID; if you haven't created it yet, you can create it from the create customers page.


Test Integration​

Use the form below to simulate registering a real Pix key.

➕

Test: Add Pix Key

1. Your Credentials

2. Which customer will receive the key?
Don't have a client? Click here to create

3. New Key Data

Request​

Required Headers​

HeaderValueDescription
AuthorizationBearer <your_token>JWT authentication token.

URL Parameters​

ParameterTypeRequiredDescription
CLIENT_IDstringYesThe _id of the customer to whom you want to add the Pix key.

Request Body​

FieldTypeRequiredDescription
keystringYesThe Pix key value (ex: your@email.com, +551199...).
typestringYesThe key type.
Accepted values: EMAIL, CPF, CNPJ, PHONE, RANDOM.

Responses​

Success (201 Created)​

The key was successfully registered and is ready for use.

{
"message": "Chave Pix adicionada com sucesso",
"key": {
"key": "444***********",
"type": "CPF",
"_id": "696c604456f8***********"
}
}

Common Errors​

StatusMessageLikely Cause
400Bad RequestThe provided Pix key is not valid.
401Unauthorized• Invalid or expired token.
• Invalid or missing header.
• IP not allowed.
404Not Found• Pix key already registered.
• Pix key does not correspond to a valid CPF.
• Customer not found.
500Internal Server ErrorInternal server error. Contact support.

How to use​

The main purpose of adding Pix keys is to allow the user to perform a withdrawal (Withdraw) using the newly created key.

The response from this endpoint immediately provides the Full Object of the key, which is required when building the withdrawal payload.

Integration Flow​

  1. Register the key: Call this endpoint (POST /pix/customer/CLIENT_ID/key).
  2. Capture: The API will return the created key data. Store this object.
  3. Submit: You must pass the entire object received inside the pixKey property in the withdrawal payload.
Format Warning

Do not send incomplete Pix key data. The withdrawal payload expects the complete JSON object containing key, type and _id.

Practical Example​

1. What you receive when creating a Pix key:


{
"message": "Chave Pix adicionada com sucesso",
"key": {
"key": "+5512**********",
"type": "PHONE",
"_id": "68fa5d5400**********"
}
}

2. How you should send it in the Withdrawal (POST /withdraw):

You will take the object above and inject it inside pixKey:

{
"amount": 0.2,
"customerId": "68e7b8****************",
"currency": {
"_id": "67339fa800****************",
"name": "BRL",
"type": "PIX",
"symbol": "R$",
"createdDate": "2024-11-12T18:34:16.289Z",
"updatedDate": "2024-11-12T18:34:16.289Z",
"__v": 0
},
"pixKey": {
"key": "+5512**********",
"type": "PHONE",
"_id": "68fa5d5400**********"
}
}

Each field in this JSON is explained on the withdrawals page.


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 = "12************";
const key = "+55***********";
const type = "PHONE";

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