Giter Club home page Giter Club logo

rest-api's Introduction

phpList core module

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

About phpList

phpList is an open source newsletter manager. This project is a rewrite of the original phpList.

About this package

This is the core module of the successor to phpList 3. It will have the following responsibilities:

  • provide access to the DB via Doctrine models and repositories (and raw SQL for performance-critical parts that do not need the models)
  • routing (which the web frontend and REST API will use)
  • authentication (which the web frontend and REST API will use)
  • logging
  • a script for tasks to be called from the command line (or a cron job)
  • tasks to create and update the DB schema

Please note that this module does not provide a web frontend or a REST API. There are the separate modules phpList/web-frontend and phpList/rest-api for these tasks.

This module should not be modified locally. It should be updated via Composer.

Installation

Since this package is only a service required to run a full installation of phpList 4, the recommended way of installing this package is to run composer install from within the phpList base distribution which requires this package. phpList/base-distribution containrs detailed installation instructions in its README.

Contributing to this package

Contributions to phpList repositories are highly welcomed! To get started please take a look at the contribution guide. It contains everything you would need to make your first contribution including how to run local style checks and run tests.

Code of Conduct

This project adheres to a Contributor Code of Conduct. By participating in this project and its community, you are expected to uphold this code.

Structure

Running the web server

The phpList application is configured so that the built-in PHP web server can run in development and testing mode, while Apache can run in production mode.

Please first set the database credentials in config/parameters.yml.

Development

To run the application in development mode using PHP's built-in server, use this command:

bin/console server:run -d public/

The server will then listen on http://127.0.0.1:8000 (or, if port 8000 is already in use, on the next free port after 8000).

You can stop the server with CTRL + C.

Development and Documentation

We use phpDocumentor to automatically generate documentation for classes. To make this process efficient and easier, you are required to properly "document" your classes,properties, methods ... by annotating them with docblocks.

More about generatings docs in PHPDOC.md

Testing

