# Intergrating webhooks with gcloud Datastore

**URL:** <https://community.particle.io/t/intergrating-webhooks-with-gcloud-datastore/43123>\
**Category:** Troubleshooting\
**Created:** [July 20, 2018, 11:44pm UTC](https://community.particle.io/t/intergrating-webhooks-with-gcloud-datastore/43123 "2018-07-20T23:44:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dropTableUsers](https://avatars.discourse-cdn.com/v4/letter/d/b4bc9f/32.png) [@dropTableUsers](https://community.particle.io/u/dropTableUsers)\
**Post date:** [July 20, 2018, 11:44pm UTC](https://community.particle.io/t/intergrating-webhooks-with-gcloud-datastore/43123/1 "2018-07-20T23:44:20Z")

</div>

Hey all,

Right now I’m trying to set up a webhook that grabs data from Google Cloud’s Datastore. When I hit the “Test” button on the Webhook’s integration, I get a 401 response. I’m trying to extract data using the [runQuery function](https://cloud.google.com/datastore/docs/reference/data/rest/v1/projects/runQuery) using the http post method. I can run this locally without any problem. However, there is no clear place to insert the credentials. Where can I paste my private API key to get the webhook to run?

[  
URL: [https://datastore.googleapis.com/v1/projects/[projectid]:runQuery](https://datastore.googleapis.com/v1/projects/%5Bprojectid%5D:runQuery)  
Request type: Post  
Request Format: Web Form  
**Form Fields**  
partitionId: {projectId: [projectId]}  
query: {kind: {name: recipes}}  
**Query Parameters**  
api\_key: [private api key]  
field1: [event name]  
]  
Is there anything that I’m missing/ misplacing? Thanks for the help in advance.

**Edit:** Fixed url, no longer getting 404 errors but 401.

---

<div class="post-metadata">

**Author:** ![Postler](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/postler/32/13693_2.png) [@Postler](https://community.particle.io/u/Postler)\
**Post date:** [July 22, 2018, 10:59pm UTC](https://community.particle.io/t/intergrating-webhooks-with-gcloud-datastore/43123/2 "2018-07-22T22:59:21Z")

</div>

http 401 error could be an unauthorization problem, [https://httpstatuses.com/401](https://httpstatuses.com/401)

---

<div class="post-metadata">

**Author:** ![dropTableUsers](https://avatars.discourse-cdn.com/v4/letter/d/b4bc9f/32.png) [@dropTableUsers](https://community.particle.io/u/dropTableUsers)\
**Post date:** [July 23, 2018, 5:07pm UTC](https://community.particle.io/t/intergrating-webhooks-with-gcloud-datastore/43123/3 "2018-07-23T17:07:46Z")

</div>

You’re right, I think that this is the problem. How should I include my private API key into my webhook? If I should not be using the API key, what other authentication method should I be using?

---

<div class="post-metadata">

**Author:** ![Postler](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/postler/32/13693_2.png) [@Postler](https://community.particle.io/u/Postler)\
**Post date:** [July 23, 2018, 9:21pm UTC](https://community.particle.io/t/intergrating-webhooks-with-gcloud-datastore/43123/4 "2018-07-23T21:21:26Z")

</div>

Could you pls make public your webhook from [https://console.particle.io/integrations](https://console.particle.io/integrations)?

Found this: [Google Cloud Platform Integration SetupT](https://community.particle.io/t/google-cloud-platform-integration-setupt/43073/2?u=postler)  
You should check again if your problem appears.

---

<div class="post-metadata">

**Author:** ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)\
**Post date:** [July 24, 2018, 11:46am UTC](https://community.particle.io/t/intergrating-webhooks-with-gcloud-datastore/43123/5 "2018-07-24T11:46:38Z")

</div>

I suspect you will find it difficult to impossible to do this with a webhook. The correct way to do it seems unnecessarily complicated, but it offers much more flexibility and allows you to customize how the data is stored in the Google cloud datastore.

You’ll want to use the Google Cloud integration, not a plain webhook. This is kind of like a webhook, but handles the authentication part. It also translates the Particle events into Google pub/sub topics, which are the Google equivalent to events.

Then you use a Google cloud function to trigger off a pub/sub event and store this in cloud data store.

This tutorial may be helpful. Note that it shows two different ways of storing the data, cloud functions (the easier way) and app engine (the harder way, but was necessary before cloud function existed).

> **[rickkas7/google\_cloud\_tutorial](https://github.com/rickkas7/google_cloud_tutorial)**
>
> google\_cloud\_tutorial - Tutorial for using Google Cloud with Particle Photon and Electron

---

<div class="post-metadata">

**Author:** ![dropTableUsers](https://avatars.discourse-cdn.com/v4/letter/d/b4bc9f/32.png) [@dropTableUsers](https://community.particle.io/u/dropTableUsers)\
**Post date:** [July 24, 2018, 6:17pm UTC](https://community.particle.io/t/intergrating-webhooks-with-gcloud-datastore/43123/6 "2018-07-24T18:17:55Z")

</div>

I agree, I was getting frustrated with the webhook approach and switched to the approach you’ve described with some positive results. I’ll be looking through your link, thanks for the tip

---

<div class="post-metadata">

**Author:** ![stebes](https://avatars.discourse-cdn.com/v4/letter/s/c0e974/32.png) [@stebes](https://community.particle.io/u/stebes)\
**Post date:** [July 25, 2018, 1:21am UTC](https://community.particle.io/t/intergrating-webhooks-with-gcloud-datastore/43123/7 "2018-07-25T01:21:43Z")

</div>

Hi rickkas,

Thanks for putting together these tutorials - they’re quite helpful.

On the topic of data retrieval from google cloud, do you know of any tutorials that illustrate the workflow for a particle to request data from a source like datastore (or through pub/sub + an intermediate google function or app engine script)?

The tutorial you linked to has been a great reference for publishing data from particle -\> particle cloud -\> google pub/sub -\> an app -\> datastore/firebase/etc. I’m curious if there’s any documentation out there that might show or explain the opposite path (data on datastore retrieved by an individual particle). Thanks for your help.

---

<div class="post-metadata">

**Author:** ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)\
**Post date:** [July 25, 2018, 2:57pm UTC](https://community.particle.io/t/intergrating-webhooks-with-gcloud-datastore/43123/8 "2018-07-25T14:57:54Z")

</div>

I added [another example](https://github.com/rickkas7/google_cloud_tutorial#datastore-and-particle-api-using-cloud-functions) to the Google Cloud Tutorial.

### Datastore and Particle API using Cloud Functions

Like the previous examples, the device publishes some random JSON data every minute, like this:

```auto
 {"a":2,"b":0.999,"c":1085377743,"n":"test2"}

```

This is stored in the Google cloud data store, along with a timestamp.

The difference is that after storing the data in the cloud data store, the cloud function uses Particle.publish to publish the latest data to all devices in the account.

While this example just shows publish, the same technique could be used to read from the cloud data store and publish data. Or read from the cloud data store and call a device function with data.
