11# Scan Documents TypeScript API Library
22
3- [ ![ NPM version] ( https://img.shields.io/npm/v/scan-documents.svg )] ( https://npmjs.org/package/scan-documents ) ![ npm bundle size] ( https://img.shields.io/bundlephobia/minzip/scan-documents )
3+ [ ![ NPM version] ( < https://img.shields.io/npm/v/scan-documents.svg?label=npm%20(stable) > )] ( https://npmjs.org/package/scan-documents ) ![ npm bundle size] ( https://img.shields.io/bundlephobia/minzip/scan-documents )
44
55This library provides convenient access to the Scan Documents REST API from server-side TypeScript or JavaScript.
66
@@ -26,11 +26,7 @@ const client = new ScanDocuments({
2626 apiKey: process .env [' SCAN_DOCUMENTS_API_KEY' ], // This is the default and can be omitted
2727});
2828
29- async function main () {
30- const file = await client .files .upload ({ file: fs .createReadStream (' path/to/file' ), name: ' REPLACE_ME' });
31- }
32-
33- main ();
29+ const file = await client .files .upload ({ file: fs .createReadStream (' path/to/file' ), name: ' REPLACE_ME' });
3430```
3531
3632### Request & Response types
@@ -45,15 +41,11 @@ const client = new ScanDocuments({
4541 apiKey: process .env [' SCAN_DOCUMENTS_API_KEY' ], // This is the default and can be omitted
4642});
4743
48- async function main() {
49- const params: ScanDocuments .FileUploadParams = {
50- file: fs .createReadStream (' path/to/file' ),
51- name: ' REPLACE_ME' ,
52- };
53- const file: ScanDocuments .File = await client .files .upload (params );
54- }
55-
56- main ();
44+ const params: ScanDocuments .FileUploadParams = {
45+ file: fs .createReadStream (' path/to/file' ),
46+ name: ' REPLACE_ME' ,
47+ };
48+ const file: ScanDocuments .File = await client .files .upload (params );
5749```
5850
5951Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
@@ -115,21 +107,17 @@ a subclass of `APIError` will be thrown:
115107
116108<!-- prettier-ignore -->
117109``` ts
118- async function main() {
119- const file = await client .files
120- .upload ({ file: fs .createReadStream (' path/to/file' ), name: ' REPLACE_ME' })
121- .catch (async (err ) => {
122- if (err instanceof ScanDocuments .APIError ) {
123- console .log (err .status ); // 400
124- console .log (err .name ); // BadRequestError
125- console .log (err .headers ); // {server: 'nginx', ...}
126- } else {
127- throw err ;
128- }
129- });
130- }
131-
132- main ();
110+ const file = await client .files
111+ .upload ({ file: fs .createReadStream (' path/to/file' ), name: ' REPLACE_ME' })
112+ .catch (async (err ) => {
113+ if (err instanceof ScanDocuments .APIError ) {
114+ console .log (err .status ); // 400
115+ console .log (err .name ); // BadRequestError
116+ console .log (err .headers ); // {server: 'nginx', ...}
117+ } else {
118+ throw err ;
119+ }
120+ });
133121```
134122
135123Error codes are as follows:
@@ -291,9 +279,8 @@ parameter. This library doesn't validate at runtime that the request matches the
291279send will be sent as-is.
292280
293281``` ts
294- client .foo .create ({
295- foo: ' my_param' ,
296- bar: 12 ,
282+ client .files .upload ({
283+ // ...
297284 // @ts-expect-error baz is not yet public
298285 baz: ' undocumented option' ,
299286});
0 commit comments