Keep in mind that the Tutsplus Magento Fundementals course is old and needs a few changes to get things to work
I think the course has been updated subsequently please check it on the following link to Tutsplus
Episode 10: Creating our First Controller
Remember to type it word for word, I used <uses> instead of <use> in the following code:
Episode 15: Putting it all Together
Remember to ensure that your etc/config.xml,has the <block> section so Magento knows where to look, under <globals>.
Also make sure that the handle for the sayHello Action of the Index controller is of the format:
Module_Controller_Action and not Namespace_Module_Controller_Action
Save it as a file first, copy and paste.
I was tasked with creating a service (app) that would interact with the ShopifyAPI.
To create the service the flow would be:
- Authenticate (Oauth)
- Register the Service with callback url
- Return relevant data when Shopify makes the external call (webhook)
This is the first time I had worked with Oauth and a Restful API. What I didn’t know was that the header information of HTTP requests often contain important information so we need to be able to get and set these values in our application development.
Furthermore for testing purposes I initially had to use curl as the client making the calls to the API. This was unintuitive in terms of setting headers and everything and then viewing and checking the response. That is when a senior developer advised that the use of a REstful client from within your browser should be used, he advised the use of Postman: a restful Client.
With postman you can easily and intuitively set the HTTP payload (often JSON) and header information. The webhook coming from Shopify will send the following header:
To identity the shop. Now to test this request with Postman, I added a header and typed in exactly that:
HTTP_X_SHOPIFY_SHOP_DOMAIN = "myshop.myshopify.com"
But an error was that the header was never sent to the application. What was going wrong?
Well I know it was being sent by checking the network tab of the developer tools. But it was not being received (or was being parsed or mutated) by either apache or php.
Eventually I found out that apache does not accept “_” underscores in HTTP headers. It will remove them, however it will convert dashes to underscores. So the header should have looked like this:
HTTP-X-SHOPIFY-SHOP-DOMAIN = "myshop.myshopify.com"
The full reason behind this can be found here: Why underscores are forbidden in HTTP header names