curl --request GET \ --url 'https://api.econpay.com.br/customers?page=1&limit=20' \ --header 'Authorization: Bearer SEU_TOKEN_JWT'
{ "data": [ { "id": 1, "name": "João da Silva", "email": "[email protected]", "document": "12345678900", "phone": "+55 11 999999999", "created_at": "2024-01-15T10:30:00Z" }, { "id": 2, "name": "Maria Santos", "email": "[email protected]", "document": "98765432100", "phone": "+55 11 988888888", "created_at": "2024-01-16T14:20:00Z" } ], "total": 150, "page": 1, "lastPage": 8 }
Listar clientes com paginação e filtros
ASC
DESC
Show properties
async function findCustomerByName(name) { const response = await fetch( `https://api.econpay.com.br/customers?name=${encodeURIComponent(name)}`, { headers: { 'Authorization': `Bearer ${token}` } } ); const { data } = await response.json(); return data; } const customers = await findCustomerByName('João'); console.log(`Encontrados ${customers.length} clientes`);
async function findCustomerByDocument(document) { const response = await fetch( `https://api.econpay.com.br/customers?document=${document}`, { headers: { 'Authorization': `Bearer ${token}` } } ); const { data } = await response.json(); return data[0]; // Retorna o primeiro (CPF é único) } const customer = await findCustomerByDocument('12345678900'); if (customer) { console.log(`Cliente encontrado: ${customer.name}`); }
async function getAllCustomers() { const allCustomers = []; let page = 1; let hasMore = true; while (hasMore) { const response = await fetch( `https://api.econpay.com.br/customers?page=${page}&limit=100`, { headers: { 'Authorization': `Bearer ${token}` } } ); const { data, lastPage } = await response.json(); allCustomers.push(...data); hasMore = page < lastPage; page++; } return allCustomers; } const customers = await getAllCustomers(); console.log(`Total de clientes: ${customers.length}`);