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

Webhook Plugin - Unable to use Custom Header #556

Open
cboothe opened this issue Jan 7, 2025 · 7 comments
Open

Webhook Plugin - Unable to use Custom Header #556

cboothe opened this issue Jan 7, 2025 · 7 comments

Comments

@cboothe
Copy link

cboothe commented Jan 7, 2025

Which plugin/repository is the issue about?
vendure-plugin-webhook

Describe the bug
I am unable to use a custom header. I tried with a custom header as well as the "x-" custom header pattern and both fail after adding to the worker queue. I don't see anywhere in the plugin or Vendure where it checks for invalid header names.

To Reproduce

Use a custom transformer as per the example.
{
headers: {
'content-type': 'application/json',
'authorization': 'Bearer ' + process.env.WEBHOOK_KEY,
'custom-header': 'true'
}

[server] error 1/6/25, 6:59 AM - [WebhookPlugin] Failed to call webhook for event OrderPlacedEvent channel 3: TypeError: custom-header: is not a legal HTTP header name

Expected behavior
Without the custom header it works.

[server] info 1/6/25, 6:58 AM - [WebhookPlugin] Successfully triggered webhook for event OrderPlacedEvent for channel 3 with transformer "Stringify Order events"

Screenshots
Screenshot 2025-01-07 at 1 51 21 AM

Environment

  • NodeJS version 18.20.4
  • Vendure version: 3.0.3
  • Plugin version 1.3.0
  • Database PostgreSQL

Additional context
[martijnvdbrug] It show this works in the transformer example.
https://plugins.pinelab.studio/plugin/vendure-plugin-webhook/#custom-transformers

@cboothe
Copy link
Author

cboothe commented Jan 7, 2025

Any chance you can comment on this @martijnvdbrug

@martijnvdbrug
Copy link
Member

Interesting, thats definitely not something we check... I will take a look

@martijnvdbrug
Copy link
Member

martijnvdbrug commented Jan 16, 2025

Could it be that your env var is undefined? This answer says spaces at the end of a header name arent allowed. Maybe test it out with a hardcoded string first?

@cboothe
Copy link
Author

cboothe commented Jan 16, 2025

I tried a bunch of things, even upgraded to Vendure 3.1.1.

Since it was an option in the plugin example I assumed it may have worked at somepoint. I have issues with types in Typescript but an X-header should be allowed.

In another plugin I just use axios and it works.

@martijnvdbrug
Copy link
Member

I will look in to it!

@martijnvdbrug
Copy link
Member

Hi @cboothe, I've tried to reproduce your issue, but failed unfortunately:

I was able to successfully send a webhook, with custom transformer and the same headers as your example:

// These are the headers I used
        headers: {
          'x-custom-header': 'stringify-custom-header',
          'content-type': 'application/json',
          authorization: 'Bearer XXXX',
          'custom-header': 'true',
        }

Image

I am also not able to reproduce the behavior with any other seemingly invalid header names. Could the error be thrown somewhere else in your server? Or maybe even the receiving endpoint?

Happy to take a look if you can supply a working reproduction, but until then there is not much I can do from this side.

(I did publish 1.3.1, which fixes the UI labels)

@cboothe
Copy link
Author

cboothe commented Jan 29, 2025

@martijnvdbrug Thanks for checking! I did try two different solutions for catching the webhook to see the headers.
Not sure how I can reproduce it but will try to get an example.

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

2 participants