Shopify App Development Tutorial with PHP (Fixing Errors)

8th July 2019   Shopify

I have written so many articles now about Shopify App Development and I know there’s going to be more things that I needed to talk about.

I also wanted to make a tutorial on how to create Shopify apps using frameworks such as Laravel but I believe it’ll take much time since I have to study the framework myself.

But for the meantime, I wanted to talk about all the errors that you guys are having. All the errors that I myself encountered as well.

So you guys have sent me lots of emails about your app issues and I wanted to take this opportunity to combine all of these errors into one article so that everyone in the future can use this as a reference.

 

Shopify App – 403 Forbidden Error

What is 403 Forbidden Error?

403 forbidden error is a type of HTTP error code that you can encounter when you’re trying to reach an address or a website that is forbidden to be located.

Now, what is that something to do with your Shopify app?

Well, to tell you honestly…

A couple of weeks ago, I made a mistake on my previous article and that mistake is the little typo in the install.php file.

Now take a look at this image.

Shopify App Troubleshooting - 403 Forbidden Error

What do you notice in the image above?

In the image above, you will see that the URL contains two myshopify.com.
That means that the install URL was initiated incorrectly.

Before, the variable looks like this:

$install_url = "https://" . $shop . ".myshopify.com/admin/oauth/authorize?client_id=" . $api_key . "&scope=" . $scopes . "&redirect_uri=" . urlencode($redirect_uri);

When in fact, It should look like this:

$install_url = "https://" . $shop . "/admin/oauth/authorize?client_id=" . $api_key . "&scope=" . $scopes . "&redirect_uri=" . urlencode($redirect_uri);

But keep in mind that both of the above URL will work.

  1. If you type in the URL bar:
    https://example.com/install.php?shop=yourstorename
  2. If you remove the myshopify.com in the install.php and then type in the URL bar:
    https://example.com/install.php?shop=yourstorename.myshopify.com

 

Invalid API key or access token (unrecognized login or wrong password)

{"errors":"[API] Invalid API key or access token (unrecognized login or wrong password)"}

This error occurs when you have used the expired access token. So go ahead and uninstall the app and make sure to generate a new access token and paste it in the token variable.

Same goes to shop variable, make sure that it has the name of your store.

<?php
ini_set("display_errors", 1);
error_reporting(E_ALL);
require_once("inc/functions.php");

$requests = $_GET;
$hmac = $_GET['hmac'];
$serializeArray = serialize($requests);
$requests = array_diff_key($requests, array('hmac' => ''));
ksort($requests);

$token ="HERE IS WHERE YOU PASTE YOUR NEW TOKEN";
$shop = "storename";            //no 'myshopify.com' or 'https'

This is also important why you should save the access token in your database. That way you won’t have to manually copy the token and paste it in the PHP code.

Argh! So inconvenient.

Shopify API – Foreach Error

If your app is not displaying anything. For example, products. Chances are you have not setup your store yet. Try adding more items to your store, make collections and add your items there.

The more items and collections the better.

Shopify Refused To Connect Error

Shopify App - Refused to connect error

Special thanks to Corey for sending this error

According to Corey, the app is not loading properly inside the Shopify app hence returning a refused to connect error. BUT if you try to browse the app URL, the app will load.

I believe this is not TRUE at all.

If the app itself is not loading, then obviously the app URL will not load too.

To finally see what is happening behind the scene of your codes.

Put the following lines of code right at the top of your require_once("inc/functions.php");

ini_set("display_errors", 1);
error_reporting(E_ALL);

This will return all the errors that you are not seeing behind the scene.

Shopify is not Giving the Access Token

Special thanks to Anand for sending me this error.

I have encountered this error so many times now and the usual problem here is the two root files. install.php and generate_token.php

Though I will recommend as well to double check the URLs that you have provided in the settings of your app. Keep in mind that everything is case-sensitive. If your URL is not properly cased then expect to receive an error.

So double check everything!

If your app is not giving access token then that means there is no OAuth happening between the store and the app.

Double check if both of your API key and secret key are correct. Make sure there are no spaces in the string.

Conclusion

I understand the errors like these are such a pain in the head but these errors will, of course, teach lessons and that lessons will help you avoid these errors.

If you are stuck in the following errors, then I suggest you start again from scratch.

I have written a full article on how to develop a Shopify app from scratch. So if you want, go ahead and read it.. maybe again.. because you’re here, looking for solutions and yet again, can’t fix it.

React to this topic
Bernard Polidario
About Bernard Polidario

A full-stack developer who has been around programming community for 10+ years and still has a lot of passion for programming and design. I am the founder of WeeklyHow and I can be reached at [email protected]

https://weeklyhow.com

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*
*