Setting up Required Modules
The Rules API POST module provides a working sample kit for building REST based workflow Rules. Out of the box it provides most of the pieces needed to synchronize content between one or more Drupal sites. This is SAMPLE code that works but you will likely need to modify it for your own real-life needs. requirements
The Rules API Post Module Provides:
- A new Rules action plugin called API POST
- Two new Content Types
API POST, for sending API Post Transactions
API Post Transaction, for receiving API Posts - A sample rule Configuration
- Documentation and Community (issue queue)
Notes on running this module in development
Under the hood, Curl is being used to make the needed HTTP requests. Curl is secure by nature and will not be happy with Self-Signed certificates typically found on local development builds. If you are running with an invalid cert, you will need to override some curl settings in the module.
On our development box, note how a new array 'verify' key is added in the curl $options area. This key is not setup by default so you may need to add it depending on your HTTPS setup. Also, this area of the module/plugin is where you can make your own tweaks to how to the Curl HTTP requests fire off. Note how the 'Accept' and 'Content-Type' keys have hard coded values, you may need to change these if you're POSTing to some other (non-Drupal) API.
Self-Signed DEV Config Sample
rules_api_post/src/Plugin/RulesAction/RulesAPI_POST.php
$client = \Drupal::httpClient();
$url =$url[0];
$method = 'POST';
// For Self-signed certificates, Curl will need to no the location of certificate.
// Add a "verify" key to the options array, pointing to your certificate file on disk.
// 'verify' => '/etc/ssl/certs/snakeoil.crt',
$options = [
'verify' => '/etc/ssl/certs/snowmaid.crt',
'auth' => [
$apiuser,
$apipass
],
'timeout' => '2',
'body' => $serialized_entity,
'headers' => [
'Content-Type' => 'application/hal+json',
'Accept' => 'application/hal+json',
'X-CSRF-Token' => $apitoken
],
];Required Enabled Core and Contributed Modules
Rules: Rules, Rules API Post
Web Services: HAL, HTTP Basic Authentication, REST UI, RESTful Web Services, Serialization
Any additional required modules, if needed, should get flagged when you try to install this list.
D8 Rules Essentials Note:
We are testing and documenting (screenshoting) without the D8 Rules Essentials module enabled. While we do not have it enabled here, you will probably want to install/enable in your environment.
Rules HTTPS Client Note:
Rules API Post (this module) started from a fork of the Rules HTTPS Client module. This was done to add Basic Authentication and to make a clean break for D8 module code/support. The Rules HTTPS Client module does have a D8 version. You may want to take a look at it's features.
Drush Notes
# Install
drush pm:enable rules_api_post
#Uninstall
drush pmu rules_api_post
Tips on Uninstalling:
The two content types provided by this module will be deleted when it is uninstalled. Any existing content for these types will be orphaned without a Content Type. Search and delete all associated content before uninstalling.

Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion