Download the PHP package ithilgers/api-export without Composer

On this page you can find all versions of the php package ithilgers/api-export. 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 api-export

TYPO3 Extension: API Export

TYPO3 12 License

Token-secured JSON feed API for TYPO3 records. External consumers fetch events, news and other records as machine-readable JSON, each with its own token and its own set of data.

Included resources (providers):

Features

Why This Extension?

Partner websites, apps or portals often need the same events or news that are shown on the website – but filtered differently per partner, and not publicly accessible. This extension delivers exactly that from the existing records, without duplicate data maintenance and without changes to the source extensions.

Installation

Via Composer (recommended)

Activation

After installation, activate the extension in the Extension Manager or via CLI:

Then:

  1. Update the database schema (Maintenance → Analyze Database) to create the tables for API clients, grants and detail page mappings.
  2. Flush all caches.
  3. Check: GET /api/v1/events without a token must return 401 as JSON.
  4. Create an API client with a grant (see Usage) and copy its token from the form.

No static template or plugin needs to be included; the extension configuration comes with working defaults.

Before the First Consumer

Configuration

Extension Configuration

Settings → Extension Configuration → api_export:

Key Description Default
basePath Path prefix of the API URLs (api/v1 → /api/v1/events) api/v1
headerName HTTP header that carries the token X-Feed-Token
defaultLimit Items per page without ?limit= 100
maxLimit Highest allowed value for ?limit= 500
failedAttemptsLimit Requests without a valid token per IP address and time window; further ones get 429. 0 = no limit 10
failedAttemptsInterval Time window for failedAttemptsLimit, e.g. 15 minutes, 1 hour 15 minutes

Everything else is configured in the grants.

Failed attempts: only requests without a valid token are counted, per IP address (rate limiter of the TYPO3 core, cache ratelimiter). Requests with a valid token are never counted or blocked, also not from an IP address that reached the limit. Rejected requests are logged as a warning with IP address and path, never with the token: with an active limit only the first failed attempt of an IP address per time window and once when the limit is reached, without a limit every failed attempt.

Behind a proxy or load balancer, set $GLOBALS['TYPO3_CONF_VARS']['SYS']['reverseProxyIP'] (and reverseProxyHeaderMultiValue) so that TYPO3 sees the real IP address of the caller. Otherwise all consumers share the IP address of the proxy and count towards the same limit – valid tokens still work.

Usage

API clients and their grants are managed in the backend with the List module, e.g. in a dedicated folder.

API Client – who

One record per consumer (table tx_apiexport_domain_model_client). Clients, grants and detail page mappings can only be managed by admins, even if editors are granted access to the tables.

Getting a token – there are two ways, both store only the SHA-256 hash of the token and its last 4 characters; the token itself is never stored and cannot be displayed again:

  1. In the backend form: a new client shows a freshly generated token with a copy button. Copy it before saving and pass it on to the consumer. Later, the form only shows "A token is stored, it ends with …". To replace it, check Generate new token, copy the new token and save – the previous token stops working at once. Closing the form without saving changes nothing.
  2. On the command line:

    generates a new token for the client with this uid, saves it like the form (including the record history) and prints it once. Only the token is written to stdout, notes (e.g. "client is deactivated") to stderr. An unknown or deleted uid ends with exit code 1 and changes nothing.

This way consumers can be created, blocked, limited in time and revoked individually. A copy of a client (also as part of a copied page) is deactivated and gets an unknown token, together with copies of its grants; generate a new token for it before activating it.

Copies of the database: since only hashes are stored, no token can be read from a database copy. A hash still works in the copy, though: in copies for staging or development, deactivate the clients or generate new tokens (api-export:client:token).

Grants – what

One grant per client and resource (inline records, table tx_apiexport_domain_model_feed): once a client has a saved grant for a resource, the backend no longer offers that resource for another grant of the client. A grant corresponds to an instance of the resource's list plugin – for a feed that matches a public list, copy the plugin settings of that list:

Grant field Corresponds to in the list plugin
Resource – (data type, /api/v1/<resource>)
Storage folders, Include subfolders Record storage page / starting point, recursive
Categories, Category conjunction, Include subcategories Category settings
Max. items Max. records (queryLimit / limit), 0 = all
Settings (per resource) Events: display, sorting · News: archive, sorting
Detail page Detail page

Visibility is the same as in a public list for anonymous visitors: hidden, scheduled, deleted and access-restricted (fe_group) records as well as workspace drafts are never delivered; records for "all languages" (-1) are, translations are not.

Detail Links

Items contain a link field with an absolute URL to the detail page. The detail page is resolved per record:

  1. Detail pages per folder – if the record is in a mapped folder, that folder's detail page applies.
  2. Inheritance to subfolders – otherwise the mapping of the nearest parent folder applies (via the rootline).
  3. Detail page of the grant. If that is empty as well, link is empty.

The link is built by the router of the site the detail page belongs to, in that site's default language – also if it is a different site than the one the feed was requested on. Route enhancers, aspects and the cHash of that site apply. Since there is no typolink involved, link handlers, absRefPrefix and mount points are not taken into account.

link is empty if there is no detail page, or if anonymous visitors cannot reach it: hidden, deleted, outside its publishing dates or restricted to a frontend group (also inherited via "Extend to subpages").

