WooCommerce API Healthiness

Table Of Contents

  1. How QPilot Makes API Requests
  2. Common Error Responses
    1. 400 Bad Request
    2. 401 Unauthorized / 403 Forbidden
    3. 401 Sorry You Are Not Allowed To Create Resources
    4. 404 Error Resources Not Found
    5. 500 Internal Server Error
    6. Healthy Connection Result with Errors Displaying
  3. Testing the WooCommerce REST API
    1. Manually Testing QPilot Integration with Postman
  4. Configuring Permalinks

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.

How QPilot Makes API Requests

Requirements 

  • Site Title
    • Your site must have a title as set in WP-Admin > Settings > General >> Site Title in order to successfully connect. 
  • Ability to make GET / POST / PUT requests over the WooCommerce REST API on your site. 

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

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.

401 Unauthorized / 403 Forbidden

  1. First, make sure that you have met the API requirements as outlined in How QPilot Makes API Requests
    1. For example, if you have not set a Site Title in WordPress your site may return a Http 401 error. 
    2. You will also get a connection error if the WooCommerce API is not enabled on the site.
  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. Ensure you have not password protected access to your site using settings on your WordPress Site or using .htaccess rules. Passwords are problematic for incoming requests and is common on some staging sites. 
  4. Disable any plugins that are blocking access to the site. Some security plugins can block incoming requests to your site and causes connection errors. 
    1. To learn more see here: Deactivating Plugins for WooCommerce Site Troubleshooting

401 Sorry You Are Not Allowed To Create Resources

If you are receiving this error, please see our documentation for best next steps and more details: Error 401: Sorry You Are Not Allowed To Create Resources

404 Error Resources Not Found

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

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  (configured within your site's htaccess or DNS).
  • Misconfigured permalinks on your site. 

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.

Common Causes

  • Another plugin or theme 
  • Database or server errors (such as running out of memory)
  • Browser cache
  • WordPress Permalinks 
  • Corrupted core files 
  • Invalid site or folder permissions 

To learn more about Http 500 errors see here: How to Fix a 500 Internal Server Error on Your WordPress Site.

How To Resolve a Http 500 Error

  1. Check your Autoship Cloud Error Logs. These logs can be accessed and reviewed in Autoship Cloud > Settings > Logs. 
  2. Check your server error logs for any obvious errors. Contact your site administrator to correct these errors then try again. 
    1. If you don't have access to your server logs, you can ask your hosting provider or site administrator. 
  3. De-activate plugins and then test the API and activate additional plugins one at a time until the source of the error is found.
    1. If you find a plugin is causing the connection error, contact the plugin author and include the error message. 
    2. Learn more here: Deactivating Plugins for WooCommerce Site Troubleshooting
  4. Change the current theme to a basic theme (for example: WooCommerce's Storefront) then test the API.  
    1. If the issue is resolved after updating your theme, then contact the theme author for assistance.  
    2. Learn more here: Switch to a "Basic" Theme for WooCommerce Site Troubleshooting

Healthy Connection Result with Errors Displaying

Sometimes you may see errors appear within a healthy API test response. See the example screenshot below 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

Testing the WooCommerce REST 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. Manually test the REST API by making a Making a Basic Request to test the WooCommerce API with your site.

Manually Testing QPilot Integration with Postman

Sometimes manually testing the API Healthiness with a client like Postman can assist in troubleshooting. Some 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.

What if I get a different response? 

The response body will vary depending on the request URL and if there are any errors. In the example above, the response body shows a successful request. However you may also get response that shows a detailed error message or even code from your site. 

  • If you get an error response, find the Http error above for more information on common causes and troubleshooting steps. 
  • If the response body contains code from your site, you will need to contact your hosting provider for further assistance. Common causes may include permalinks or server security. 

Permalinks can cause connection Http 404 and 500 errors on your site. If you suspect permalinks are an issue, please follow and review the following: 

  1. Contact your hosting provider with the error you are experiencing.
  2. You can learn more about WooCommerce Permalinks here.
  3. To learn more about how Permalinks work with WooCommerce REST API see here.

Still need help? Contact Us Contact Us