Use Oauth 1 and the WooCommerce REST API to retrieve order details.
I was determined to find a way to use the REST API. I posted a question on the WordPress Ireland Facebook group. Diego Zanella of Aelia (Currency Switcher for WooCommerce) directed me to use OAuth ‘one-legged’ authentication.
Postman to cURL
I created REST API keys within WooCommerce. You need to select a user that has the capability to access the endpoint that you will be using. In my testing I will be viewing orders so I chose the site admin and generated a consumer key and consumer secret.
This worked! I used the ‘Code‘ feature to get the PHP cURL code to achieve the same result. I was not able to use the code again because some of the fields have to be regenerated for each request.
Postman automatically generates some of the required values (timestamp, nonce and signature). It was easy to generate a timestamp (simply using ‘time()‘) and a nonce (using ‘uniqid()‘). The hard part was that when these are changed the ‘oauth_signature‘ value needs to be updated to incorporate the new values.
It took a lot of work reading through the WooCommerce source to find out how to regenerate the ‘oauth_signature‘. I eventually copied bits of code from the WooCommerce WC_REST_Authentication class.
I plan to work on creating an order with the REST API and then update the Thrivecart script to use the new code.