mysendingbox 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +505 -148
- package/lib/resources/resourceBase.js +78 -68
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,315 +1,672 @@
|
|
|
1
|
+
|
|
1
2
|
# mysendingbox-node
|
|
2
3
|
|
|
4
|
+
|
|
5
|
+
|
|
3
6
|
[downloads-image]: http://img.shields.io/npm/dm/mysendingbox.svg
|
|
7
|
+
|
|
4
8
|
[npm-url]: https://npmjs.org/package/mysendingbox
|
|
9
|
+
|
|
5
10
|
[npm-image]: https://badge.fury.io/js/mysendingbox.svg
|
|
6
11
|
|
|
7
|
-
|
|
12
|
+
|
|
8
13
|
|
|
14
|
+
[![NPM version][npm-image]][npm-url] [](https://gemnasium.com/github.com/exaland/mysendingbox-node)
|
|
9
15
|
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
10
19
|
|
|
11
20
|
MySendingBox.com Node.js Client is a simple but flexible wrapper for the [MySendingBox.fr](https://www.mysendingbox.fr) API.
|
|
12
21
|
|
|
22
|
+
|
|
23
|
+
|
|
13
24
|
See full Seeuletter.com documentation [here](https://docs.mysendingbox.fr/).
|
|
14
25
|
|
|
26
|
+
|
|
27
|
+
|
|
15
28
|
For best results, be sure that you're using the latest version of the Seeuletter API and the latest version of the Node.js wrapper.
|
|
16
29
|
|
|
30
|
+
|
|
31
|
+
|
|
17
32
|
#### French
|
|
33
|
+
|
|
18
34
|
Un module NPM pour envoyer du courrier postal ou electronique en ligne depuis votre application Node.Js.
|
|
19
35
|
|
|
36
|
+
|
|
37
|
+
|
|
20
38
|
Seeuletter propose une API permettant d'envoyer très facilement du courrier postal ou électronique depuis votre ERP, CRM ou application web.
|
|
21
39
|
|
|
40
|
+
|
|
41
|
+
|
|
22
42
|
Pas de frais d'installation. Pas d'engagement. Vous payez ce que vous consommez.
|
|
23
43
|
|
|
44
|
+
|
|
45
|
+
|
|
24
46
|
Documentation : https://docs.mysendingbox.fr/
|
|
25
47
|
|
|
48
|
+
|
|
49
|
+
|
|
26
50
|
Bien démarrer : https://www.mysendingbox.fr/guide/bien-demarrer-avec-l-api-d-envoi-de-courrier
|
|
27
51
|
|
|
52
|
+
|
|
53
|
+
|
|
28
54
|
## Table of Contents
|
|
29
55
|
|
|
56
|
+
|
|
57
|
+
|
|
30
58
|
- [Getting Started](#getting-started)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
59
|
+
|
|
60
|
+
- [Registration](#registration)
|
|
61
|
+
|
|
62
|
+
- [Installation](#installation)
|
|
63
|
+
|
|
64
|
+
- [Letters](#letters)
|
|
65
|
+
|
|
66
|
+
- [Postcards](#postcards)
|
|
67
|
+
|
|
68
|
+
- [Price](#price) **new update**
|
|
69
|
+
|
|
70
|
+
- [Accounts](#accounts)
|
|
71
|
+
|
|
72
|
+
- [Invoices](#invoices)
|
|
73
|
+
|
|
37
74
|
- [Examples](#examples)
|
|
38
75
|
|
|
76
|
+
|
|
77
|
+
|
|
39
78
|
## Getting Started
|
|
40
79
|
|
|
80
|
+
|
|
81
|
+
|
|
41
82
|
Here's a general overview of the Seeuletter services available, click through to read more.
|
|
42
83
|
|
|
84
|
+
|
|
85
|
+
|
|
43
86
|
Please read through the official [API Documentation](https://docs.mysendingbox.fr/) to get a complete sense of what to expect from each endpoint.
|
|
44
87
|
|
|
88
|
+
|
|
89
|
+
|
|
45
90
|
### Registration
|
|
46
91
|
|
|
92
|
+
|
|
93
|
+
|
|
47
94
|
First, you will need to first create an account at [Seeuletter.com](https://www.mysendingbox.fr/signup) and obtain your Test and Live API Keys.
|
|
48
95
|
|
|
96
|
+
|
|
97
|
+
|
|
49
98
|
Once you have created an account, you can access your API Keys from the [Settings Panel](https://www.mysendingbox.fr/app/dashboard/keys).
|
|
50
99
|
|
|
100
|
+
|
|
101
|
+
|
|
51
102
|
|
|
52
103
|
### Installation
|
|
53
104
|
|
|
105
|
+
|
|
106
|
+
|
|
54
107
|
mysendingbox-node can be installed through the npm:
|
|
55
108
|
|
|
109
|
+
|
|
110
|
+
|
|
56
111
|
```
|
|
112
|
+
|
|
57
113
|
$ npm install -S mysendingbox
|
|
114
|
+
|
|
58
115
|
```
|
|
59
116
|
|
|
117
|
+
|
|
118
|
+
|
|
60
119
|
To build and install from the latest source:
|
|
61
120
|
|
|
121
|
+
|
|
122
|
+
|
|
62
123
|
```
|
|
124
|
+
|
|
63
125
|
$ git clone git@github.com:exaland/mysendingbox-node.git
|
|
126
|
+
|
|
64
127
|
$ npm install
|
|
128
|
+
|
|
65
129
|
```
|
|
66
130
|
|
|
131
|
+
|
|
132
|
+
|
|
67
133
|
### Letters
|
|
68
134
|
|
|
135
|
+
|
|
136
|
+
|
|
69
137
|
#### Create a new letter - Callback style
|
|
138
|
+
|
|
70
139
|
```javascript
|
|
71
|
-
|
|
140
|
+
|
|
141
|
+
var Seeuletter = require('seeuletter')('YOUR API KEY');
|
|
142
|
+
|
|
143
|
+
|
|
72
144
|
|
|
73
145
|
// callback pattern
|
|
146
|
+
|
|
74
147
|
Seeuletter.letters.create({
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
148
|
+
|
|
149
|
+
description: 'Test Letter from the Node.js Wrapper',
|
|
150
|
+
|
|
151
|
+
to: {
|
|
152
|
+
|
|
153
|
+
name: 'Erlich',
|
|
154
|
+
|
|
155
|
+
address_line1: '30 rue de rivoli',
|
|
156
|
+
|
|
157
|
+
address_line2: '',
|
|
158
|
+
|
|
159
|
+
address_city: 'Paris',
|
|
160
|
+
|
|
161
|
+
address_country: 'France',
|
|
162
|
+
|
|
163
|
+
address_postalcode: '75004'
|
|
164
|
+
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
postage_type: 'prioritaire',
|
|
168
|
+
|
|
169
|
+
color: 'bw',
|
|
170
|
+
|
|
171
|
+
source_file: '<html>Hello, {{nom}}</html>',
|
|
172
|
+
|
|
173
|
+
source_file_type: 'html',
|
|
174
|
+
|
|
175
|
+
variables: {
|
|
176
|
+
|
|
177
|
+
nom : 'Seeuletter'
|
|
178
|
+
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
}, function (err, body) {
|
|
182
|
+
|
|
183
|
+
if (err) console.log('err : ' , err.message);
|
|
184
|
+
|
|
185
|
+
console.log('body : ', body)
|
|
186
|
+
|
|
94
187
|
})
|
|
188
|
+
|
|
95
189
|
```
|
|
96
190
|
|
|
191
|
+
|
|
192
|
+
|
|
97
193
|
#### Create a new letter - Promise style
|
|
98
194
|
|
|
195
|
+
|
|
196
|
+
|
|
99
197
|
```javascript
|
|
100
|
-
|
|
198
|
+
|
|
199
|
+
var Seeuletter = require('seeuletter')('YOUR API KEY');
|
|
200
|
+
|
|
201
|
+
|
|
101
202
|
|
|
102
203
|
// promise pattern
|
|
204
|
+
|
|
103
205
|
Seeuletter.letters.create({
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
206
|
+
|
|
207
|
+
description: 'Test Letter from the Node.js Wrapper',
|
|
208
|
+
|
|
209
|
+
to: {
|
|
210
|
+
|
|
211
|
+
name: 'Erlich',
|
|
212
|
+
|
|
213
|
+
address_line1: '30 rue de rivoli',
|
|
214
|
+
|
|
215
|
+
address_line2: '',
|
|
216
|
+
|
|
217
|
+
address_city: 'Paris',
|
|
218
|
+
|
|
219
|
+
address_country: 'France',
|
|
220
|
+
|
|
221
|
+
address_postalcode: '75004'
|
|
222
|
+
|
|
223
|
+
},
|
|
224
|
+
|
|
225
|
+
postage_type: 'prioritaire',
|
|
226
|
+
|
|
227
|
+
color: 'bw',
|
|
228
|
+
|
|
229
|
+
source_file: '<html>Hello, {{nom}}</html>',
|
|
230
|
+
|
|
231
|
+
source_file_type: 'html',
|
|
232
|
+
|
|
233
|
+
variables: {
|
|
234
|
+
|
|
235
|
+
nom : 'Seeuletter'
|
|
236
|
+
|
|
237
|
+
}
|
|
238
|
+
|
|
120
239
|
})
|
|
121
|
-
|
|
122
|
-
|
|
240
|
+
|
|
241
|
+
.then(function (response) {
|
|
242
|
+
|
|
243
|
+
console.log('response : ', response);
|
|
244
|
+
|
|
123
245
|
})
|
|
124
|
-
|
|
125
|
-
|
|
246
|
+
|
|
247
|
+
.catch(function (err) {
|
|
248
|
+
|
|
249
|
+
console.log('err : ', err);
|
|
250
|
+
|
|
126
251
|
});
|
|
252
|
+
|
|
127
253
|
```
|
|
128
254
|
|
|
255
|
+
|
|
256
|
+
|
|
129
257
|
#### Create a new electronic letter - Promise style
|
|
130
258
|
|
|
259
|
+
|
|
260
|
+
|
|
131
261
|
```javascript
|
|
132
|
-
|
|
262
|
+
|
|
263
|
+
var Seeuletter = require('seeuletter')('YOUR API KEY');
|
|
264
|
+
|
|
265
|
+
|
|
133
266
|
|
|
134
267
|
// promise pattern
|
|
268
|
+
|
|
135
269
|
Seeuletter.letters.createElectronic({
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
270
|
+
|
|
271
|
+
description: 'Test electronic letter from the Node.js Wrapper',
|
|
272
|
+
|
|
273
|
+
to: {
|
|
274
|
+
|
|
275
|
+
email: 'erlich.dumas@example.com',
|
|
276
|
+
|
|
277
|
+
first_name: 'Erlich',
|
|
278
|
+
|
|
279
|
+
last_name: 'Dumas',
|
|
280
|
+
|
|
281
|
+
status: 'individual'
|
|
282
|
+
|
|
283
|
+
},
|
|
284
|
+
|
|
285
|
+
postage_type: 'lre',
|
|
286
|
+
|
|
287
|
+
content: 'Please review the attached documents:',
|
|
288
|
+
|
|
289
|
+
source_file: '<html>Hello, {{nom}}</html>',
|
|
290
|
+
|
|
291
|
+
source_file_type: 'html',
|
|
292
|
+
|
|
293
|
+
variables: {
|
|
294
|
+
|
|
295
|
+
nom : 'Seeuletter'
|
|
296
|
+
|
|
297
|
+
}
|
|
298
|
+
|
|
150
299
|
})
|
|
151
|
-
|
|
152
|
-
|
|
300
|
+
|
|
301
|
+
.then(function (response) {
|
|
302
|
+
|
|
303
|
+
console.log('response : ', response);
|
|
304
|
+
|
|
153
305
|
})
|
|
154
|
-
|
|
155
|
-
|
|
306
|
+
|
|
307
|
+
.catch(function (err) {
|
|
308
|
+
|
|
309
|
+
console.log('err : ', err);
|
|
310
|
+
|
|
156
311
|
});
|
|
312
|
+
|
|
157
313
|
```
|
|
158
314
|
|
|
315
|
+
|
|
316
|
+
|
|
159
317
|
#### List all Letters
|
|
160
318
|
|
|
319
|
+
|
|
320
|
+
|
|
161
321
|
```javascript
|
|
162
|
-
|
|
322
|
+
|
|
323
|
+
var Seeuletter = require('seeuletter')('test_12345678901234567890')
|
|
324
|
+
|
|
325
|
+
|
|
163
326
|
|
|
164
327
|
Seeuletter.letters.list()
|
|
165
|
-
|
|
166
|
-
|
|
328
|
+
|
|
329
|
+
.then(function (response) {
|
|
330
|
+
|
|
331
|
+
console.log('response : ', response);
|
|
332
|
+
|
|
167
333
|
})
|
|
168
|
-
|
|
169
|
-
|
|
334
|
+
|
|
335
|
+
.catch(function (err) {
|
|
336
|
+
|
|
337
|
+
console.log('err : ', err);
|
|
338
|
+
|
|
170
339
|
});
|
|
340
|
+
|
|
171
341
|
```
|
|
172
342
|
|
|
343
|
+
|
|
344
|
+
|
|
173
345
|
#### Retrieve a specific Letter
|
|
174
346
|
|
|
347
|
+
|
|
348
|
+
|
|
175
349
|
```javascript
|
|
176
|
-
|
|
350
|
+
|
|
351
|
+
var Seeuletter = require('seeuletter')('test_12345678901234567890')
|
|
352
|
+
|
|
353
|
+
|
|
177
354
|
|
|
178
355
|
Seeuletter.letters.retrieve('LETTER_ID')
|
|
179
|
-
|
|
180
|
-
|
|
356
|
+
|
|
357
|
+
.then(function (response) {
|
|
358
|
+
|
|
359
|
+
console.log('response : ', response);
|
|
360
|
+
|
|
181
361
|
})
|
|
182
|
-
|
|
183
|
-
|
|
362
|
+
|
|
363
|
+
.catch(function (err) {
|
|
364
|
+
|
|
365
|
+
console.log('err : ', err);
|
|
366
|
+
|
|
184
367
|
});
|
|
368
|
+
|
|
185
369
|
```
|
|
186
370
|
|
|
371
|
+
|
|
372
|
+
|
|
187
373
|
### Postcards
|
|
188
374
|
|
|
375
|
+
|
|
376
|
+
|
|
189
377
|
#### Create a new postcard - Promise style
|
|
190
378
|
|
|
379
|
+
|
|
380
|
+
|
|
191
381
|
```javascript
|
|
192
|
-
|
|
382
|
+
|
|
383
|
+
var Seeuletter = require('seeuletter')('YOUR API KEY');
|
|
384
|
+
|
|
385
|
+
|
|
193
386
|
|
|
194
387
|
// Create the address
|
|
388
|
+
|
|
195
389
|
Seeuletter.postcards.create({
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
390
|
+
|
|
391
|
+
description: 'Test Postcard from the Node.js Wrapper',
|
|
392
|
+
|
|
393
|
+
to: {
|
|
394
|
+
|
|
395
|
+
name: 'Erlich',
|
|
396
|
+
|
|
397
|
+
address_line1: '30 rue de rivoli',
|
|
398
|
+
|
|
399
|
+
address_line2: '',
|
|
400
|
+
|
|
401
|
+
address_city: 'Paris',
|
|
402
|
+
|
|
403
|
+
address_country: 'France',
|
|
404
|
+
|
|
405
|
+
address_postalcode: '75004'
|
|
406
|
+
|
|
407
|
+
},
|
|
408
|
+
|
|
409
|
+
// https://www.mysendingbox.fr/templates
|
|
410
|
+
|
|
411
|
+
source_file_front: 'YOUR TEMPLATE ID',
|
|
412
|
+
|
|
413
|
+
source_file_front_type: 'template_id',
|
|
414
|
+
|
|
415
|
+
source_file_back: 'YOUR TEMPLATE ID',
|
|
416
|
+
|
|
417
|
+
source_file_back_type: 'template_id',
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
variables: {
|
|
422
|
+
|
|
423
|
+
PRENOM: 'Erlich',
|
|
424
|
+
|
|
425
|
+
NOM: 'Bachman',
|
|
426
|
+
|
|
427
|
+
CODE_PROMO_BIENVENUE: 'CODE',
|
|
428
|
+
|
|
429
|
+
URL_COURTE_BIENVENUE: 'https://goo.gl/uqTHnD',
|
|
430
|
+
|
|
431
|
+
ADRESSE: '30 rue de Rivoli',
|
|
432
|
+
|
|
433
|
+
CODE_POSTAL : '75004',
|
|
434
|
+
|
|
435
|
+
VILLE : 'Paris',
|
|
436
|
+
|
|
437
|
+
PAYS : 'France'
|
|
438
|
+
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
})
|
|
442
|
+
|
|
443
|
+
.then(function (letter) {
|
|
444
|
+
|
|
445
|
+
console.log('The Seeuletter API Postcard responded : ', letter)
|
|
446
|
+
|
|
447
|
+
})
|
|
448
|
+
|
|
449
|
+
.catch(function (err) {
|
|
450
|
+
|
|
451
|
+
console.log('Error message : ', err.message)
|
|
452
|
+
|
|
221
453
|
})
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
})
|
|
225
|
-
.catch(function (err) {
|
|
226
|
-
console.log('Error message : ', err.message)
|
|
227
|
-
})
|
|
454
|
+
|
|
455
|
+
|
|
228
456
|
|
|
229
457
|
```
|
|
458
|
+
### Price
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
#### Get Price for MySendingBox- Promise style
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
```javascript
|
|
467
|
+
|
|
468
|
+
var Seeuletter = require('seeuletter')('YOUR API KEY');
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
// Get the Letter Price
|
|
473
|
+
Seeuletter.LettersPrice.getPrice({
|
|
474
|
+
|
|
475
|
+
// Letter type
|
|
476
|
+
|
|
477
|
+
postage_type: 'ecopli',
|
|
478
|
+
|
|
479
|
+
page_count: 11,
|
|
480
|
+
|
|
481
|
+
channel: 'paper',
|
|
482
|
+
|
|
483
|
+
color: 'color',
|
|
484
|
+
|
|
485
|
+
pack: 'business',
|
|
486
|
+
|
|
487
|
+
both_sides: false,
|
|
488
|
+
|
|
489
|
+
postage_speed: 'express'
|
|
490
|
+
|
|
491
|
+
}).then(function (response) {
|
|
492
|
+
|
|
493
|
+
console.log('[Get Price] The Seeuletter API responded : ', response)
|
|
494
|
+
|
|
495
|
+
}).catch(function (err) {
|
|
496
|
+
|
|
497
|
+
console.log('[Get Price] Error message : ', err.message)
|
|
498
|
+
|
|
499
|
+
console.log('[Get Price] Error status_code : ', err.status_code)
|
|
500
|
+
|
|
501
|
+
})
|
|
502
|
+
```
|
|
230
503
|
|
|
231
504
|
### Accounts
|
|
232
505
|
|
|
506
|
+
|
|
507
|
+
|
|
233
508
|
#### Create a new account for the company
|
|
234
509
|
|
|
510
|
+
|
|
511
|
+
|
|
235
512
|
```javascript
|
|
236
|
-
|
|
513
|
+
|
|
514
|
+
var Seeuletter = require('seeuletter')('YOUR API KEY');
|
|
515
|
+
|
|
516
|
+
|
|
237
517
|
|
|
238
518
|
// Create the account
|
|
519
|
+
|
|
239
520
|
Seeuletter.accounts.create({
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
521
|
+
|
|
522
|
+
email: "msb.partner@example.com",
|
|
523
|
+
|
|
524
|
+
name: "Erlich Bachman",
|
|
525
|
+
|
|
526
|
+
phone: "+33104050607",
|
|
527
|
+
|
|
528
|
+
company_name: "MSB Partner",
|
|
529
|
+
|
|
530
|
+
address_line1: '30 rue de rivoli',
|
|
531
|
+
|
|
532
|
+
address_line2: '',
|
|
533
|
+
|
|
534
|
+
address_city: 'Paris',
|
|
535
|
+
|
|
536
|
+
address_country: 'France',
|
|
537
|
+
|
|
538
|
+
address_postalcode: '75004'
|
|
539
|
+
|
|
249
540
|
})
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
541
|
+
|
|
542
|
+
.then(function (account) {
|
|
543
|
+
|
|
544
|
+
console.log('The Seeuletter API Account responded : ', account)
|
|
545
|
+
|
|
546
|
+
})
|
|
547
|
+
|
|
548
|
+
.catch(function (err) {
|
|
549
|
+
|
|
550
|
+
console.log('Error message : ', err.message)
|
|
551
|
+
|
|
552
|
+
})
|
|
553
|
+
|
|
554
|
+
|
|
256
555
|
|
|
257
556
|
```
|
|
258
557
|
|
|
558
|
+
|
|
559
|
+
|
|
259
560
|
#### Update the account company email
|
|
260
561
|
|
|
562
|
+
|
|
563
|
+
|
|
261
564
|
```javascript
|
|
262
|
-
|
|
565
|
+
|
|
566
|
+
var Seeuletter = require('seeuletter')('YOUR API KEY');
|
|
567
|
+
|
|
568
|
+
|
|
263
569
|
|
|
264
570
|
// Update the account
|
|
571
|
+
|
|
265
572
|
Seeuletter.accounts.updateEmail("ACCOUNT COMPANY ID", "UPDATED EMAIL")
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
573
|
+
|
|
574
|
+
.then(function () {
|
|
575
|
+
|
|
576
|
+
console.log('The Seeuletter API Account responded with success')
|
|
577
|
+
|
|
578
|
+
})
|
|
579
|
+
|
|
580
|
+
.catch(function (err) {
|
|
581
|
+
|
|
582
|
+
console.log('Error message : ', err.message)
|
|
583
|
+
|
|
584
|
+
})
|
|
585
|
+
|
|
586
|
+
|
|
272
587
|
|
|
273
588
|
```
|
|
274
589
|
|
|
590
|
+
|
|
591
|
+
|
|
275
592
|
### Invoices
|
|
276
593
|
|
|
594
|
+
|
|
595
|
+
|
|
277
596
|
#### List all invoices for a company
|
|
278
597
|
|
|
598
|
+
|
|
599
|
+
|
|
279
600
|
```javascript
|
|
280
|
-
|
|
601
|
+
|
|
602
|
+
var Seeuletter = require('seeuletter')('YOUR API KEY');
|
|
603
|
+
|
|
604
|
+
|
|
281
605
|
|
|
282
606
|
// Getting the invoice list
|
|
607
|
+
|
|
283
608
|
Seeuletter.invoices.list({
|
|
284
|
-
|
|
609
|
+
|
|
610
|
+
// Pass optional filter here as object
|
|
611
|
+
|
|
285
612
|
})
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
613
|
+
|
|
614
|
+
.then(function (response) {
|
|
615
|
+
|
|
616
|
+
console.log('The Seeuletter API Invoices responded : ', response)
|
|
617
|
+
|
|
618
|
+
})
|
|
619
|
+
|
|
620
|
+
.catch(function (err) {
|
|
621
|
+
|
|
622
|
+
console.log('Error message : ', err.message)
|
|
623
|
+
|
|
624
|
+
})
|
|
625
|
+
|
|
626
|
+
|
|
292
627
|
|
|
293
628
|
```
|
|
294
629
|
|
|
630
|
+
|
|
631
|
+
|
|
295
632
|
#### Retrieve a specific invoice
|
|
296
633
|
|
|
634
|
+
|
|
635
|
+
|
|
297
636
|
```javascript
|
|
298
|
-
|
|
637
|
+
|
|
638
|
+
var Seeuletter = require('seeuletter')('YOUR API KEY');
|
|
639
|
+
|
|
640
|
+
|
|
299
641
|
|
|
300
642
|
// Getting the invoice list
|
|
643
|
+
|
|
301
644
|
Seeuletter.invoices.retrieve("INVOICE ID")
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
645
|
+
|
|
646
|
+
.then(function (invoice) {
|
|
647
|
+
|
|
648
|
+
console.log('The Seeuletter API Invoice responded : ', invoice)
|
|
649
|
+
|
|
650
|
+
})
|
|
651
|
+
|
|
652
|
+
.catch(function (err) {
|
|
653
|
+
|
|
654
|
+
console.log('Error message : ', err.message)
|
|
655
|
+
|
|
656
|
+
})
|
|
657
|
+
|
|
658
|
+
|
|
308
659
|
|
|
309
660
|
```
|
|
310
661
|
|
|
662
|
+
|
|
663
|
+
|
|
311
664
|
=======================
|
|
312
665
|
|
|
666
|
+
|
|
667
|
+
|
|
313
668
|
Copyright © 2025 Exaland.app
|
|
314
669
|
|
|
315
|
-
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
Released under the MIT License, which can be found in the repository in `LICENSE.txt`.
|
|
@@ -1,107 +1,117 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var bluebird = require('bluebird')
|
|
3
|
+
const axios = require('axios')
|
|
4
|
+
const stream = require('stream')
|
|
6
5
|
|
|
7
6
|
var ResourceBase = function (endpoint, config) {
|
|
8
7
|
this.uri = config.options.host + endpoint
|
|
9
8
|
this.config = config.options
|
|
10
9
|
this.useBody = config.useBody || false
|
|
11
|
-
}
|
|
10
|
+
}
|
|
12
11
|
|
|
13
12
|
(function () {
|
|
14
|
-
|
|
15
13
|
this._transmit = function (method, uri, qs, form, headers, callback) {
|
|
16
|
-
|
|
17
14
|
if (typeof headers === 'function') {
|
|
18
15
|
callback = headers
|
|
19
16
|
headers = {}
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
17
|
+
} else {
|
|
22
18
|
headers = headers || {}
|
|
23
19
|
}
|
|
24
20
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var opts = {
|
|
30
|
-
url: this.uri + (uri ? '/' + uri : ''),
|
|
31
|
-
method: method,
|
|
32
|
-
auth: {user: this.config.apiKey, password: ''},
|
|
33
|
-
headers: this.config.headers,
|
|
34
|
-
json: true
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
var isMultiPartForm = false
|
|
38
|
-
|
|
39
|
-
for (var key in form) {
|
|
40
|
-
if (form[key] === true || form[key] === false) {
|
|
41
|
-
form[key] = form[key].toString()
|
|
42
|
-
}
|
|
21
|
+
// Ajoutez ou mettez à jour les headers
|
|
22
|
+
for (let headerKey in this.config.headers) {
|
|
23
|
+
headers[headerKey] = this.config.headers[headerKey]
|
|
43
24
|
}
|
|
44
25
|
|
|
45
|
-
|
|
46
|
-
var val = form[param]
|
|
47
|
-
|
|
48
|
-
if (val instanceof stream.Stream) {
|
|
49
|
-
isMultiPartForm = true
|
|
50
|
-
break
|
|
51
|
-
}
|
|
26
|
+
const url = this.uri + (uri ? '/' + uri : '')
|
|
52
27
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
28
|
+
// Préparer la configuration axios
|
|
29
|
+
const axiosConfig = {
|
|
30
|
+
url: url,
|
|
31
|
+
method: method,
|
|
32
|
+
headers: headers,
|
|
33
|
+
auth: {
|
|
34
|
+
username: this.config.apiKey,
|
|
35
|
+
password: ''
|
|
36
|
+
},
|
|
37
|
+
// Par défaut, axios sérialise en JSON
|
|
38
|
+
// Ajoutez des options spécifiques selon votre besoin
|
|
57
39
|
}
|
|
58
40
|
|
|
41
|
+
// Gestion des paramètres de requête
|
|
59
42
|
if (qs) {
|
|
60
|
-
|
|
43
|
+
axiosConfig.params = qs
|
|
61
44
|
}
|
|
62
45
|
|
|
46
|
+
// Gestion du corps de la requête
|
|
63
47
|
if (form) {
|
|
48
|
+
// Vérifier si le corps doit être envoyé en tant que formData
|
|
49
|
+
let isMultiPartForm = false
|
|
50
|
+
for (const key in form) {
|
|
51
|
+
const val = form[key]
|
|
52
|
+
if (val instanceof stream.Stream) || (val && val.hasOwnProperty('value')) {
|
|
53
|
+
isMultiPartForm = true
|
|
54
|
+
break
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
64
58
|
if (this.useBody) {
|
|
65
|
-
|
|
59
|
+
axiosConfig.data = form
|
|
66
60
|
} else if (isMultiPartForm) {
|
|
67
|
-
|
|
61
|
+
// Si vous utilisez des fichiers stream ou formData, utilisez form-data
|
|
62
|
+
const FormData = require('form-data')
|
|
63
|
+
const formData = new FormData()
|
|
64
|
+
for (const key in form) {
|
|
65
|
+
formData.append(key, form[key])
|
|
66
|
+
}
|
|
67
|
+
axiosConfig.data = formData
|
|
68
|
+
axiosConfig.headers = {
|
|
69
|
+
...headers,
|
|
70
|
+
...formData.getHeaders()
|
|
71
|
+
}
|
|
68
72
|
} else {
|
|
69
|
-
|
|
73
|
+
axiosConfig.data = form
|
|
70
74
|
}
|
|
71
75
|
}
|
|
72
76
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (body && body.error) {
|
|
81
|
-
var error = new Error(body.error.message)
|
|
82
|
-
error.status_code = body.error.status_code || resp.statusCode
|
|
83
|
-
error._response = resp
|
|
84
|
-
return reject(error)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (resp && resp.statusCode >= 500) {
|
|
88
|
-
var error = new Error(resp.statusMessage)
|
|
89
|
-
error.status_code = resp.statusCode
|
|
90
|
-
error._response = resp
|
|
91
|
-
return reject(error)
|
|
92
|
-
}
|
|
93
|
-
|
|
77
|
+
// Appel axios avec gestion Promises
|
|
78
|
+
const promise = axios(axiosConfig)
|
|
79
|
+
.then(response => {
|
|
80
|
+
const body = response.data
|
|
81
|
+
// Ajout de la propriété _response
|
|
94
82
|
Object.defineProperty(body, '_response', {
|
|
95
83
|
enumerable: false,
|
|
96
84
|
writable: false,
|
|
97
|
-
value:
|
|
85
|
+
value: response
|
|
98
86
|
})
|
|
99
|
-
|
|
100
|
-
|
|
87
|
+
return body
|
|
88
|
+
})
|
|
89
|
+
.catch(err => {
|
|
90
|
+
if (err.response) {
|
|
91
|
+
const resp = err.response
|
|
92
|
+
const body = resp.data
|
|
93
|
+
if (body && body.error) {
|
|
94
|
+
const error = new Error(body.error.message)
|
|
95
|
+
error.status_code = body.error.status_code || resp.status
|
|
96
|
+
error._response = resp
|
|
97
|
+
throw error
|
|
98
|
+
}
|
|
99
|
+
if (resp.status >= 500) {
|
|
100
|
+
const error = new Error(resp.statusText)
|
|
101
|
+
error.status_code = resp.status
|
|
102
|
+
error._response = resp
|
|
103
|
+
throw error
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
throw err
|
|
101
107
|
})
|
|
102
|
-
}).nodeify(callback)
|
|
103
|
-
}
|
|
104
108
|
|
|
109
|
+
if (callback && typeof callback === 'function') {
|
|
110
|
+
promise.then(result => callback(null, result)).catch(err => callback(err))
|
|
111
|
+
} else {
|
|
112
|
+
return promise
|
|
113
|
+
}
|
|
114
|
+
}
|
|
105
115
|
}).call(ResourceBase.prototype)
|
|
106
116
|
|
|
107
|
-
module.exports = ResourceBase
|
|
117
|
+
module.exports = ResourceBase
|
package/package.json
CHANGED
|
@@ -11,16 +11,16 @@
|
|
|
11
11
|
"Mysendingbox.com",
|
|
12
12
|
"printing"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.0.
|
|
14
|
+
"version": "1.0.7",
|
|
15
15
|
"homepage": "https://github.com/exaland/mysendingbox-node",
|
|
16
16
|
"author": "Exaland Concept For -> Mysendingbox <hello@mysendingbox.fr> (https://www.mysendingbox.fr/)",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"bluebird": "^3.
|
|
19
|
-
"flat": "^
|
|
20
|
-
"
|
|
18
|
+
"bluebird": "^3.7.2",
|
|
19
|
+
"flat": "^6.0.1",
|
|
20
|
+
"axios": "^1.16.1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"moment": "^2.
|
|
23
|
+
"moment": "^2.30.1"
|
|
24
24
|
},
|
|
25
25
|
"repository": {
|
|
26
26
|
"type": "git",
|