Creating webhook with .js file

I’m trying to create a webhook that will run a simple JavaScript file when called. I’ve followed the tutorial and I’m able to create the webhook with the file attached. I’ve also tested the JavaScript in a simple HTML file and it works fine. However, then I call the webhook, the JavaScript file is never fired.

I maybe misunderstanding how the associated of a file with a webhook works. I was making the assumption from the Librato example where a JSON file is uploaded and associated with a webhook.

My objective is to create a new object in Parse.com when the webhook is called.

Here is the JavaScript file I’m using:

Parse.initialize("XXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXX");

var GameScore = Parse.Object.extend("GameScore");
var gameScore = new GameScore();
 
gameScore.set("score", 1337);
gameScore.set("playerName", "Sean Plott");
gameScore.set("cheatMode", false);
 
gameScore.save(null, {
  success: function(gameScore) {
    // Execute any logic that should take place after the object is saved.
    alert('New object created with objectId: ' + gameScore.id);
  },
  error: function(gameScore, error) {
    // Execute any logic that should take place if the save fails.
    // error is a Parse.Error with an error code and message.
    alert('Failed to create new object, with error code: ' + error.message);
  }
});

My SparkCore code:

#define publish_delay 10000

unsigned int lastPublish = 0;

void setup() {

}

void loop() {
    unsigned long now = millis();

    if ((now - lastPublish) < publish_delay) {
        // it hasn't been 10 seconds yet...
        return;
    }

    Spark.publish("ParsePost");
}

EDIT:

Here is what I get when I call

spark webhook list

When I created my webhook:


I’ve edited your post to properly format the code. Please check out this post, so you know how to do this yourself in the future. Thanks in advance! ~Jordy

@random, can you post your webhook as well.

I’ve updated my answer, is this what your looking for??

@random, I think you are misunderstanding the webhooks. You cannot “attach” a javascript file to a webhook so it runs when the hook is called. The hook is designed to do a GET or POST to a specified website. You can specify a number of items to pass in the call including a structured query or JSON formatted items but not a javascript file. The JS file could run on the target site I suppose and provide the return data for the webhook. @Dave, can you help me here? :flushed:

2 Likes

Ah, that makes sense I believe. It seemed as though in the Librato example they were attaching a .json file to the webhook. I’m assuming my solution would be to create an endpoint on a server that would run the .js file, then call that endpoint from the webhook??

1 Like

@random, the Librato example is deceiving since it shows the output of the webhook create command, not the input json file. I would say yes, the .js file needs to run on the endpoint server you call with the webhook.

2 Likes

Hey All,

That’s correct, the webhook file is just to help describe what kind of web request the hook should make. We’re also talking about building out something like workers, where you could also do what you had in mind @random, but that won’t be ready until at least later this summer. :slight_smile:

Thanks,
David

1 Like

@peekay123 Thank you for the clarification! I should be able to get it rolling no problem now.

@Dave that would make life much more awesome! Will be eagerly awaiting!