Skip to content

Instantly share code, notes, and snippets.

@yanmendes
Created February 8, 2025 15:45
Show Gist options
  • Save yanmendes/ab9a09a03e77940080cb98dd1c138cee to your computer and use it in GitHub Desktop.
Save yanmendes/ab9a09a03e77940080cb98dd1c138cee to your computer and use it in GitHub Desktop.
require('dotenv').config()
const fs = require('fs')
const axios = require('axios')
const FormData = require('form-data')
const pages = 20;
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
const main = async () => {
const body = new FormData()
const authBody = ({
scope: 'bankweb',
grant_type: 'password',
username: process.env.CAYENA_USERNAME,
password: process.env.CAYENA_PASSWORD
})
Object.keys(authBody).map(k => body.append(k, authBody[k]))
const { data: { access_token } } = await axios.request({
url: 'https://api-stg.cayena.io/authorization-server-web/oauth/token',
method: 'POST',
headers: {
Authorization: `Basic ${process.env.CAYENA_PUBLIC_TOKEN}`,
'Content-Type': 'application/x-www-form-urlencoded'
},
data: body
})
const orders = []
for(let i = 0; i < pages; i++) {
const response = await axios.post('https://api-stg.cayena.io/payment-rest-api/order-suppliers/list?size=500&page=0', {}, {
headers: {
Authorization: `Bearer ${access_token}`
}
})
orders.push(...response.data.content)
sleep(5000)
}
return orders
}
const parseOrders = orders =>
orders.map(o => o.orderNumber)
main()
.then(parseOrders)
.then(orderIds => fs.writeFileSync('./ids.json', JSON.stringify(orderIds)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment