WooCommerce API Healthiness

The Autoship Cloud plugin integrates your WooCommerce site with QPilot using the WooCommerce REST API (version 2).

While the Autoship Cloud plugin does not add to, change or modify your site's REST API, it is very important that your site's WooCommerce REST API is enabled and fully functional to ensure a successful connection with QPilot.

If you are experiencing issues connecting Autoship Cloud to QPilot, it's a good idea to test the WooCommerce API to ensure it is accessible and healthy.

Note: The REST API is a feature of WooCommerce and you may test your site's REST API with or without the Autoship Cloud powered by QPilot plugin being active on your site at any time by following WooCommerce's documentation here.

Testing the WooCommerce API

  1. Navigate to WooCommerce > Settings >> Advanced >> REST API
  2. In older versions of WooCommerce, you may need to select "Enable the REST API" and Save Changes before proceeding.

  3. In the REST API tab, add a new API Key with the settings below:

    Description: "Test Key" (or any description you choose)
    User: Select a user who has Administrator User privileges for the Wordpress site
    Permissions: Read/Write
  4. Follow the guide for  Making a Basic Request to test the WooCommerce API with your site.

How QPilot Makes API Requests

GET Request

Used to securely pass Data from WooCommerce to QPilot to keep data synchronized, including:

  • Order Data
  • Product Data
  • Customer Data
  • Tokenized Payment Data

POST Request

Used to securely create WooCommerce Orders when processing a Scheduled Order over WooCommerce REST API

PUT Request

Used to securely update WooCommerce Order data when processing a Scheduled Order over the REST API.
Also used to securely update product availability data for WooCommerce Products and add QPilot data to Reports and Notifications in Wordpress.

Common Error Responses

401 Unauthorized / 403 Forbidden

  1. Check that the WooCommerce API is enabled on the site. This setting is found in the WP Admin under WooCommerce > Settings > Advanced (tab) >> REST API.
  2. Check that there is a valid WooCommerce API key for "Autoship - QPilot". The API keys are listed under WP-Admin > WooCommerce > Settings > Advanced (tab) >> REST API.
    1. If there is no API key for "Autoship - QPilot", follow the guide to Connect Autoship Cloud.
    2. Ensure that the associated user account for this API key is a site administrator with full privileges to manage WooCommerce.
  3. Password protecting access to your site using settings on your WordPress Site or using .htaccess rules to restrict access. This will be problematic for incoming requests.
  4. Disable any plugins that are blocking access to the site.

400 Bad Request

The 400 error code indicates that the request is invalid, e.g. using an unsupported HTTP method.  

The error is most common with staging sites using an insecure URL ("http" instead of "https"). This is error is documented by WooCommerce's REST API docs here: https://woocommerce.github.io/woocommerce-rest-api-docs/#errors.

If this is the case, you may want to ask your hosting provider to enable your staging site to be a secure URL (use " https://mysite.staging.myhost.com" instead of "http"), so you can then connect your site's API without using the secure URL.

404 Error Resources Not Found

The 404 error indicates that the request reached the server, however the information requested was not found.

This error can be caused by a url redirect (configured within your site's htaccess or DNS) or setting . 

Examples of common redirects resulting in a 404 Error:

  • Secure to insecure site redirect ("https" redirecting to "http" protocol) 
  • A site url that redirects to a different url

Resolving a redirect issue:

  1. Navigate to your QPilot Merchant Account and edit your connected site's settings.
  2. Within the "General Settings" tab, edit the url of your connected site to the url your site is redirecting to. 
  3. Select "Update" to confirm your changes.
  4. After updating your url, within your Wordpress Admin, visit WP-Admin > Autoship Cloud > Settings and then select "Test Integration". This will attempt to test your site's connection to QPilot and result in a healthy connection status if the issue is fixed.

500 Internal Server Error

The 500 error indicates a fatal exception has been thrown on the server. This type of error can be caused by many different types of issues, and the source of the error must be tracked down.

  1. Check the server error log for any obvious errors. Contact your site administrator to correct these errors then try again.
    • A quick find for "500" in your error logs (see how to enable your error log) can usually point out the errors preceding the 500 error (usually another plugin)
  2. De-activate any plugins that may be having errors first; you may want to de-activate all plugins on the site except for WooCommerce. Test the API and activate additional plugins one at a time until the source of the error is found.
  3. Change the current theme to a basic theme (for example: WooCommerce's Storefront) then test the API. The default Wordpress theme should not produce any errors. 

Healthy Connection Result with Errors Displaying

Sometimes you may see errors appear within a healthy API test response.
See this example screenshot where a 500 error is returned within a successful API test response: 

This means that it is possible to connect with the URLs (the "endpoints") for your site and successfully test your API, but your site is responding to an API request with "other" errors  (for example returning a non-standard error message or one that is not a common API response). 

This does not necessarily mean that the connection with your site is unhealthy or that Autoship Cloud's connection with QPilot is not working. Instead, it means that your site may have errors within its code. Typically, this type of situation is caused when another plugin installed on your site is causing an unexpected or fatal error. 

Suggested Steps to Resolve This Type of Error

  1. Run the "test connection" action again. 
    1. This helps clear any notices and asks QPilot to retest URLs.
    2. In some cases, the error message clears on its own. If so, this could be that the cause of this issue was resolved (with a plugin update for example) and is no longer causing the notice. 
  2. If the error persists, you'll want to debug this as you would any error within Wordpress.
    1. Enable the WP Error log ( https://wordpress.org/support/article/debugging-in-wordpress/ ). 
    2. The Error log can then be used to troubleshoot which file installed on your site might be causing the problematic response to the API Health Check. 
    3. Pro Tip! You may also configure the WP Error Log to not display to customers and provide additional error details.
PHP Warnings and Errors

Sometimes the WooCommerce API can produce PHP error messages in the response instead of properly formatted JSON.

  1. De-activate all plugins on the site except for WooCommerce and then test the API and activate additional plugins one at a time until the source of the error is found.
  2. Change the current theme to the default Wordpress theme (for example, Storefront or the default "2017" Wordpress theme) then test the API. These default themes should not produce any errors. 

Product Sync Related Errors

Sometimes your firewall will block http requests to endpoints used by QPilot to update your product availability during product synchronization. If you are having product sync errors regarding product availability, be sure the following http requests and their endpoints are not being blocked:

  1. GET: /wp-json/wc/v2/products/<id> 

  2. PUT: autoshipcloud/v1/product

Manually Testing QPilot Integration with Postman

Sometimes manually testing the API Healthiness with a client like Postman can assist in troubleshooting. Sometimes hosting providers restrict access to sites, preventing site visitors (including http requests from external sources like the QPilot API) from getting appropriate responses (for instance: html log in instead of the expected JSON object). Some hosting providers restrict certain http requests (commonly seen: PUT or update requests). Testing the API Healthiness manually will give additional details to a failed http request including request type, status, and the response body.

This is a similar test to that outlined in WooCommerce's documentation: Making a Basic Request. We use the WooCommerce API keys to authenticate make the following 3 requests:

  • GET- {your site url}/wp-json/wc/v3/products/
  • POST- {your site url}/wp-json/autoshipcloud/v1/statuscheck/post
  • PUT- {your site url}/wp-json/autoshipcloud/v1/statuscheck/put

Any failure response should be recorded to share with your hosting provider.

Still need help? Contact Us Contact Us