Integration with external service not working
This usually happens when the external service instead of calling a standard endpoint, calls the homepage without any Post request, but just. adding some query arguments to the URL.
Imagine you want to connect your website with an external service, and that service provides a plugin for the integration.
The external service will need to get information from your WordPress website. A clean way to do it would be by calling an endpoint that looks like https://example.com/wp-json/wp/v2/sample-variable1/sample-value1/sample-variable2/sample-value2 Then your website would answer with some information.
Until the external service calls the endpoints respecting the best practices, you will have no problems.
But what happens if it calls the homepage just adding some query arguments?
Imagine it is called http://example.com/?sample-variable1=sample-value1&sample-variable2=sample-variable2, and on the homepage, you have disabled their integration plugin.
Simple, the integration between your site and the external service will not work, because the code of the integration plugin will not run.
Read further to see how you can solve it.
How to solve it.
If what is written above is your case, then you will solve it by following these steps:
- Go to Custom URLs => Frontend URLs
- Add a row with the pattern [home]?*
- Enable the integration plugin
- Save the changes
By doing so, if the requested URL of the homepage includes any query argument, the integration plugin will be active.
What is described above is the easiest way to solve the issue, but not the best one. Why? Because you may not want to enable the integration plugin every time the URL includes a query argument. Imagine for example when someone shares the URL of your homepage. In that case, probably you will not need the integration plugin.
If you want to enable the integration plugin only when the external service calls the homepage, you can still use the Frontend URLs, but you should first discover what are the query arguments added to the URL, and then build the right pattern.
To discover the query arguments you can do as following:
Enable the debug in wp-config.php by adding the following lines of code to the file wp-config.php before the comment /* That’s all, stop editing! Happy publishing. */:
define( 'WP_DEBUG', true ); define( 'WP_DEBUG_DISPLAY', false ); define( 'WP_DEBUG_LOG', true );
If for example, the external service calls https://example.com/sample-variable1=sample-value1, then in wp-config.php you will see something that looks like this:
******* FDP Logger Start ******* URL: example.com/?sample-variable1=sample-value1 $_GET: Array ( [sample-variable1] => sample-value1 ) $_REQUEST: Array ( [sample-variable1] => sample-value1 ) $_POST: Array ( ) ....