Zappin Vinli Trips

Zapier is a fantastic tool for filling in the gaps that naturally exist between various apps and services. It comes equipped with some powerful utility features (such as webhooks, code injection, data formatting, email parsing, etc) that make it possible for developers to achieve even more robust integrations when the "click-to-config" integrations fall short.

Recently, I was using Zapier to troubleshoot an issue that someone had reported, when I got inspired to find a cool use-case where Vinli and Zapier could work together. This post is the result.

Objective

We'll use Zapier to log Vinli trips into a google spreadsheet. In doing so, we'll touch on a few key platform concepts:

Prerequisites

If you don't have a Zapier account, you can get one here for free. No worries, everything we do here will be available in the free version.

Make sure you are registered in the Vinli Developer Portal and have a MyVinli account.

We'll be doing a lot with Vinli CLI and Virtual Vinli. If you don't know what those are, or need a refresher, check out the blog posts that I've linked here.

Register Your App and Make a Dummy

If you haven't already, create a an app in the Vinli Developer Portal. Make sure to set up a Web client, as you'll need a client to auth a MyVinli user.

Next you should create a dummy device from your terminal using Vinli CLI. (if you don't already have one)

> vinli dummy create --name ZappinDummy

Prep Your Catch Hook

Make a new Zap in Zapier. For your trigger, you should select 'Webhooks by Zapier'. Then select the 'Catch Hook' option.

Once you hit continue, Zapier will generate a custom webhook URL (it will look like this https://zapier.com/hooks/catch/2zabxz/).

Important

Jot down that URL and DON'T test this step in Zapier yet. You'll have to start over if you do :(

Create An Event Subscription

Create an event subscription for your dummy device (or whatever device you want to use). For this use-case, we're going to subscribe to the trip-completed event, that way we get a notification whenever the device completes a trip.

POST https://events.vin.li/api/v1/devices/de01abb1-453d-4293-831a-f0d804b48fdf/subscriptions
Accept: application/json
Content-Type: application/json
{
  "subscription" : {
    "eventType" : "trip-completed",
    "url": "https://zapier.com/hooks/catch/2zabxz/"
  }
}

here's the same request in cURL

curl -X POST -u 'YOUR_APP_ID:YOUR_APP_SECRET' -H "Content-Type: application/json" -H "Accept: application/json" -d '{
  "subscription" : {
    "eventType" : "trip-completed",
    "url": "https://zapier.com/hooks/catch/2zabxz/"
  }
}' "https://events.vin.li/api/v1/devices/de01abb1-453d-4293-831a-f0d804b48fdf/subscriptions"

Now navigate to the subscription in the Dev Portal.

subscription

Send your Dummy for a drive

Our subscription will receive a notification anytime the device completes a trip. In order to give us some sample data to work with, let's send our dummy on a run.

HINT: you might pick the dummy route for time's sake.

> vinli dummy start --dummy ZappinDummy --route 377d7edc-ba9f-4d4c-a898-7c955f8d4eb6

Once your dummy finishes running the route, head back to the dev portal and reload the Notifications section of your Subscription. You should see a notification!

notification

The next webhook

Let's bounce back to Zapier. Remember when I told you not to test your catch hook? Now go ahead and test it. It should receive the notification from your dummy's completed trip.

Now we're going to add another Action to our Zap. Choose Webhook's by Zapier again, and select the GET option.

Set up the webhook like this:
webhook1
webhook2
webhook3

This GET request will take the trip Id from the notification and return the trip details.

Hit continue, and test the step in Zapier.

Spreadsheet time

We're almost done! All we have to do now is set up our spreadsheet and map in our trip parameters.

Create a header column with labels for the trip parameters you want to track, here are the ones I chose (feel free to pick your own!)

sheet-column-header

Now head over to Zapier and add an Action. Select the Google Sheets app. Select the 'Create Spreadsheet Row' action. Then map in the Trip parameters from Step 2.

mappings

That's it!

Send your dummy on another run just to test. Or, create a subscription for your real Vinli device and start logging those trips!!