# directus-extension-upsert

> As the name suggests a basic extension for upserting records in a single API call, it will check if the record exists and if so, update it, otherwise it will create it.

Latest version **1.0.5** (published 2023-06-28) · 0 weekly downloads

## Install

```sh
npm install directus-extension-upsert
pnpm add directus-extension-upsert
yarn add directus-extension-upsert
bun add directus-extension-upsert
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2023-06-28 |
| First published | 2023-01-30 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | freekrai |
| Maintainers | datamcfly |
| Keywords | directus, directus-extension, directus-custom-endpoint |

## Links

- npm: https://www.npmjs.com/package/directus-extension-upsert
- Repository: https://github.com/freekrai/directus-extension-upsert
- Homepage: https://github.com/freekrai/directus-extension-upsert#readme
- Issues: https://github.com/freekrai/directus-extension-upsert/issues
- npm.io page: https://npm.io/package/directus-extension-upsert

## Recent versions

- 1.0.5 (latest) — 2023-06-28
- 1.0.4 — 2023-01-30
- 1.0.3 — 2023-01-30
- 1.0.2 — 2023-01-30
- 1.0.1 — 2023-01-30
- 1.0.0 — 2023-01-30

## README

# Directus Extension upsert

As the name suggests a basic extension for upserting records in a single API call, it will check if the record exists and if so, update it, otherwise it will create it.

> Tested with Directus 10

## Installation

The package is published to npm:
`npm install directus-extension-upsert`

**Manual Installation**
- Download or fork the repository
- Install the requirements\
  `npm install`
- Build the extension\
  `npm run build`
- Move the result to your extension folder\
  `mv dist extensions/hooks/directus-extension-upsert`
- Restart your Directus instance

## Usages

This endpoint will intercept any `POST` requests to `/upsert/:collection` and check if the record exists and if so, update it, otherwise it will create it.


```
URL
  http://localhost:8055/upsert/:collection
Method
  POST
Headers
  Authorization: ...
  Content-Type: application/json
Body
{
    "filter": {
        "key": "test2"
    },
    "body": {
      "key": "test2",
      "value": "testindddddg"
    }
}
```
**response**
```
{
    "success": true,
    "msg": "Create Success",
    "code": 201,
    "data": null
}
```

or

```
{
    "success": true,
    "msg": "Update Success",
    "code": 201,
    "data": null
}
```

---
_Source: https://npm.io/package/directus-extension-upsert · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
