@autoapicom/client 1.0.0
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/LICENSE +21 -0
- package/README.md +111 -0
- package/dist/client.d.ts +39 -0
- package/dist/client.js +112 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.js +16 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 AUTO-API.COM
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# auto-api-client-typescript
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.com/package/@auto-api/client)
|
|
4
|
+
[](https://npmjs.com/package/@auto-api/client)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
TypeScript client for the [auto-api.com](https://auto-api.com) car listings API. Zero dependencies — uses the built-in `fetch`.
|
|
8
|
+
|
|
9
|
+
Search and filter offers across 8 marketplaces (encar, mobile.de, autoscout24, che168, dongchedi, guazi, dubicars, dubizzle), track price changes, pull individual listings by ID or URL.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @auto-api/client
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { Client } from '@auto-api/client';
|
|
21
|
+
|
|
22
|
+
const client = new Client('your-api-key');
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Get filters
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
const filters = await client.getFilters('encar');
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Search offers
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
const offers = await client.getOffers('mobilede', {
|
|
35
|
+
page: 1,
|
|
36
|
+
brand: 'BMW',
|
|
37
|
+
year_from: 2020,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Pagination
|
|
41
|
+
console.log(offers.meta.page);
|
|
42
|
+
console.log(offers.meta.next_page);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Get single offer
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
const offer = await client.getOffer('encar', '40427050');
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Track changes
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
const changeId = await client.getChangeId('encar', '2025-01-15');
|
|
55
|
+
const changes = await client.getChanges('encar', changeId);
|
|
56
|
+
|
|
57
|
+
// Next batch
|
|
58
|
+
const nextBatch = await client.getChanges('encar', changes.meta.next_change_id);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Get offer by URL
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
const info = await client.getOfferByUrl('https://encar.com/dc/dc_cardetailview.do?carid=40427050');
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Error handling
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { Client, AuthError, ApiError } from '@auto-api/client';
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
const offers = await client.getOffers('encar', { page: 1 });
|
|
74
|
+
} catch (e) {
|
|
75
|
+
if (e instanceof AuthError) {
|
|
76
|
+
// 401/403 — invalid API key
|
|
77
|
+
} else if (e instanceof ApiError) {
|
|
78
|
+
console.log(e.statusCode);
|
|
79
|
+
console.log(e.message);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Supported sources
|
|
85
|
+
|
|
86
|
+
| Source | Platform | Region |
|
|
87
|
+
|--------|----------|--------|
|
|
88
|
+
| `encar` | [encar.com](https://encar.com) | South Korea |
|
|
89
|
+
| `mobilede` | [mobile.de](https://mobile.de) | Germany |
|
|
90
|
+
| `autoscout24` | [autoscout24.com](https://autoscout24.com) | Europe |
|
|
91
|
+
| `che168` | [che168.com](https://che168.com) | China |
|
|
92
|
+
| `dongchedi` | [dongchedi.com](https://dongchedi.com) | China |
|
|
93
|
+
| `guazi` | [guazi.com](https://guazi.com) | China |
|
|
94
|
+
| `dubicars` | [dubicars.com](https://dubicars.com) | UAE |
|
|
95
|
+
| `dubizzle` | [dubizzle.com](https://dubizzle.com) | UAE |
|
|
96
|
+
|
|
97
|
+
## Other languages
|
|
98
|
+
|
|
99
|
+
| Language | Package |
|
|
100
|
+
|----------|---------|
|
|
101
|
+
| PHP | [auto-api/client](https://github.com/autoapicom/auto-api-php) |
|
|
102
|
+
| Python | [auto-api-client](https://github.com/autoapicom/auto-api-python) |
|
|
103
|
+
| Go | [auto-api-go](https://github.com/autoapicom/auto-api-go) |
|
|
104
|
+
| C# | [AutoApi.Client](https://github.com/autoapicom/auto-api-dotnet) |
|
|
105
|
+
| Java | [auto-api-client](https://github.com/autoapicom/auto-api-java) |
|
|
106
|
+
| Ruby | [auto-api-client](https://github.com/autoapicom/auto-api-ruby) |
|
|
107
|
+
| Rust | [auto-api-client](https://github.com/autoapicom/auto-api-rust) |
|
|
108
|
+
|
|
109
|
+
## Documentation
|
|
110
|
+
|
|
111
|
+
[auto-api.com](https://auto-api.com)
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare class Client {
|
|
2
|
+
private readonly apiKey;
|
|
3
|
+
private readonly baseUrl;
|
|
4
|
+
private readonly apiVersion;
|
|
5
|
+
private readonly timeout;
|
|
6
|
+
constructor(apiKey: string, baseUrl?: string, apiVersion?: string);
|
|
7
|
+
/**
|
|
8
|
+
* Available filters for a source (brands, models, body types, etc.)
|
|
9
|
+
*/
|
|
10
|
+
getFilters(source: string): Promise<Record<string, unknown>>;
|
|
11
|
+
/**
|
|
12
|
+
* List of offers with pagination and filters.
|
|
13
|
+
*
|
|
14
|
+
* Params: page (required), brand, model, configuration, complectation,
|
|
15
|
+
* transmission, color, body_type, engine_type, year_from, year_to,
|
|
16
|
+
* mileage_from, mileage_to, price_from, price_to
|
|
17
|
+
*/
|
|
18
|
+
getOffers(source: string, params?: Record<string, string | number>): Promise<Record<string, unknown>>;
|
|
19
|
+
/**
|
|
20
|
+
* Single offer by inner_id.
|
|
21
|
+
*/
|
|
22
|
+
getOffer(source: string, innerId: string): Promise<Record<string, unknown>>;
|
|
23
|
+
/**
|
|
24
|
+
* Get change_id by date (format: yyyy-mm-dd).
|
|
25
|
+
*/
|
|
26
|
+
getChangeId(source: string, date: string): Promise<number>;
|
|
27
|
+
/**
|
|
28
|
+
* Changes feed (added/changed/removed) starting from change_id.
|
|
29
|
+
*/
|
|
30
|
+
getChanges(source: string, changeId: number): Promise<Record<string, unknown>>;
|
|
31
|
+
/**
|
|
32
|
+
* Get offer data by its URL on the marketplace.
|
|
33
|
+
*/
|
|
34
|
+
getOfferByUrl(url: string): Promise<Record<string, unknown>>;
|
|
35
|
+
private get;
|
|
36
|
+
private post;
|
|
37
|
+
private decode;
|
|
38
|
+
private handleError;
|
|
39
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { ApiError, AuthError } from './errors.js';
|
|
2
|
+
export class Client {
|
|
3
|
+
apiKey;
|
|
4
|
+
baseUrl;
|
|
5
|
+
apiVersion;
|
|
6
|
+
timeout;
|
|
7
|
+
constructor(apiKey, baseUrl = 'https://auto-api.com', apiVersion = 'v2') {
|
|
8
|
+
this.apiKey = apiKey;
|
|
9
|
+
this.baseUrl = baseUrl.replace(/\/+$/, '');
|
|
10
|
+
this.apiVersion = apiVersion;
|
|
11
|
+
this.timeout = 30000;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Available filters for a source (brands, models, body types, etc.)
|
|
15
|
+
*/
|
|
16
|
+
async getFilters(source) {
|
|
17
|
+
return this.get(`api/${this.apiVersion}/${source}/filters`);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* List of offers with pagination and filters.
|
|
21
|
+
*
|
|
22
|
+
* Params: page (required), brand, model, configuration, complectation,
|
|
23
|
+
* transmission, color, body_type, engine_type, year_from, year_to,
|
|
24
|
+
* mileage_from, mileage_to, price_from, price_to
|
|
25
|
+
*/
|
|
26
|
+
async getOffers(source, params = {}) {
|
|
27
|
+
return this.get(`api/${this.apiVersion}/${source}/offers`, params);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Single offer by inner_id.
|
|
31
|
+
*/
|
|
32
|
+
async getOffer(source, innerId) {
|
|
33
|
+
return this.get(`api/${this.apiVersion}/${source}/offer`, { inner_id: innerId });
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get change_id by date (format: yyyy-mm-dd).
|
|
37
|
+
*/
|
|
38
|
+
async getChangeId(source, date) {
|
|
39
|
+
const response = await this.get(`api/${this.apiVersion}/${source}/change_id`, { date });
|
|
40
|
+
return response.change_id;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Changes feed (added/changed/removed) starting from change_id.
|
|
44
|
+
*/
|
|
45
|
+
async getChanges(source, changeId) {
|
|
46
|
+
return this.get(`api/${this.apiVersion}/${source}/changes`, { change_id: changeId });
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get offer data by its URL on the marketplace.
|
|
50
|
+
*/
|
|
51
|
+
async getOfferByUrl(url) {
|
|
52
|
+
return this.post('api/v1/offer/info', { url });
|
|
53
|
+
}
|
|
54
|
+
async get(endpoint, params = {}) {
|
|
55
|
+
const query = new URLSearchParams();
|
|
56
|
+
query.set('api_key', this.apiKey);
|
|
57
|
+
for (const [key, value] of Object.entries(params)) {
|
|
58
|
+
query.set(key, String(value));
|
|
59
|
+
}
|
|
60
|
+
const url = `${this.baseUrl}/${endpoint}?${query.toString()}`;
|
|
61
|
+
const response = await fetch(url, {
|
|
62
|
+
method: 'GET',
|
|
63
|
+
signal: AbortSignal.timeout(this.timeout),
|
|
64
|
+
});
|
|
65
|
+
if (!response.ok) {
|
|
66
|
+
await this.handleError(response);
|
|
67
|
+
}
|
|
68
|
+
return this.decode(response);
|
|
69
|
+
}
|
|
70
|
+
async post(endpoint, data) {
|
|
71
|
+
const url = `${this.baseUrl}/${endpoint}`;
|
|
72
|
+
const response = await fetch(url, {
|
|
73
|
+
method: 'POST',
|
|
74
|
+
headers: {
|
|
75
|
+
'Content-Type': 'application/json',
|
|
76
|
+
'x-api-key': this.apiKey,
|
|
77
|
+
},
|
|
78
|
+
body: JSON.stringify(data),
|
|
79
|
+
signal: AbortSignal.timeout(this.timeout),
|
|
80
|
+
});
|
|
81
|
+
if (!response.ok) {
|
|
82
|
+
await this.handleError(response);
|
|
83
|
+
}
|
|
84
|
+
return this.decode(response);
|
|
85
|
+
}
|
|
86
|
+
async decode(response) {
|
|
87
|
+
const text = await response.text();
|
|
88
|
+
try {
|
|
89
|
+
return JSON.parse(text);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
throw new ApiError(`Invalid JSON response: ${text.slice(0, 200)}`, response.status);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async handleError(response) {
|
|
96
|
+
let body;
|
|
97
|
+
let message = `API error: ${response.status} ${response.statusText}`;
|
|
98
|
+
try {
|
|
99
|
+
body = await response.json();
|
|
100
|
+
if (body && typeof body === 'object' && 'message' in body) {
|
|
101
|
+
message = body.message;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
// Response body is not JSON
|
|
106
|
+
}
|
|
107
|
+
if (response.status === 401 || response.status === 403) {
|
|
108
|
+
throw new AuthError(message, response.status);
|
|
109
|
+
}
|
|
110
|
+
throw new ApiError(message, response.status, body);
|
|
111
|
+
}
|
|
112
|
+
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class ApiError extends Error {
|
|
2
|
+
readonly statusCode: number;
|
|
3
|
+
readonly responseBody: unknown;
|
|
4
|
+
constructor(message: string, statusCode: number, responseBody?: unknown);
|
|
5
|
+
}
|
|
6
|
+
export declare class AuthError extends ApiError {
|
|
7
|
+
constructor(message?: string, statusCode?: number);
|
|
8
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export class ApiError extends Error {
|
|
2
|
+
statusCode;
|
|
3
|
+
responseBody;
|
|
4
|
+
constructor(message, statusCode, responseBody) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = 'ApiError';
|
|
7
|
+
this.statusCode = statusCode;
|
|
8
|
+
this.responseBody = responseBody;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export class AuthError extends ApiError {
|
|
12
|
+
constructor(message = 'Invalid or missing API key', statusCode = 401) {
|
|
13
|
+
super(message, statusCode);
|
|
14
|
+
this.name = 'AuthError';
|
|
15
|
+
}
|
|
16
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@autoapicom/client",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Auto-api.com client for Node.js — fetch car listings from encar, mobile.de, autoscout24 and 5 other sources",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=18"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"prepublishOnly": "tsc"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"auto-api",
|
|
26
|
+
"api-client",
|
|
27
|
+
"car-listings",
|
|
28
|
+
"encar",
|
|
29
|
+
"mobile-de",
|
|
30
|
+
"autoscout24",
|
|
31
|
+
"typescript-api-client",
|
|
32
|
+
"car-auction",
|
|
33
|
+
"scraper",
|
|
34
|
+
"encar api",
|
|
35
|
+
"mobile.de api",
|
|
36
|
+
"autoscout24 api",
|
|
37
|
+
"che168 api",
|
|
38
|
+
"dongchedi api",
|
|
39
|
+
"guazi api",
|
|
40
|
+
"dubicars api",
|
|
41
|
+
"dubizzle api"
|
|
42
|
+
],
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "https://github.com/autoapicom/auto-api-node.git"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://auto-api.com",
|
|
48
|
+
"author": "AUTO-API.COM <access@auto-api.com>",
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"typescript": "^5.0.0"
|
|
52
|
+
}
|
|
53
|
+
}
|