exaconnect-node-sdk
v2.1.2
Published
Exaconnect node.js SDK
Downloads
14
Readme
exaconnect-node-sdk
Node.js SDK for exaconnect webservice (https://www.exaprint.fr/).
Installation
npm i exaconnect-node-sdk
Usage
By default, a production configuration is setup and and exempts you to use the configure
method, but if you feel the need to use a custom configuration, you can still use the method as the example below.
const exaconnect = require('exaconnect-node-sdk');
exaconnect.configure({
schema: 'http',
hostname: 'stg-connect.exaprint.fr'
});
exaconnect
.createClient()
.then(console.log)
.catch(console.error);
Methods
getToken
Promise example :
const exaconnect = require('exaconnect-node-sdk');
exaconnect
.createClient()
.then(client =>
client.getToken({
username: '[email protected]',
password: 'secret'
})
)
.then(console.log)
.catch(console.error);
async/await example :
const exaconnect = require('exaconnect-node-sdk');
(async () => {
const client = await exaconnect.createClient();
const token = await client.getToken({
username: '[email protected]',
password: 'secret'
});
console.log(token);
})().catch(console.error);
createOrder
Promise example :
const exaconnect = require('exaconnect-node-sdk');
exaconnect
.createClient()
.then(client =>
Promise.all([
client,
client.getToken({
username: '[email protected]',
password: 'secret'
})
])
)
.then(([client, token]) =>
client.createOrder({
token: token,
order: {
reference: 'My first automated order',
product: '25086',
quantity: 100,
openedFormatLength: '8.6',
openedFormatWidth: '5.4',
closedFormatLength: '0',
closedFormatWidth: '0',
comment: '',
address: {
contactName: 'M. Dupond',
line1: '1 Place Georges Frêche',
line2: '',
line3: '',
doorCode: '#3412',
mail: '[email protected]',
phone: '0432000000',
mobile: '0660000000',
city: 'Montpellier',
zipCode: '34000',
country: 'FR',
comment: ''
}
}
})
)
.then(console.log)
.catch(console.error);
async/await example :
const exaconnect = require('exaconnect-node-sdk');
(async () => {
const client = await exaconnect.createClient();
const token = await client.getToken({
username: '[email protected]',
password: 'secret'
});
const order = await client.createOrder({
token: token,
order: {
reference: 'My first automated order',
product: '25086',
quantity: 100,
openedFormatLength: '8.6',
openedFormatWidth: '5.4',
closedFormatLength: '0',
closedFormatWidth: '0',
comment: '',
address: {
contactName: 'M. Dupond',
line1: '1 Place Georges Frêche',
line2: '',
line3: '',
doorCode: '#3412',
mail: '[email protected]',
phone: '0432000000',
mobile: '0660000000',
city: 'Montpellier',
zipCode: '34000',
country: 'FR',
comment: ''
}
}
});
console.log(order);
})().catch(console.error);
createOrderFromPartnerOrder
Promise example :
const exaconnect = require('exaconnect-node-sdk');
exaconnect
.createClient()
.then(client =>
Promise.all([
client,
client.getToken({
username: '[email protected]',
password: 'secret'
})
])
)
.then(([client, token]) =>
client.createOrderFromPartnerOrder({
token: token,
order: {
reference: 'My first automated order from partner order',
partnerOrderId: 327999,
comment: '',
address: {
contactName: 'M. Dupond',
line1: '1 Place Georges Frêche',
line2: '',
line3: '',
doorCode: '#3412',
mail: '[email protected]',
phone: '0432000000',
mobile: '0660000000',
city: 'Montpellier',
zipCode: '34000',
country: 'FR',
comment: ''
}
}
})
)
.then(console.log)
.catch(console.error);
async/await exemple :
const exaconnect = require('exaconnect-node-sdk');
(async () => {
const client = await exaconnect.createClient();
const token = await client.getToken({
username: '[email protected]',
password: 'secret'
});
const orderFromPartnerOrder = await client.createOrderFromPartnerOrder({
token: token,
order: {
reference: 'My first automated order from partner order',
partnerOrderId: 327999,
comment: '',
address: {
contactName: 'M. Dupond',
line1: '1 Place Georges Frêche',
line2: '',
line3: '',
doorCode: '#3412',
mail: '[email protected]',
phone: '0432000000',
mobile: '0660000000',
city: 'Montpellier',
zipCode: '34000',
country: 'FR',
comment: ''
}
}
});
console.log(orderFromPartnerOrder);
})().catch(console.error);
setOrderStateAsFileTransferred
Promise example :
const exaconnect = require('exaconnect-node-sdk');
exaconnect
.createClient()
.then(client =>
Promise.all([
client,
client.getToken({
username: '[email protected]',
password: 'secret'
})
])
)
.then(([client, token]) =>
client.setOrderStateAsFileTransferred({
token: token,
orders: [5591277, 5591389]
})
)
.then(console.log)
.catch(console.error);
async/await example :
const exaconnect = require('exaconnect-node-sdk');
(async () => {
const client = await exaconnect.createClient();
const token = await client.getToken({
username: '[email protected]',
password: 'secret'
});
const updatedOrders = await client.setOrderStateAsFileTransferred({
token: token,
orders: [5591277, 5591389]
});
console.log(updatedOrders);
})().catch(console.error);
getOrders
Promise example :
const exaconnect = require('exaconnect-node-sdk');
exaconnect
.createClient()
.then(client =>
Promise.all([
client,
client.getToken({
username: '[email protected]',
password: 'secret'
})
])
)
.then(([client, token]) =>
client.getOrders({
token: token,
dateFilterMin: '20200101',
dateFilterMax: '20200701',
statusFilter: 24,
page: 1
})
)
.then(console.log)
.catch(console.error);
async/await example :
const exaconnect = require('exaconnect-node-sdk');
(async () => {
const client = await exaconnect.createClient();
const token = await client.getToken({
username: '[email protected]',
password: 'secret'
});
const orders = await client.getOrders({
token: token,
dateFilterMin: '20200101',
dateFilterMax: '20200701',
statusFilter: 24,
page: 1
});
console.log(orders);
})().catch(console.error);
getOrderStatus
Promise example :
const exaconnect = require('exaconnect-node-sdk');
exaconnect
.createClient()
.then(client =>
Promise.all([
client,
client.getToken({
username: '[email protected]',
password: 'secret'
})
])
)
.then(([client, token]) =>
client.getOrderStatus({
token: token,
orders: [5591277, 5591389]
})
)
.then(console.log)
.catch(console.error);
async/await example :
const exaconnect = require('exaconnect-node-sdk');
(async () => {
const client = await exaconnect.createClient();
const token = await client.getToken({
username: '[email protected]',
password: 'secret'
});
const ordersStatus = await client.getOrderStatus({
token: token,
orders: [5591277, 5591389]
});
console.log(ordersStatus);
})().catch(console.error);
cancelOrder
Promise example :
const exaconnect = require('exaconnect-node-sdk');
exaconnect
.createClient()
.then(client =>
Promise.all([
client,
client.getToken({
username: '[email protected]',
password: 'secret'
})
])
)
.then(([client, token]) =>
client.cancelOrder({
token,
order: { orderId: 5591277, reason: 'File error' }
})
)
.then(console.log)
.catch(console.error);
async/await example :
const exaconnect = require('exaconnect-node-sdk');
(async () => {
const client = await exaconnect.createClient();
const token = await client.getToken({
username: '[email protected]',
password: 'secret'
});
const cancelledOrder = await client.cancelOrder({
token,
order: { orderId: 5591277, reason: 'File error' }
});
console.log(cancelledOrder);
})().catch(console.error);
More examples
You can find more examples in the example
directory of this repository.
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
License
MIT