News types: as in the news list plugin, a news of the type internal page links to the selected page (empty if anonymous visitors cannot reach it, or if the target is not a page or URL), and a news of the type external URL links to the URL exactly as entered. Regular news link to the detail page.

API

The path is matched below the base of the site and of its language, so the API answers on every site of the installation, with or without a language prefix (/api/v1/events, /en/api/v1/events) and in subdirectory installations (/portal/api/v1/events). A trailing slash is ignored. A language prefix changes neither the data nor the links: the feed always contains the default language and records for "all languages". The API is only reachable at these URLs; there is no other entry point.

HEAD is answered like GET, without a body.

Responses (errors always as JSON {"error": …, "message": …}):

Situation Status
Valid token and active grant for the resource 200
Invalid page/limit 400
Missing or invalid token 401
No (active) grant for this resource 403
Unknown resource or path below a resource (only with a valid token) 404
Method other than GET/HEAD 405
Too many requests without a valid token from this IP address (with Retry-After) 429
Error while generating the feed (logged) 500

The token is checked before anything else: without a valid token the response is always 401, so the API does not reveal to unauthorized callers which resources exist.

Every response to a feed URL is JSON – never an HTML page or a redirect, whatever type or state the root page of the site has – and carries these headers, so that no proxy or CDN caches the token-dependent content:

Exception: middlewares that TYPO3 runs before this extension, the trusted host check and the maintenance mode (pageUnavailable_force), answer as for the whole site, i.e. possibly with HTML.

Pagination

The response always contains total (all matching items), pages, page, limit and count (items on this page). Consumers page until page >= pages. A page beyond the last one returns items: [].

Example Output (/api/v1/events?limit=1)

Extending

Adjusting the Output (PSR-14 Event)

Ithilgers\ApiExport\Event\ModifyFeedItemEvent is dispatched for every item before output. A listener in your own site package can add, change or remove fields – e.g. output the price of an event:

getRecord() returns the complete record, getClient() the requesting client (uid and title only, never token data) and getRequest() the feed request (site, language, query parameters, normalizedParams, …).

The feed is generated by a middleware, before the page is resolved: there is no $GLOBALS['TSFE'], no ContentObjectRenderer and no frontend template setup, and frontend and backend users are never authenticated. Listeners that depend on any of these do not work here; use the request and the TYPO3 APIs instead (e.g. the router of a site for links).

If a listener throws a PropagateResponseException (or ImmediateResponseException), its response is delivered (e.g. to abort the feed on purpose), only extended by the headers above; any other error results in a JSON 500.

Adding a New Resource

  1. Create a provider class. For a TCA table it is sufficient to extend Ithilgers\ApiExport\Feed\Provider\AbstractTableFeedProvider (table, category field, sorting, buildItem()); visibility, language, folders, categories and pagination are handled by the base class. Alternatively implement FeedProviderInterface directly.
  2. Make the resource selectable in the grant via a TCA override and give it a FlexForm for its own settings:

Providers are registered automatically as tagged services – no further wiring needed.

Technical Details

Requirements

How It Works

  1. The middleware (FeedTokenAuthenticator) runs right after the site has been resolved (and after the maintenance mode), before the frontend and backend user authentication, redirects and the page resolver. It detects feed requests by the remaining path of the site routing (/{basePath}/{resource} below the base of the site and its language), allows only GET/HEAD and checks token, resource, grant and pagination. All other requests are passed on unchanged.
  2. For feed requests it answers itself, without TSFE, page rendering or plugin: the FeedRenderer builds a FeedDemand from the grant (folders, category filter, settings, detail links, page) and calls the matching provider. Every item passes through ModifyFeedItemEvent. Errors are logged and answered with a JSON 500 – never with an HTML error page.
  3. Providers query their table via Doctrine. If the source extension is not installed, the provider simply returns nothing.

Since the page tree is not involved, neither the type nor the access settings of the root page matter. The regular HTML output of the source extensions is not affected.

The field "Token" of a client is a virtual TCA field without database column (type: none with its own renderType, so that the core never selects it, e.g. as a column in the List module); a DataHandler hook turns it into token_hash and token_hint. Code that writes client records directly into the database, bypassing the DataHandler, has to set token_hash (SHA-256 of the token) itself.

Running Tests

Unit and functional tests (real frontend requests through the complete middleware stack) are located in Tests/. The extension comes with its own Composer setup in .Build/ for this:

Against MariaDB/MySQL, e.g. in DDEV:

Composer blocks TYPO3 12.4 because of security advisories (ELTS only). For the test installation this is disabled in composer.json under config.policy.advisories.block; it has no effect on projects that install the extension.

Tests and build files are excluded from release archives via .gitattributes.

Compatibility

Extension Version TYPO3 Version PHP Version
1.x 12.4 LTS 8.1+

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

This extension is licensed under the GNU General Public License v2.0 or later.

Support

For bugs, feature requests, or questions:

Credits

Developed by Theodor Hilgers.


Keywords: TYPO3, API, JSON, feed, export, events, news, sf_event_mgt, token authentication


All versions of api-export with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
typo3/cms-backend Version ^12.4
typo3/cms-core Version ^12.4
typo3/cms-frontend Version ^12.4
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 ithilgers/api-export contains the following files

Loading the files please wait ...