Private App for Customer Create Webhook

Shopify Partner
4 0 0

I have read a lot of forums and discussions about Webhooks and I just haven't had the "ah ha" moment. What I'd like to accomplish is to have an email sent to the shop owner every time a new customer account is created. I know that I need to setup a Webhook for customers/create.

What I've done so far:

So now I don't know what to do next. Where do I host the Private App files? Do they need to be on an external server apart from the Shopify store? If so, does the external server/domain need an SSL certificate? How do I get the Webhook API call to actually fire? Eventually I know I need to have the JSON contents parsed and then sent in an email to the store owner, but I just don't know how to get the Webhook working and then how to properly retrieve the contents of the JSON sent.

<?

    session_start();

    require __DIR__.'/vendor/autoload.php';
    use phpish\shopify;

    require __DIR__.'/conf.php';

    $shopify = shopify\client(SHOPIFY_SHOP, SHOPIFY_APP_API_KEY, SHOPIFY_APP_PASSWORD, true);

    try
    {
        # Making an API request can throw an exception
        $customers = $shopify('POST /admin/webhooks.json', array(), array
        (
            'webook' => array 
            (
                "topic": "customers/create",
                "address": "http://webhookhandler.example.com/webhooks <---not the actual domain I use in my code", 
                "format": "json"
            )

        ));

        print_r($customers);
    }
    catch (shopify\ApiException $e)
    {
        # HTTP status code was >= 400 or response contained the key 'errors'
        echo $e;
        print_R($e->getRequest());
        print_R($e->getResponse());
    }
    catch (shopify\CurlException $e)
    {
        # cURL error
        echo $e;
        print_R($e->getRequest());
        print_R($e->getResponse());
    }

?>

0 Likes
Shopify Expert
62 0 8

> Where do I host the Private App files? Do they need to be on an external server apart from the Shopify store?

Yes.

The trouble with testing your webhooks through the API is that you need a publicly visible URL to handle them. Unlike client-side redirects, webhooks originate directly from the server. This means that you cannot use the following as an endpoint in your testing environment:

  • Localhost
  • Any URL ending in the word "internal" (i.e. thisshop.com/internal)
  •  
  • "Fake" domains like www.example.com
  • Shopify domains (i.e. shopify.com and myshopify.com)

-- http://docs.shopify.com/api/webhooks/using-webhooks#configure-webhook

 

> If so, does the external server/domain need an SSL certificate? 

Not necessarily.

A Webhook is a tool for retrieving and storing data from a certain event. They allow you to register an http:// or https:// URL where the event data can be stored in JSON or XML formats.

http://docs.shopify.com/api/webhooks/using-webhooks#about-webhooks

 

> How do I get the Webhook API call to actually fire? 

Depends on the webhook. For customers/create, create a customer.

If you could file an issue on Github, I'll try to add webhook examples into the skeleton.

 

Check out my apps: Social Call-to-Action [https://apps.shopify.com/social-call-to-action] and Fliptabify [https://apps.shopify.com/fliptabify]. I also maintain the Shopify API client in PHP [https://github.com/phpish/shopify] and PHP Quickstart Skeletons for building Shopify apps: [https://github.com/phpish/shopify_app-skeleton] and [https://github.com/phpish/shopify_private_app-skeleton]
0 Likes
Highlighted
New Member
3 0 0

require __DIR__.'/vendor/autoload.php';

where is this file ?

0 Likes