PHPackages                             os2forms/os2forms\_rest\_api - 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. os2forms/os2forms\_rest\_api

ActiveDrupal-module[API Development](/categories/api)

os2forms/os2forms\_rest\_api
============================

OS2Forms REST API

2.3.0(5mo ago)04.5k1MITPHP

Since Dec 21Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/OS2Forms/os2forms_rest_api)[ Packagist](https://packagist.org/packages/os2forms/os2forms_rest_api)[ RSS](/packages/os2forms-os2forms-rest-api/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (11)Used By (0)

OS2Forms REST API
=================

[](#os2forms-rest-api)

We use [Webform REST](https://www.drupal.org/project/webform_rest) to expose a number of API endpoints.

Installation
------------

[](#installation)

```
composer require os2forms/os2forms_rest_api
vendor/bin/drush pm:enable os2forms_rest_api
```

Authentication
--------------

[](#authentication)

We use [Key auth](https://www.drupal.org/project/key_auth) for authenticating api users.

A user can access the Webform REST API if

1. it has the “OS2Form REST API user” (`os2forms_rest_api_user`) role,
2. has been granted access to the form (see [Custom access control](#custom-access-control) )
3. has a generated key (User &gt; Edit &gt; Key authentication; `/user/«user id»/key-auth`).

The “OS2Form REST API user” role gives read-only access to the API. To get write access, a user must also have the “OS2Form REST API user (write)” (`os2forms_rest_api_user_write`) role.

Endpoints
---------

[](#endpoints)

NamePathMethodsWebform Elements`/webform_rest/{webform_id}/elements`GETWebform Fields`/webform_rest/{webform_id}/fields`GETWebform Submission`/webform_rest/{webform_id}/submission/{uuid}`GETWebform Submissions`/webform_rest/{webform_id}/submissions`GETWebform Submit`/webform_rest/submit`POSTFile`/entity/file/{file_id}`GETExamples
--------

[](#examples)

### Get file content from webform submission

[](#get-file-content-from-webform-submission)

Example uses `some_webform_id` as webform id, `some_submission_id` as submission id and `dokumenter` as the webform file element key.

Request:

```
> curl --silent --header 'api-key: …' https://127.0.0.1:8000/webform_rest/some_webform_id/submission/some_submission_uuid
```

Response:

```
{
  …,
  "data": {
    "navn": "Jack",
    "telefon": "12345678"
    "dokumenter": {
      "some_document_id",
      "some_other_docuent_id"
    }
  }
}
```

Use the file endpoint from above to get information on a file, substituting `{file_id}` with the actual file id (`some_document_id`) from the previous request.

Request:

```
> curl --silent --header 'api-key: …' https://127.0.0.1:8000/webform_rest/entity/file/some_document_id
```

Response:

```
{
  …,
  "uri": [
    {
      "value": "private:…",
      "url": "/system/files/webform/some_webform_id/…"
    }
  ],
  …
}
```

Finally, you can get the actual file by combining the base url with the url from above response:

```
> curl --silent --header 'api-key: …' http://127.0.0.1:8000/system/files/webform/some_webform_id/…
```

Response:

The actual document content.

### Submit webform

[](#submit-webform)

Request:

```
> curl --silent --location --header 'api-key: …' --header 'content-type: application/json' https://127.0.0.1:8000/webform_rest/submit --data @-  curl --silent --header 'api-key: …' 'https://127.0.0.1:8000/webform_rest/some_webform_id/submissions?starttime=2023-10-01'
```

Response:

```
{
  "webform_id": "some_webform_id",
  "starttime": "2023-10-01",
  "submissions": {
    "123": "https://127.0.0.1:8000/da/webform_rest/some_webform_id/submission/44b1fe1b-ee96-481e-b941-d1219d1dcb55",
    "124": "https://127.0.0.1:8000/da/webform_rest/some_webform_id/submission/3652836d-3dab-4919-b880-e82cbbf3c24c"
  }
}
```

Custom access control
---------------------

[](#custom-access-control)

To give access to webforms, you need to specify a list of API users that are allowed to access a webform's data via the API.

Go to Settings &gt; Access &gt; View any submissions &gt; Users to specify which users can access a webform's data.

### Technical details

[](#technical-details)

The custom access check is implemented in an event subscriber listening on the `KernelEvents::REQUEST` event. See [EventSubscriber::onRequest](src/EventSubscriber/EventSubscriber.php) for details.

In order to make documents accessible for api users the Key auth `authentication_provider` service has been overwritten to be global. See [os2forms\_rest\_api.services](os2forms_rest_api.services.yml).

Linked data
-----------

[](#linked-data)

To make using the REST API easier we add linked data to `GET` responses:

```
{
  …
  "data": {
    "file": "87",
    "name": "The book",
    "linked": {
      "file": {
        "87": {
          "id": "87",
          "url": "http://os2forms.example.com/system/files/webform/os2forms/1/cover.jpg",
          "mime_type": "image/jpeg",
          "size": "96757"
        }
      }
    }
  }
}
```

Attachments
-----------

[](#attachments)

Attachment elements are added to `GET` responses:

```
{
  …
  "data": {
    …
    "attachments": {
      "attachment_pdf": {
        "name": "Attachment (pdf)",
        "type": "pdf",
        "url": "http://os2forms.example.com/da/webform/os2forms/submissions/42/attachment/pdf/pdf.pdf"
      },
      …
    }
  }
}
```

### Technical details on linked data and attachments

[](#technical-details-on-linked-data-and-attachments)

In order to add linked data, we apply a patch, [webform\_rest\_submission.patch](patches/webform_rest_submission.patch), to the Webform REST module and implement an event subscriber, [WebformSubmissionDataEventSubscriber](src/EventSubscriber/WebformSubmissionDataEventSubscriber.php), to add the linked data.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance72

Regular maintenance activity

Popularity21

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 64.8% of commits — single point of failure

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 ~120 days

Recently: every ~173 days

Total

10

Last Release

158d ago

Major Versions

1.1.0 → 2.0.02023-10-24

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/33924554?v=4)[ITK Development](/maintainers/itk-dev)[@itk-dev](https://github.com/itk-dev)

![](https://www.gravatar.com/avatar/9d838759fdace714b1c00ca64212935cb06568a6d641169301aa2ed05eed16f9?d=identicon)[rimi-itk](/maintainers/rimi-itk)

---

Top Contributors

[![jekuaitk](https://avatars.githubusercontent.com/u/78410897?v=4)](https://github.com/jekuaitk "jekuaitk (35 commits)")[![rimi-itk](https://avatars.githubusercontent.com/u/11267554?v=4)](https://github.com/rimi-itk "rimi-itk (19 commits)")

### Embed Badge

![Health badge](/badges/os2forms-os2forms-rest-api/health.svg)

```
[![Health](https://phpackages.com/badges/os2forms-os2forms-rest-api/health.svg)](https://phpackages.com/packages/os2forms-os2forms-rest-api)
```

###  Alternatives

[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

74513.7M114](/packages/meilisearch-meilisearch-php)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)[hubspot/api-client

Hubspot API client

23914.2M16](/packages/hubspot-api-client)[botman/driver-telegram

Telegram driver for BotMan

92437.3k6](/packages/botman-driver-telegram)

PHPackages © 2026

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