To run the server in testing mode (which normally will only be needed for the automated tests, provide the --env option:

bin/console server:run -d public/ --env=test

Production

For documentation on running the application in production mode using Apache, please see the phpList base distribution README.

Changing the database schema

Any changes to the database schema must always be done both in phpList 3 and later versions so that both versions always have the same schema.

For changing the database schema, please edit resources/Database/Schema.sql and adapt the corresponding domain model classes and repository classes accordingly.

Developing phpList modules (plugins)

In phpList, plugins are called modules. They are Composer packages which have the type phplist-module.

Bundle and route configuration

If your module provides any Symfony bundles, the bundle class names need to be listed in the extra section of the module's composer.json like this:

"extra": {
    "phplist/core": {
        "bundles": [
            "Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle",
            "PhpList\\Core\\EmptyStartPageBundle\\PhpListEmptyStartPageBundle"
        ]
    }
}

Please note that the key of the section with extra needs to always be phplist/core, not the name of your module package. Please have a look at the composer.json in the rest-api module for an example.

Similarly, if your module provides any routes, those also need to be listed in the extra section of the module's composer.json like this:

"extra": {
    "phplist/core": {
        "routes": {
            "homepage": {
                "resource": "@PhpListEmptyStartPageBundle/Controller/",
                "type": "annotation"
            }
        }
    }
}

You can also provide system configuration for your module:

"extra": {
    "phplist/core": {
        "configuration": {
            "framework": {
                "templating": {
                    "engines": [
                        "twig"
                    ]
                }
            }
        }
    }
}

It is recommended to define the routes using annotations in the controller classes so that the route configuration in the composer.json is minimal.

Accessing the database

For accessing the phpList database tables from a module, please use the Doctrine model and repository classes stored in src/Domain/ in the phplist/core package (this package).

For accessing a repository, please have it injected via dependency injection. Please do not get the repository directly from the entity manager as this would skip dependency injection for that repository, causing those methods to break that rely on other services having been injected.

Currently, only a few database tables are mapped as models/repositories. If you need a mode or a repository method that still is missing, please submit a pull request or file an issue.

Accessing the phpList data from third-party applications

To access the phpList data from a third-party application (i.e., not from a phpList module), please use the REST API.

Copyright

phpList is copyright (C) 2000-2021 phpList Ltd.

rest-api's People

Contributors

fenn-cs avatar michield avatar oliverklee avatar schmidtsabine avatar xh3n1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rest-api's Issues

Add more functions to the api

So in resume, (something that is not precisely specified on the docs) atm of write this, the api only allows you to:

  • Create and Destroy Session
  • Retrieve all subscriber lists
  • Retrieve the info of a single list
  • Delete a list
  • Retrieve the subscribers of a list
  • Add a subscriber

although the api is a great step in phplist its current functions/calls are very very reduced and of low usability

I would like to ask more functions/calls that make the api a little more functional like:

  • Create a list
  • Add subscribers to a list
  • Remove subscribers
  • Remove subscribers from a list
  • Run a list/campaign

And other calls/functions that make more usable the Api

Thanks in advance

"Bad request"message displayed when you enter empty credentials

Short problem description

"Bad request" message displayed when you enter empty credentials or Empty JSON data

Expected behaviour

eg: if you enter empty crendetials, it is expected incomplete credentials message

Actual behaviour

"Bad request" message

How can target a LIST when add a new subscriber via php , How can I add attributes to the JSON?

Dear All
Am testing the Rest API, and it works great.
The problem is how can I target a specific List.
and how can I add the attributes to the json?

try {
    $subscriberRequest = $client->request('POST', $base_uri . '/subscribers',
        [
            'headers' => [
                'Authorization' => 'Basic ' . $credentials,
                'Content-Type' => 'application/json',
            ],
            'json' => [
                'email' => '[email protected]',
                'confirmed' => true,
                'blacklisted' => false,
                'html_email' => true,
                'disabled' => false,
                
            ],
        ]
    );
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
}

I can found nothing in the API Doc
https://github.com/phpList/rest-api/blob/master/docs/Api/RestApi.apib

Request: Trigger sending of double-opt-in / confirmation mail

In the JSON data for the /api/v2/subscribers endpoint, for adding new subscriber, there should be an (optional) attribute for triggering the sending of the confirmation email (double opt-in) to the new subscriber. Such as "request_confirmation" : true.

This would be very helpful when e.g. using a custom subscribe form on a business website which interacts with phpList via the new API. Especially for websites in the European Union where a double-opt-in is mandatory.

API errors after upgrade to 3.6.3 - why is it looking for composer.json

Short problem description

I almost had API working with 3.6.2, but was having trouble authenticating (getting credentials) with an error similar to this one: #57 so I tried upgrading. Admin site works fine and doesn't throw errors; however, trying to access the API is causing errors, see below:

Steps to reproduce

  1. Upgrade to 3.6.3 from 3.6.2
  2. Attempt to use phplist API

Expected behaviour

I'd love to be able to use the API. Authentication is another thing I guess I'll tackle later. It was giving me a really hard time before the upgrade to 3.6.3 from 3.6.2

Actual behaviour

Stack trace:
#0 /home/sierdcqi/public_html/lists/base/vendor/phplist/core/src/Core/ApplicationKernel.php(70): PhpList\Core\Core\ApplicationStructure->getApplicationRoot()
#1 /home/sierdcqi/public_html/lists/base/vendor/phplist/core/src/Core/ApplicationKernel.php(169): PhpList\Core\Core\ApplicationKernel->getApplicationDir()
#2 /home/sierdcqi/public_html/lists/base/vendor/phplist/core/src/Core/ApplicationKernel.php(147): PhpList\Core\Core\ApplicationKernel->readBundleConfiguration()
#3 /home/sierdcqi/public_html/lists/base/vendor/phplist/core/src/Core/ApplicationKernel.php(31): PhpList\Core\Core\ApplicationKernel->bundlesFromConfiguration()
#4 /home/sierdcqi/public_html/lists/base/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(493): Ph in /home/sierdcqi/public_html/lists/base/vendor/phplist/core/src/Core/ApplicationStructure.php on line 56

$corePackageIsRootPackage is returned false. Exception thrown because "there is no composer.json in the application root."
This package is installed on my server per the installation instructions and as mentioned above, is otherwise working fine except the API.

System configuration

Package version

Phplist version 3.6.3

PHP and Composer version

LiteSpeed Server
PHP version: 7.3.27
PHP post max size: 1 GB
PHP time limit: 1500
PHP max input vars: 2000
cURL version: 7.71.0, OpenSSL/1.1.1d

Add an expiry for session tokens

REST sessions should expire a certain time after the last interaction, i.e., the timer is reset each time the token ist used. This should help against attackers that find an old token.

Add security headers to prevent XSS

Some browsers such as Internet Explorer require the ​nosniff header to be set and potentially dangerous characters to be encoded. Otherwise other websites embedding this resource could trigger a XSS vulnerability.

Add host URL documentation to RestApi.apib

Currently it is unclear which base URL should be used for sending API requests to. I believe that the standard label for this in API Blueprint format is 'HOST'. Please add the URL that should be used for receiving requests to the RestApi.apib file.

[META] phase 2

This meta ticket covers the rest-api-related tasks for phase 2. The core-specific tasks are listed in phpList/core#125, the base-distribution-specific tasks are listed in phpList/base-distribution#18, the the web-distribution-specific tasks are listed in phpList/web-frontend#16.

  • #21 fix the MySQL DB import in Travis
  • #22 make sure Composer installs the latest version of the dependencies (was a packagist configuration issue)
  • #23 get the Travis builds to work on Trusty
  • #24 return error 400 for bad data, not a 500
  • #25 return a JSON content type for the response
  • #26 rename the branch alias from 4.0.0-dev to 4.0.x-dev https://getcomposer.org/doc/articles/aliases.md#branch-alias
  • #28 add the Symfony console
  • #29, #31 add host URL documentation
  • #37 make this bundle known to the core
  • #37 use the module registration hook
  • #40 move the REST routing configuration to the rest-api package
  • #56 switch to FOSRestBundle
  • #62 finish the authentication, AKA REST API for handling authentication
  • #62, REST API for reading lists and creating subscribers

'Incomplete credentials' error returned, though credentials are provided

Short problem description

The following JSON request is sent but 'incomplete credentials' are reported:

{
    "loginName": "admin",
    "password": "password"
}

Using a local PHP development server (http://127.0.0.1:8000/api/v2/sessions), with .htaccess in root dir removed (to avoid permission issues).

Steps to reproduce

  1. Send a login request with above JSON using Postman Chrome app
  2. Observe reported error

Expected behaviour

Session is created, success status returned

Actual behaviour

Error reported

System configuration

Package version

Installed base-distribution via composer

PHP and Composer version

PHP 7.1.11
Composer version 1.5.2 2017-09-11 16:59:25

subscriptions method return 404 not found

Short problem description

After settle phplist on my ubuntu server, the rest of the api method work fine, but except the subscriptions method return 404 not found when i use post method to https://example.com/lists/api/v2/subscriptions. i know this funtion is not include in default so i hv configure the file in /lists/base/rest-api like this PR, but it seem something still not right. any suggestion? thanks

System configuration

Package version

phplist 3.6.4

PHP and Composer version

PHP 7.4.9 Composer 1.10.10

[META] phase 3

  • #74 Provide the code language in markdown files
  • #75 make sure everything is fine both with the lowest as well as highest version of the dependencies http://naderman.de/slippy/slides/2017-07-13-T3DD17-Composer-Best-Practices.pdf
  • #82 REST action: list of subscribers for a list
  • #89 REST action: get list info
  • document testing via Postman
  • #91 Use the database test trait and web test base class
  • #98 REST action: delete list
  • #101 REST action: destroy session
  • REST action: update list
  • #81, #??? add system tests for all three environments
  • require a JSON content type for the request and add tests for requests without content type
  • in the wiki or README, create a table with possible resource/action combinations and their status
  • document how to test this package without the base-distribution package
  • make the project structure more similar to the default Symfony project structure
  • add nice 404 error JSON responses
  • #32 add error handling for illegal request methods
  • #57 improve the error messages for missing json content type headers and incomplete credentials
  • block authentication for disabled admins
  • create a REST reading list in the wiki
  • #32 Add error handling for illegal request methods (MethodNotAllowedException)
  • #48 Look into nelmio/api-doc-bundle for creating API docs
  • research how to have different levels of detail for the response
  • research how to best model actions via a REST API
  • research jsonapi.org
  • rework the used HTTP status codes

Sessions error: "Field 'entered' doesn't have a default value"

Short problem description

When logging in using the API via the /sessions route, correct credientials are provided, but the following error is returned:

{
    "code": 500,
    "message": "An exception occurred while executing 'INSERT INTO phplist_admintoken (expires, value, adminid) VALUES (?, ?, ?)' with params [\"2017-12-04 15:09:49\", \"15574d49a0c75ff3f2f498e92ec9ca46\", 1]:\n\nSQLSTATE[HY000]: General error: 1364 Field 'entered' doesn't have a default value"
}

Steps to reproduce

  1. Install using base-distribution via composer
  2. Attempt to log in using Postman and the REST API using valid credentials, and an existing phpList 3 database

Expected behaviour

Login successful, token info is returned

Actual behaviour

Exception is returned
postman_340

Add error handling for illegal request methods (MethodNotAllowedException)

Currently if an illegal request method is used for communication with the API, no response is returned and a PHP Fatal Error is triggered (Uncaught Symfony\Component\Routing\Exception\MethodNotAllowedException in /base-distribution/var/cache/prod/phplist4coreProdProjectContainerUrlMatcher.php:58).

Add exception handling and error reporting for such cases.

[META] REST API Feature descriptions

(moved from phpList/core#177)

Feature descriptions

This describes some required features of phpList 4. The features will be used to accommodate inter-dependency between groups of features and related functionality.

Subscribers

  • Subscriber sign-up

    A new subscriber registers themselves

    • Required:
      • Valid subscriber data including preferences is stored
      • Subscriptions to supplied lists are created
      • If no lists are supplied then no subscription is created
      • The confirmation status is unconfirmed
      • An email confirmation request is sent to the supplied address
      • When the confirmation link is visited the subscriber is marked confirmed
    • Optional:
      • Supplied values for existing subscriber attributes are stored
      • Supplied values for non-existing subscriber attributes trigger error
  • Import subscribers

    One or more subscribers are imported by an administrator

    • Required:
      • All validated subscribers are stored
      • Existing subscribers are matched against those being imported based on email address or foreign key (where available)
      • If update subscription is requested then identified subscribers will have their data replaced where it differs
      • Return a summary of the import result with total subscribers imported, updated, duplicated, and errored
    • Optional:
      • If dry run is requested then return a summary of import results but do not store subscribers
      • If send confirmation is requested then imported subscribers are stored unconfirmed
      • If send confirmation is requested then a confirmation link is created and email sent
      • If email validation is requested then subscribers with invalid email addresses will be discarded
      • If old email retention is requested then where old and new email addresses conflict, prefer the old
      • If invalid assignation is requested then parse and apply custom email address where invalid addresses are provided

Subscriptions

To be done

Lists

To be done

[META] phase 4

  • upgrade phpstan
  • REST action: subscriber info
  • REST action: delete subscriber
  • REST action: update subscriber
  • REST action: create list
  • REST action: list of subscriptions for subscriber
  • REST action: list of subscriptions for list
  • REST action: create subscription
  • REST action: update subscription
  • REST action: delete subscription
  • REST action: info for subscription
  • research HAL JSON API
  • drop the DI class and load the services via composer.json instead
  • decide on what to log
  • log things
  • read up on REST formats
  • support HTTP caching (last modified header, eTag, HEAD requests?), also research whether and how to use and set “valid until” headers
  • research GraphQL
  • investigate Symfony filters for authentication
  • performance testing to have some numbers
  • add a REST route for /api/
  • add a REST route for /api/v2/
  • investigate https://scrutinizer-ci.com/ and maybe use it
  • investigate https://swagger.io/
  • use stylecio to fix the style in PRs
  • delete the old rewrite

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.