Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create webhook service? #15

Closed
smart-reports opened this issue Aug 27, 2019 · 14 comments
Closed

Create webhook service? #15

smart-reports opened this issue Aug 27, 2019 · 14 comments

Comments

@smart-reports
Copy link

I have a webhooks URL which receives data from sources other than github etc.

Is it possible that N8N can listen for those incoming webhooks to run a workflow?

How would I go about implementing that?

@janober
Copy link
Member

janober commented Aug 27, 2019

Ah yes n8n can listen to GET or POST request it receives. Simply look under the "Trigger" nodes for "Webhook". It allows you to specify what to listen for exactly and when and how to respond.
It can either respond directly as soon as it receives the webhook (to really just trigger a workflow to start) or it can return the data of the last node (json or binary).

Here a simple example workflow which writes text on an image depending on what was given via the query parameter. Hope it helps. If not simply get back to me. Want to launch the website with more example workflows the next days.

To test it simply press "Execute Workflow" and then visit the test URL which gets displayed in the node under "Webhook URLs". Make sure to save the workflow first as webhooks only work for saved workflows (as the workflow-id is part of the URL).
The URL will look like this:
http://localhost:5678/webhook-test//webhook/test?name=Jim
(You can simply attach the "?name=Jim" yourself.)

Simply copy & paste the following in an empty n8n workflow:

{
  "nodes": [
    {
      "parameters": {
        "path": "test",
        "reponseMode": "lastNode",
        "reponseData": "firstEntryBinary"
      },
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        -100,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://www.needpix.com/file_download.php?url=//storage.needpix.com/thumbs/newspaper-412809_1280.jpg"
      },
      "name": "Read File URL",
      "type": "n8n-nodes-base.readFileFromUrl",
      "typeVersion": 1,
      "position": [
        100,
        300
      ]
    },
    {
      "parameters": {
        "operation": "text",
        "text": "=They found the killer it was {{$node[\"Read File URL\"].data[\"query\"][\"name\"]}}!",
        "fontSize": "=25",
        "positionX": 150,
        "positionY": 180,
        "lineLength": 18
      },
      "name": "Edit Image",
      "type": "n8n-nodes-base.editImage",
      "typeVersion": 1,
      "position": [
        300,
        300
      ]
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Read File URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read File URL": {
      "main": [
        [
          {
            "node": "Edit Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

@smart-reports
Copy link
Author

Hi Jan

Thanks for that. I pasted the code in and it seems to create a workflow.

When I look at the Webhooks URL for test I get this URL:

http://localhost:5678/webhook-test/2/webhook/test

Via Postman I input this as the URL

http://localhost:5678/webhook-test/2/webhook/test?name=Stuart

Auth: None
HTTP Method: Post
Path: test
Response Mode: On Received 200 (how do I change this to give a 201 response to the send of the webhook?
Property Name: name (i changed this manually.

I then get this error on post:

{"code":404,"message":"The requested webhook is not registred.","stack":"ReponseError: The requested webhook is not
registred.\n at TestWebhooks.callTestWebhook

@smart-reports
Copy link
Author

I finally got it to the point of waiting for the webhook-call.....

How do I keep it in persistent listening mode? As soon as it runs once it stops the webhook trigger from listening.

@janober
Copy link
Member

janober commented Aug 27, 2019

The test webhook does always just listens till it receives the first call and then displays that data in the editor UI as it is only for development and debugging. If you want that it keeps on listening, you have to activate the workflow (top right corner of the window).

If you do that you have to make sure that you use the production webhook URL and not the test one (does not have the "-test" in the URL).

@smart-reports
Copy link
Author

Jan - thanks very much! it works.

Do you know how to change the OnReceived response from 200 to 201?

Do I have to configure it somewhere?

I currently get 200 response with this message:

{
"message": "Workflow got started."
}

@janober
Copy link
Member

janober commented Aug 27, 2019

On success it always returns 200, changing it to 201 is currently not possible. I can look how complicated it would be to make that configurable for the next release.

When you have "Response Mode" set to "On Received" it will always return just "Workflow got started". If you want to return something else you have to set it to "Last Node" and then make sure that the last node returns the data you want it to return.

@smart-reports
Copy link
Author

Thanks Jan - much appreciated. Any plans to connect with the Quickbooks Online API?

@janober
Copy link
Member

janober commented Aug 28, 2019

You are welcome. Glad that it works now.
Actually want to have a connection to more or less every online service. Sadly does each integration take some time to create and my time is limited. So hope that the other people from the community (once it exists, some point after the proper launch) create more.
For now have planned to make it possible somewhere for people to suggest integrations and I will then create one after another with the most demand. Can inform you here once I have something in place.

Close the ticket for now as your problem seems to be solved.

@janober janober closed this as completed Aug 28, 2019
@janober
Copy link
Member

janober commented Aug 28, 2019

Just released a new version of n8n (0.18.1) which includes the functionality to set a custom response code on the Webhook-Node.

@smart-reports
Copy link
Author

Just released a new version of n8n (0.18.1) which includes the functionality to set a custom response code on the Webhook-Node.

Thanks Jan - I am going to test it

@gabrieligbastos
Copy link

hi, it's me again =(
testing this sample, i'm receiving now:

Error: write EPIPE
    at afterWriteDispatched (internal/stream_base_commons.js:146:25)
    at writeGeneric (internal/stream_base_commons.js:137:3)
    at Socket._writeGeneric (net.js:698:11)
    at Socket._write (net.js:710:8)
    at doWrite (_stream_writable.js:428:12)
    at writeOrBuffer (_stream_writable.js:412:5)
    at Socket.Writable.write (_stream_writable.js:302:11)
    at gm._spawn (/Users/gbastos/Development/ThirdParties/n8n/node_modules/gm/lib/command.js:253:18)
    at /Users/gbastos/Development/ThirdParties/n8n/node_modules/gm/lib/command.js:140:19
    at series (/Users/gbastos/Development/ThirdParties/n8n/node_modules/array-series/index.js:11:36)

am i missing any library for this specific node?

@janober
Copy link
Member

janober commented Sep 3, 2019

That is possible as the problem is in "gm" which is http://www.graphicsmagick.org/
So you should look that you get graphicsmagick installed and then also that problem is fixed and the "Edit Image" node should work.

@gabrieligbastos
Copy link

thanks, that was what i thought.
now working but not writting the text indeed.
image

maybe some error in the lib yet?
another doubt, something in the build process should had installed it? do u think is interesting some way to learn node dependencies?

@janober
Copy link
Member

janober commented Sep 3, 2019

Sorry sadly can not really help there. Must be something graphicsmagick related in combination with MacOS. You can try some of their examples on the website via the commandline and see if they work.

The docker-image has everything included and there everything will run for sure. Self installing is always more problematic especially on systems that run MacOS. Would be suprised if everything would run perfectly as I do not have a Mac and it is known to make problems.

When n8n gets build it installs all the packages but not additional software and that is correct like that. Graphicsmagick is also just needed for that one node and that one is also more to show what can be done and playing around than something people are currently using for anything at all. But have to add somewhere that if people want to use that node they have to make sure that this package is installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants