# Integrations

Use API users and PHP libraries to connect external systems.

## Use the resource interface

The REST API exposes resource records through existing authentication and authorization. Create a dedicated integration user with API access and a role restricted to the necessary resource operations. Obtain a short-lived token at `/api/v1/auth/token` and include it as a Bearer token.

```bash
curl "$NIMBLY_DEMO_URL/api/v1/events?filter=published:1&sort=date%7Casc" \
  -H "Authorization: Bearer $NIMBLY_DEMO_TOKEN"
```

The URL and token here are environment values for the calling process. Keep credentials outside tracked files and logs. See [REST API](/en/docs/reference/api/) and its [OpenAPI description](/en/docs/reference/api/openapi.json).

## Put business logic in a library

An application library in `ext/lib/` prepares data, calls external services and implements domain rules. It should not generate template-owned HTML. Use a module when the integration packages reusable templates, resources and logic.

## Background work

Move scheduled or deferred integrations into established jobs and scheduler mechanisms. Define retry behavior, idempotency and permissions for the actual operation. Confirm the external service accepted the operation rather than treating a queued job as completion.
