PHPackages                             remp/crm-api-module - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. remp/crm-api-module

ActiveLibrary[API Development](/categories/api)

remp/crm-api-module
===================

CRM Api Module

4.4.0(5mo ago)150.8k—9.5%3[1 PRs](https://github.com/remp2020/crm-api-module/pulls)1MITPHPPHP ^8.1

Since Oct 22Pushed 5mo ago5 watchersCompare

[ Source](https://github.com/remp2020/crm-api-module)[ Packagist](https://packagist.org/packages/remp/crm-api-module)[ Docs](https://remp2030.com)[ RSS](/packages/remp-crm-api-module/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (87)Used By (1)

CRM API Module
==============

[](#crm-api-module)

[![Translation status @ Weblate](https://camo.githubusercontent.com/467e25ee1c63076274b4c053dbc0c9e4079713fbee72b5c3cedb23c4e74da7f9/68747470733a2f2f686f737465642e7765626c6174652e6f72672f776964676574732f72656d702d63726d2f2d2f6170692d6d6f64756c652f7376672d62616467652e737667)](https://hosted.weblate.org/projects/remp-crm/api-module/)

This documentation serves as a complement to [CRM Skeleton](https://github.com/remp2020/crm-skeleton/#registerapicalls)documentation related to creating and registering API handlers.

It describes API handlers provided by this module for others to use.

Enabling module
---------------

[](#enabling-module)

Make sure you add extension to your `app/config/config.neon` file.

```
extensions:
	- Crm\ApiModule\DI\ApiModuleExtension
```

### Configuration

[](#configuration)

#### Preflight requests

[](#preflight-requests)

Module allows you to configure preflight request handling. Add following snippet to your `config.neon` file:

```
services:
	# ...
	apiHeadersConfig:
		setup:
			- setAllowedOrigins('*')
			- setAllowedHeaders('Content-Type', 'Authorization', 'X-Requested-With')
			- setAllowedHttpMethods('*')
			- setAllowedCredentials(true)
			- setAccessControlMaxAge(600) # seconds
```

You can configure allowed origins by explicitly stating them or by using wildcards. Following configurations are valid:

- `setAllowedOrigins("*")`. Matches everything
- `setAllowedOrigins("foo.bar", "*.foo.bar")`. Matches `foo.bar` and all of its subdomains.
- `setAllowedOrigins("foo.bar", "1.foo.bar")`. Matches `foo.bar`, `1.foo.bar`, but nothing else (nor any other subdomain).

#### API requests logging

[](#api-requests-logging)

You can globally enable or disable API logging in the CRM admin - config section. If the logging is enabled, you can further configure which specific paths should be logged or not.

We recommend using configuration of blacklist over whitelist. Otherwise you might encounter a scenario, where logs from one of our APIs might be missing when you need them.

To enable blacklist, add following snippet to your `config.neon` file:

```
services:
	# ...
	apiLoggerConfig:
		setup:
			- setPathBlacklist([
				Crm\ApiModule\Models\Api\LoggerEndpointIdentifier('1', 'foo', 'bar'),
			])
```

The `LoggerEndpointIdentifier` requires three parameters: `version`, `package` and `apiCall` - same parameters which you use when you register a new API handler. The snippet above will not log requests to the `/api/v1/foo/bar` endpoint.

You can also use wildcards where necessary:

- `Crm\ApiModule\Models\Api\LoggerEndpointIdentifier('*', 'foo', 'bar')` will match all requests going to `/api/*/foo/bar`.
- `Crm\ApiModule\Models\Api\LoggerEndpointIdentifier('1', '*', '*')` will match all requests going to `/api/v3/*/*`.

Blacklist and whitelist cannot be combined, the latter configured wins.

By default the API logger redacts standard fields found in GET parameters, POST parameters and JSON payload parameters: `password`, `token` and `auth`. If you need to extend this and redact other parameters, you can extend the redaction:

```
	# ...
	apiLoggerConfig:
		setup:
			- addRedactedFields(['internal_token'])
```

#### Data retention configuration

[](#data-retention-configuration)

You can configure time before which `application:cleanup` deletes old repository data and column which it uses by using (in your project configuration file):

```
apiLogsRepository:
	setup:
		- setRetentionThreshold('-2 months', 'created_at')
```

Database tables migration
-------------------------

[](#database-tables-migration)

Because of need of changing primary keys (int -&gt; bigint), in tables that contain lots of data (or have risk of overflowing primary key if its int), we had to create migration process. Since some tables are very exposed and cannot be locked for more than a couple of seconds, we decided to create new tables, migrate the data manually and keep the old and new table in sync while migrating.

*This migration process is necessary only for installations after specific version for specific table, and is two steps process.*

### Api logs migration (installed before version 2.5.0)

[](#api-logs-migration-installed-before-version-250)

Consists of `api_logs` table migration.

Steps:

1. Run phinx migrations command `phinx:migrate`, which creates new table `api_logs_v2` (in case there is no data in table, migration just changes type of primary key and next steps are not needed).
2. Run command `api:convert_api_logs_to_bigint`, which copies data from old table to new (e.g. `api_logs` to `api_logs_v2`). Command will after successful migration atomically rename tables (e.g. `api_logs` -&gt; `api_logs_old` and `api_logs_v2` -&gt; `api_logs`), so when the migration ends only new tables are used.

It's recommended to run `application:bigint_migration_cleanup api_logs` command, at least 2 weeks (to preserve backup data, if some issue emerges) after successful migration to drop left-over tables.

API documentation
-----------------

[](#api-documentation)

All examples use `http://crm.press` as a base domain. Please change the host to the one you use before executing the examples.

All examples use `XXX` as a default value for authorization token, please replace it with the real tokens:

- *API tokens.* Standard API keys for server-server communication. It identifies the calling application as a whole. They can be generated in CRM Admin (`/api/api-tokens-admin/`) and each API key has to be whitelisted to access specific API endpoints. By default the API key has access to no endpoint.
- *User tokens.* Generated for each user during the login process, token identify single user when communicating between different parts of the system. The token can be read:
    - From `n_token` cookie if the user was logged in via CRM.
    - From the response of [`/api/v1/users/login` endpoint](https://github.com/remp2020/crm-users-module#post-apiv1userslogin) - you're free to store the response into your own cookie/local storage/session.

API responses can contain following HTTP codes:

ValueDescription200 OKSuccessful response, default value400 Bad RequestInvalid request (missing required parameters)403 ForbiddenThe authorization failed (provided token was not valid)404 Not foundReferenced resource wasn't foundIf possible, the response includes `application/json` encoded payload with message explaining the error further.

---

#### GET `/api/v1/token/check`

[](#get-apiv1tokencheck)

API servers for checking the validity of provided Bearer token within header.

##### *Headers:*

[](#headers)

NameValueRequiredAuthorizationBearer XXXyes##### *Example:*

[](#example)

```
curl -v –X GET http://crm.press/api/v1/token/check \
-H "Content-Type:application/json" \
-H "Authorization: Bearer XXX"
```

Response:

```
{
    "status": "ok"
}
```

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance72

Regular maintenance activity

Popularity32

Limited adoption so far

Community26

Small or concentrated contributor base

Maturity86

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~31 days

Recently: every ~63 days

Total

85

Last Release

160d ago

Major Versions

0.39.0 → 1.0.02022-03-29

1.2.1 → 2.0.02022-08-25

1.2.3 → 2.3.02023-02-17

2.11.0 → 3.0.02024-01-22

3.7.0 → 4.0.02025-03-31

PHP version history (5 changes)0.1.1PHP ^7.1

0.30.0PHP ^7.3

0.35.0PHP ^7.4

2.0.0PHP ^8.0

3.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/7c733f9bd683c3814197d8a532b7da1ba1f631bb1efe1cde5f064feab1e24877?d=identicon)[rootpd](/maintainers/rootpd)

![](https://www.gravatar.com/avatar/a05541c0b35f43d95db5342210e1d9e64242888812d13f5b096df48b6aabd863?d=identicon)[msvitok](/maintainers/msvitok)

![](https://www.gravatar.com/avatar/2c30fdbc85cda35b94f7f59399918193a0289152281abcef344ec9ee82864177?d=identicon)[markoph](/maintainers/markoph)

---

Top Contributors

[![markoph](https://avatars.githubusercontent.com/u/6843562?v=4)](https://github.com/markoph "markoph (92 commits)")[![rootpd](https://avatars.githubusercontent.com/u/812909?v=4)](https://github.com/rootpd "rootpd (61 commits)")[![miroc](https://avatars.githubusercontent.com/u/1230714?v=4)](https://github.com/miroc "miroc (15 commits)")[![tomaj](https://avatars.githubusercontent.com/u/446736?v=4)](https://github.com/tomaj "tomaj (7 commits)")[![zoldia](https://avatars.githubusercontent.com/u/1526070?v=4)](https://github.com/zoldia "zoldia (5 commits)")[![weblate](https://avatars.githubusercontent.com/u/1607653?v=4)](https://github.com/weblate "weblate (3 commits)")[![lubos-michalik](https://avatars.githubusercontent.com/u/63700066?v=4)](https://github.com/lubos-michalik "lubos-michalik (2 commits)")[![burithetech](https://avatars.githubusercontent.com/u/3502143?v=4)](https://github.com/burithetech "burithetech (2 commits)")[![mikoczy](https://avatars.githubusercontent.com/u/14105084?v=4)](https://github.com/mikoczy "mikoczy (1 commits)")[![ricco24](https://avatars.githubusercontent.com/u/1409647?v=4)](https://github.com/ricco24 "ricco24 (1 commits)")[![Matefko](https://avatars.githubusercontent.com/u/22897457?v=4)](https://github.com/Matefko "Matefko (1 commits)")

### Embed Badge

![Health badge](/badges/remp-crm-api-module/health.svg)

```
[![Health](https://phpackages.com/badges/remp-crm-api-module/health.svg)](https://phpackages.com/packages/remp-crm-api-module)
```

###  Alternatives

[cebe/php-openapi

Read and write OpenAPI yaml/json files and make the content accessable in PHP objects.

49815.4M86](/packages/cebe-php-openapi)[php-opencloud/openstack

PHP SDK for OpenStack APIs. Supports BlockStorage, Compute, Identity, Images, Networking and Metric Gnocchi

2292.2M24](/packages/php-opencloud-openstack)[mtownsend/response-xml

The missing XML support for Laravel's Response class.

1041.2M3](/packages/mtownsend-response-xml)[devizzent/cebe-php-openapi

Read and write OpenAPI yaml/json files and make the content accessable in PHP objects.

379.0M49](/packages/devizzent-cebe-php-openapi)[nfephp-org/sped-cte

API para geração e comunicação da CTe com as SEFAZ autorizadoras.

113227.7k1](/packages/nfephp-org-sped-cte)[tomaj/nette-api

Nette api

36261.8k4](/packages/tomaj-nette-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
