https://github.com/robingenz/engine4-node
⚙️ Node.js library for the ENGINE4 API.
https://github.com/robingenz/engine4-node
api engine4 node node-sdk
Last synced: about 2 months ago
JSON representation
⚙️ Node.js library for the ENGINE4 API.
- Host: GitHub
- URL: https://github.com/robingenz/engine4-node
- Owner: robingenz
- License: other
- Created: 2022-11-27T17:24:48.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-05T15:15:10.000Z (over 1 year ago)
- Last Synced: 2025-03-24T18:53:52.047Z (about 2 months ago)
- Topics: api, engine4, node, node-sdk
- Language: TypeScript
- Homepage: https://docs.engine4.io/api
- Size: 438 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# engine4-node
[](https://github.com/robingenz/engine4-node/actions?query=workflow%3A%22CI%22)
[](https://github.com/robingenz/engine4-node/blob/main/LICENSE)
[](https://www.npmjs.com/package/engine4-node)
[](https://www.npmjs.com/package/engine4-node)⚙️ Node.js library for the ENGINE4 API.
## Installation
Use [npm](https://docs.npmjs.com/cli/) to install the package:
```bash
npm install engine4-node
```## Usage
First of all, you import `ENGINE4` so that you can create an instance of the class.
You need to pass the `baseUrl` of the API server:```typescript
import { ENGINE4 } from 'engine4-node';const engine4 = new ENGINE4({ baseUrl: 'https://test.engine4.io' });
```Now you can authenticate yourself with `username`, `password` and `clientId`:
```typescript
const authenticate = async () => {
const { accessToken } = await engine4.authenticate({
username: 'my_username',
password: 'my_password',
clientId: 'my_client_id',
});
return accessToken;
};
```The access token is required for the following calls.
Here you can find examples for deleting, querying, inserting and updating records:
```typescript
import { ENGINE4, CompareOperator } from 'engine4-node';const accessToken = await authenticate();
const delete = async () => {
await engine4.delete({
accessToken,
entityId: '39aeedee-91e3-4ec4-b7bb-b5a036601f9f',
dataId: '3c7d04f7-74e6-4cfd-9fd6-233c6f4ded8a',
});
};const deleteMultiple = async () => {
await engine4.deleteMultiple({
accessToken,
entityId: '39aeedee-91e3-4ec4-b7bb-b5a036601f9f',
dataIds: [
'3c7d04f7-74e6-4cfd-9fd6-233c6f4ded8a',
'7130fa8b-4040-40d0-b97b-a9006fc140ec',
],
});
};const fetch = async () => {
const { items } = await engine4.fetch({
accessToken,
entityId: '7130fa8b-4040-40d0-b97b-a9006fc140ec',
take: 10,
skip: 20,
filter: {
genericName: 'Custom_001',
compareOperator: CompareOperator.Equal,
value: 'my_value',
},
sorting: [
{
genericName: 'Custom_001',
sort: 'desc',
},
],
});
return items;
};const get = async () => {
const { item } = await engine4.get({
accessToken,
entityId: '39aeedee-91e3-4ec4-b7bb-b5a036601f9f',
dataId: '3c7d04f7-74e6-4cfd-9fd6-233c6f4ded8a',
});
return item;
};const getMultiple = async () => {
const { items } = await engine4.getMultiple({
accessToken,
entityId: '39aeedee-91e3-4ec4-b7bb-b5a036601f9f',
dataIds: [
'3c7d04f7-74e6-4cfd-9fd6-233c6f4ded8a',
'7130fa8b-4040-40d0-b97b-a9006fc140ec',
],
});
return items;
};const saveAll = async () => {
const { items } = await engine4.saveAll({
accessToken,
items: [
{
EntityId: '39aeedee-91e3-4ec4-b7bb-b5a036601f9f',
DataId: '3c7d04f7-74e6-4cfd-9fd6-233c6f4ded8a',
Custom_001: 'my_value',
}
],
returnType: 'dataId',
});
return items;
};const fetchAttachment = async () => {
const { item } = await engine4.fetchAttachment({
accessToken,
dataId: "ea10248d-1fe8-4baf-84d7-d18a64106b40",
});
return item;
};const fetchAndSaveAttachment = async () => {
const { writeFile } = require("fs");
const { promisify } = require("util");
const writeFilePromise = promisify(writeFile);const { item } = await engine4.fetchAttachment({
accessToken,
dataId: "ea10248d-1fe8-4baf-84d7-d18a64106b40",
});
await writeFilePromise("test.pdf", item);
};
```## Changelog
See [CHANGELOG.md](https://github.com/robingenz/engine4-node/blob/main/CHANGELOG.md).
## License
See [LICENSE](https://github.com/robingenz/engine4-node/blob/main/LICENSE).