Esta gema es la biblioteca oficial proporcionada por Xtract para interactuar con nuestra API.
Puede leer los documentos de la API directamente desde aquí.
Añade esta línea al Gemfile de tu aplicación:
gem 'xtract-sdk'
Y luego ejecuta:
$> bundle
O instálalo tú mismo como:
$> gem install xtract-sdk
En primer lugar, debes configurar tu API Key obtenida desde la plataforma:
XtractSDK.configure do |config|
config.api_key = 'API_KEY'
end
También puedes pasar la clave al crear el cliente directamente:
client = XtractSDK::Client.new(api_key: 'API_KEY')
A continuación, puede crear un cliente y empezar a hacer peticiones. Ofrecemos una forma cómoda de hacerlo:
client = XtractSDK::Client.new
invoices = client
.invoices
.client_tax_id('SOME_TAX_ID')
.call
invoices.each do |invoice|
puts invoice.id
puts invoice.products
end
Estas son todas las opciones de filtrado:
client_business_name
client_tax_id
provider_business_name
provider_tax_id
date_from
date_to
expiration_date_from
expiration_date_to
number
electronic_authorization_id
created_at_from
created_at_to
accounted ('pending', 'in_progress', 'completed', 'with_errors')
imputed (true, false)
client = XtractSDK::Client.new
invoices = client.invoice(ID)
puts invoice.id
puts invoice.products
client = XtractSDK::Client.new
client.update_invoice(ID, { accounted: 'completed' }) #=> :ok
Puede consultar aquí todas las clases de error que la biblioteca plantea.
Bug reports and pull requests are welcome on GitHub at https://github.com/xtractapp/ruby-sdk.
require 'http'
response = HTTP.get(
'https://api.xtract.app/api/v1/invoices',
headers: {
authorization: 'API_KEY'
},
params: {
provider_tax_id: '123456789'
}
)
puts response.body
const axios = require('axios');
axios
.get(
'https://api.xtract.app/api/v1/invoices',
{
headers: {
authorization: 'API_KEY'
},
params: {
provider_tax_id: '123456789'
}
}
)
.then(res => {
console.log(res.data);
});
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://api.xtract.app/api/v1/invoices?provider_tax_id=123456789")
.addHeader("Authorization", "API_KEY")
.build();
Response response = client.newCall(request).execute();
GsonBuilder builder = new GsonBuilder();
Invoices invoices = builder.create().fromJson(response.body().string(), Invoices.class);
System.out.println(invoices);
This repo contains the code that powers the Xtract API connector library that you can use directly from Google Apps Script. If you don't want to use the library you can copy and modify the code in this repo as you need.
The library's script ID is 1oW5XdZwVg31CSl9LYMEiuvm0BcWz8omozSXqdl9uJxFa-WAPclG4fPwg
First create a new Apps Script Project. This can be done directly here or after creating a new spreadsheet you can click
After this you can start coding the code that will interact between you spreadsheet and the Xtract API.
On your left click
Create 2 sheets one called
Then you can get started with the following example:
const API_KEY = 'CHANGE_WITH_YOUR_ACCOUNT_KEY';
// Add a menu at the top of the spreadsheet to easily execute
const onOpen = () => { // eslint-disable-line
const ui = SpreadsheetApp.getUi();
const menu = ui.createMenu('Xtract');
menu.addItem('Generate report', 'generateReport');
menu.addToUi();
};
// This function gets called after pressing the generate report button
const generateReport = () => { // eslint-disable-line
const invoices = Xtract.fetchInvoices(API_KEY, {});
const rows = [];
invoices.forEach((invoice, idx) => {
rows.push([idx, invoice.number]);
});
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Report');
sheet.clearContents();
sheet.getRange(1, 1, rows.length, rows[0].length).setValues(rows);
};
If you want to add some filters you can do the following:
const API_KEY = 'CHANGE_WITH_YOUR_ACCOUNT_KEY';
const REPORT_SHEET_NAME = 'Report';
const FILTERS_SHEET_NAME = 'Filters';
/*
Location of the filters
- Key is the query param used to call the API
- Value is the cell where you can get the value
*/
const FILTERS_POSITIONS = {
date_from: 'B2',
date_to: 'B3',
provider_tax_id: 'B4',
};
const onOpen = () => { // eslint-disable-line
const ui = SpreadsheetApp.getUi();
const menu = ui.createMenu('Xtract');
menu.addItem('Generate report', 'generateReport');
menu.addToUi();
};
const generateReport = () => { // eslint-disable-line
const filters = Xtract.getFilters(FILTERS_SHEET_NAME, FILTERS_POSITIONS);
const invoices = Xtract.fetchInvoices(API_KEY, filters);
const rows = [];
invoices.forEach((invoice, idx) => {
rows.push([idx, invoice.number]);
});
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(REPORT_SHEET_NAME);
sheet.clearContents();
sheet.getRange(1, 1, rows.length, rows[0].length).setValues(rows);
};
© 2025 Xtract.app