Download the PHP package os2forms/os2forms_rest_api without Composer

On this page you can find all versions of the php package os2forms/os2forms_rest_api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package os2forms_rest_api

OS2Forms REST API

We use Webform REST to expose a number of API endpoints.

Installation

Authentication

We use 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 )
  3. has a generated key (User > Edit > 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

Name Path Methods
Webform Elements /webform_rest/{webform_id}/elements GET
Webform Fields /webform_rest/{webform_id}/fields GET
Webform Submission /webform_rest/{webform_id}/submission/{uuid} GET
Webform Submissions /webform_rest/{webform_id}/submissions GET
Webform Submit /webform_rest/submit POST
File /entity/file/{file_id} GET

Examples

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:

Response:

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:

Response:

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

Response:

The actual document content.

Submit webform

Request:

Response:

(the sid value is a webform submission uuid).

Webform submissions

You can filter results based on submission time by adding query parameters to the URL:

Name Value Example
starttime PHP Date and Time Formats yesterday
endtime PHP Date and Time Formats 2023-10-23

If left out, filtering upon the left out parameter will not be done.

This example requests all submissions on or after October 1st, 2023:

Request:

Response:

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 > Access > View any submissions > Users to specify which users can access a webform's data.

Technical details

The custom access check is implemented in an event subscriber listening on the KernelEvents::REQUEST event. See EventSubscriber::onRequest 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.

Linked data

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

Attachments

Attachment elements are added to GET responses:

Technical details on linked data and attachments

In order to add linked data, we apply a patch, webform_rest_submission.patch, to the Webform REST module and implement an event subscriber, WebformSubmissionDataEventSubscriber, to add the linked data.


All versions of os2forms_rest_api with dependencies

PHP Build Version
Package Version
Requires cweagans/composer-patches Version ^1.7
drupal/key_auth Version ^2.0
drupal/webform_rest Version ^4.1
os2forms/os2forms Version ^3.13
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package os2forms/os2forms_rest_api contains the following files

Loading the files please wait ....