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

Sendgrid plugin not compatible with Medusa 1.18 #5969

Closed
aldo-roman opened this issue Dec 28, 2023 · 32 comments
Closed

Sendgrid plugin not compatible with Medusa 1.18 #5969

aldo-roman opened this issue Dec 28, 2023 · 32 comments

Comments

@aldo-roman
Copy link
Contributor

aldo-roman commented Dec 28, 2023

Bug report

Describe the bug

The Sendgrid plugin is using the deprecated Subscriber method (valid until 1.17).
When using Medusa 1.18, the plugin will not load.

System information

Medusa version (including plugins): 1.18
Node.js version:
Database:
Operating system:
Browser (if relevant):

Additional context

SendGrid plugin subscriber

Also possible root case for #4291

@aldo-roman
Copy link
Contributor Author

aldo-roman commented Dec 28, 2023

Hello team. Downgrading to 1.17 is also not possible for my use case. We need to send emails when an order is placed.

1.17.4 has a bug where promiseAll util is not imported, thus the order subscriber fails.
This was fixed on #5635 and published on 1.19.x, but not back ported to 1.17.x where the bug was introduced.

I am now blocked to use the plugin in any version.
Please send help 🙏

Update: It actually works in 1.17! The promiseAll error is still there, but the send grid listener gets fired properly and the emails are arriving. Still, this issue is blocking upgrade to 1.18+

@Mehmo21
Copy link

Mehmo21 commented Jan 2, 2024

Same issue

@adrien2p
Copy link
Member

adrien2p commented Jan 8, 2024

We have a pr open to upgrade the sendgrid plugin
cc @olivermrbl

@cmario92
Copy link

cmario92 commented Feb 7, 2024

any updates on this? still not able to send emails using Sendgrid

@Kushal-starr
Copy link

Kushal-starr commented Feb 12, 2024

ResponseError: Bad Request
at node_modules/@sendgrid/client/src/classes/client.js:146:29
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 400,
response: {
headers: {
server: 'nginx',
date: 'Mon, 12 Feb 2024 08:48:48 GMT',
'content-type': 'application/json',
'content-length': '851',
connection: 'keep-alive',
'access-control-allow-origin': 'https://sendgrid.api-docs.io',
'access-control-allow-methods': 'POST',
'access-control-allow-headers': 'Authorization, Content-Type, On-behalf-of, x-sg-elas-acl',
'access-control-max-age': '600',
'x-no-cors-reason': 'https://sendgrid.com/docs/Classroom/Basics/API/cors.html',
'strict-transport-security': 'max-age=600; includeSubDomains'
},
body: { errors: [Array] }
}
}

medusajs/medusa: 1.20 v
medusajs/medusa-cli: 1.3.21 v

facing this error while using the sendGrid to send the order confirmation emails.

Also, pls provide the correct steps, In docs is somewhat, confusing, may be I missed something just to check with. Thanks!
FYI: @olivermrbl

@iaremarkus
Copy link

Shew its really harsh to complete an entire Medusa store from top to bottom, finally get to enabling sendgrid for email notifications, only to find that its broken 😭

Really hope this is resolved soon 🤞

Good luck devs!
🤜🤛

@denisfelst
Copy link

Im having trouble with this as well. Got Medusa v1.20.2, everything seems to be up-to-date and nothing works. Here's my package.json:

  "dependencies": {
    "@medusajs/admin": "7.1.11",
    "@medusajs/cache-inmemory": "^1.8.9",
    "@medusajs/cache-redis": "^1.8.9",
    "@medusajs/event-bus-local": "^1.9.8",
    "@medusajs/event-bus-redis": "^1.8.11",
    "@medusajs/file-local": "^1.0.3",
    "@medusajs/medusa": "1.20.2",
    "@sendgrid/mail": "^8.1.1",
    "@tanstack/react-query": "4.22.0",
    "body-parser": "^1.19.0",
    "cors": "^2.8.5",
    "dotenv": "16.3.1",
    "express": "^4.17.2",
    "medusa-fulfillment-manual": "^1.1.39",
    "medusa-interfaces": "^1.3.8",
    "medusa-payment-manual": "^1.0.24",
    "medusa-payment-stripe": "^6.0.7",
    "medusa-plugin-mailchimp": "^1.1.50",
    "medusa-plugin-sendgrid": "^1.3.12",
    "prism-react-renderer": "^2.0.4",
    "typeorm": "^0.3.16"
  },

I also get the 'Processing order.placed which has 2 subscribers', as well as this log when hitting npx medusa develop to fire up the admin server:

Initializing plugins
warn: The subscriber in C:\Users\DenisFelst\silice\silice-admin0\node_modules\medusa-plugin-sendgrid\subscribers\order.js is missing a config.
warn: The subscriber in C:\Users\DenisFelst\silice\silice-admin0\node_modules\medusa-plugin-sendgrid\subscribers\restock.js is missing a config.
warn: The subscriber in C:\Users\DenisFelst\silice\silice-admin0\node_modules\medusa-plugin-sendgrid\subscribers\user.js is missing a config.

Wondering if this could be the problem? However, I have no idea how to see the missing config. Any hint would be appreciated.

@damienmutt
Copy link

damienmutt commented Feb 27, 2024

Same here, no mails, spent two days searching my error just to realise it seems related to some Sendgrid incompatibility and not a bug of mine.
Got the same errors as denisfelst: subscriber is missing a config.

@medusa/medusa: 1.20.2
medusa-plugin-sendgrid: 1.3.12

I'll keep an eye here.

@denisfelst
Copy link

denisfelst commented Feb 27, 2024

@damienmutt although it might seem obvious, make sure you have redis installed and the connection up and running, as well as its respective lines in medusa.config.js uncommented:

const projectConfig = {
  ...
  redis_url: REDIS_URL
  ...
}

This was my error. now its picking up all events and i'm able to subscribe to them. FYI my package.json looks like this:

"dependencies": {
  "@medusajs/admin": "7.1.11",
  "@medusajs/cache-inmemory": "^1.8.9",
  "@medusajs/cache-redis": "^1.8.9",
  "@medusajs/event-bus-local": "^1.9.8",
  "@medusajs/event-bus-redis": "^1.8.11",
  "@medusajs/file-local": "^1.0.3",
  "@medusajs/medusa": "1.20",
  "@tanstack/react-query": "4.22.0",
  "body-parser": "^1.19.0",
  "cors": "^2.8.5",
  "dotenv": "16.3.1",
  "express": "^4.17.2",
  "medusa-fulfillment-manual": "^1.1.39",
  "medusa-interfaces": "^1.3.8",
  "medusa-payment-manual": "^1.0.24",
  "medusa-payment-stripe": "^6.0.7",
  "medusa-plugin-mailchimp": "^1.1.50",
  "medusa-plugin-sendgrid": "^1.3.12",
  "prism-react-renderer": "^2.0.4",
  "typeorm": "^0.3.16"
},

Hope that helps. Good luck!

@damienmutt
Copy link

@denisfelst Config correct and Redis running, copied your package but still not working. I'll check .env and Sendgrid again, just let me ask you a question:

Did you still get subscriber is missing a config warning? or is it gone? just to know if I can rely on that.

Thanks!

@denisfelst
Copy link

denisfelst commented Feb 27, 2024

@damienmutt

Nope, I just checked and don't get it anymore (see screenshot, this is when I complete the order).

Maybe check again your env as you say, renew your sendgrid API key, check the request is being sent (eg. log something on node_modules@sendgrid\client\src\classes\client.js -> request function see if there's a request error, it might be your API is not working), check if your template options are right, try other ones as well, perhaps other events are triggering, like cancelling an order ... my config is:

const plugins = [
...
{
  resolve: `medusa-plugin-sendgrid`,
  options: {
    api_key: process.env.SENDGRID_API_KEY,
    from: "info@silice.glass",
    order_placed_template: process.env.SENDGRID_ORDER_PLACED_TEMPLATE_KEY,
    order_shipment_created: process.env.SENDGRID_ORDER_SHIPPED_TEMPLATE_KEY,
    order_canceled_template: process.env.SENDGRID_ORDER_CANCELED_TEMPLATE_KEY,
  }
},
image

And again, double-check your redis config (port number is ok, try redis-cli ping, etc.). If there's any code you can share, I'd be happy to give it a try. It's quite frustrating, I know.

@denisfelst
Copy link

denisfelst commented Feb 27, 2024

@damienmutt actually I just checked again. Yes, I do get the same messages.

The subscriber in ...\medusa-plugin-sendgrid\subscribers\order.js is missing a config.

I guess you don't have to rely on that anymore. Sorry for the confusion. Still, I left my previous post just in case it helps you somehow.

@aldo-roman
Copy link
Contributor Author

aldo-roman commented Feb 27, 2024

@denisfelst @damienmutt This cannot be a configuration issue, as the error is shown when validating the subscriber inside a loader validator.

Subscribers using loaders was introduced in 1.18 (as a breaking change). The root cause of this error is the sendgrid plugin not being migrated to subscribe with a loader.

logger.warn(`The subscriber in ${path} is missing a config.`)

@joaoemersonufc
Copy link

Hey guys. I have the same issue with the plugin, any news?

@damienmutt
Copy link

Hey guys. I have the same issue with the plugin, any news?

Mine did not work on local but did in prod... weird; I need to test everything again.

@joaoemersonufc
Copy link

joaoemersonufc commented Mar 7, 2024

Hey guys. I have the same issue with the plugin, any news?

Mine did not work on local but did in prod... weird; I need to test everything again.

Did you mean, that's only in production can I have the test? I don't know, in my case is for a storefront application with real products and cash. If only in production it's possible to test, it means I need to pay one product.

@xmartinezpujol
Copy link

Same here, both in local and prod. In the end I had to create my own endpoints for password reset both for customer and user because the emails were never sent, they are always stuck in the subscribers queue. Later I will have to add also order_placement and similar to temporarly fix this issue.

I guess Sendgrid plugin works, just not the event subscription as the action never gets fired. At the start I though it was a configuration issue with Sendgrid, but if I use the "dynamic usage" explained in the documentation it just works and emails are being sent with no issue.

I have Redis and all enabled, not using the local module.
Probably some issue with event subscribers.

@sayansiva
Copy link

sayansiva commented Mar 12, 2024

I had the same problem, then I noticed that the redis config was commented out, followed this article, and now sendgrid is working perfectly.

FYI, I am still getting

The subscriber in ...\medusa-plugin-sendgrid\subscribers\order.js is missing a config.

@bentron2000
Copy link

ResponseError: Bad Request at node_modules/@sendgrid/client/src/classes/client.js:146:29 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { code: 400, response: { headers: { server: 'nginx', date: 'Mon, 12 Feb 2024 08:48:48 GMT', 'content-type': 'application/json', 'content-length': '851', connection: 'keep-alive', 'access-control-allow-origin': 'https://sendgrid.api-docs.io', 'access-control-allow-methods': 'POST', 'access-control-allow-headers': 'Authorization, Content-Type, On-behalf-of, x-sg-elas-acl', 'access-control-max-age': '600', 'x-no-cors-reason': 'https://sendgrid.com/docs/Classroom/Basics/API/cors.html', 'strict-transport-security': 'max-age=600; includeSubDomains' }, body: { errors: [Array] } } }

medusajs/medusa: 1.20 v medusajs/medusa-cli: 1.3.21 v

facing this error while using the sendGrid to send the order confirmation emails.

Also, pls provide the correct steps, In docs is somewhat, confusing, may be I missed something just to check with. Thanks! FYI: @olivermrbl

Just in case this is still an issue for you, or if anyone else comes up against this.
I received this error when I used the incorrect value for templateID - i first attempted to use the name of the sendgrid template - you must use the Template ID

image

@AbhinavChavareTechcopain

Hello guys,
I have installed Medusa send grid,
having an account in send grid also has Single Sender Verification.
I have loaded the plugin in the Medusa config file still I am still struggling to send the mail to reset user password.
Please guide for the same.

@SGFGOV
Copy link
Contributor

SGFGOV commented Mar 27, 2024 via email

@AbhinavChavareTechcopain
Copy link

AbhinavChavareTechcopain commented Mar 27, 2024 via email

@luongtrieuvy202
Copy link

I solved this by using npm instead of yarn, and the email notification works perfectly. It seems like the problem is the same as in #5902.

@pixelwiese
Copy link

pixelwiese commented Apr 23, 2024

I am not sure if it resolves the errors above but in my case it just was a typo in the medusa-config.js and because it's in the documentation like this i think it is worth sharing.

I followed the Documentation under https://docs.medusajs.com/plugins/notifications/sendgrid#order-shipment-created and put the provided key order_shipped_template in my medusa-config.js file.

So after trying a lot of different things I started checking the code of src/services/sendgrid.js (Node Module) i saw that there is a getTemplateId function which normalizes the Event-Key to (probably) get the Template-Id from the config file later. (Also i could not find any hard coded order_shipped_template in the code. )
I tried order_shipment_created_template as key and it suddenly worked.

So i hope this helps others as well :)

@Adityagndusharma
Copy link

@damienmutt actually I just checked again. Yes, I do get the same messages.

The subscriber in ...\medusa-plugin-sendgrid\subscribers\order.js is missing a config.

I guess you don't have to rely on that anymore. Sorry for the confusion. Still, I left my previous post just in case it helps you somehow.

I am getting the same warning. Please help out

@falguni-green-apex
Copy link

I have created dynamic template and added sendgrid key, from email and template id in env and in medusa.config file. Still struggling to send order placed email. I am not knowing that what i am missing more. Can anyone suggest me in this? I did all this in backend code.

@olivermrbl
Copy link
Contributor

@falguni-green-apex, can you share your plugin configuration?

@falguni-green-apex
Copy link

@falguni-green-apex, can you share your plugin configuration?

Here is plugin configuration that i have applied in medusa-config.js file and dynamic template in my sendgrid account.
{
resolve: medusa-plugin-sendgrid,
options: {
api_key: process.env.SENDGRID_API_KEY,
from: process.env.SENDGRID_FROM,
order_placed_template: process.env.SENDGRID_ORDER_PLACED_TEMPLATE
},
},
Screenshot (13)

@sradevski
Copy link
Member

Hey, thanks for the report! Since v2 brought a lot of architectural and API changes on the backend, we will be closing this ticket since it no longer applies to our new setup, or the issue has already been fixed. If you are still facing issues with v1,
please open a new ticket and we will address it as soon as possible. Thanks! 🙏

@NicolasGorga
Copy link

@sradevski Sorry, but i don't see how the last message is a valid conclusion to this issue. This was raised for v1, not v2.
Using Medusa 1.20.9 and medusa-plugin-sendgrid 1.3.13 the plugin loads but no emails are sent with the everything set up on Sendgrid.

Receiving warning:

warn: The subscriber in E:\proyectos personales\centr0\mercur\marketplace-1.2.x\marketplace\api\node_modules\medusa-plugin-sendgrid\subscribers\order.js is missing a config.
warn: The subscriber in E:\proyectos personales\centr0\mercur\marketplace-1.2.x\marketplace\api\node_modules\medusa-plugin-sendgrid\subscribers\restock.js is missing a config.
warn: The subscriber in E:\proyectos personales\centr0\mercur\marketplace-1.2.x\marketplace\api\node_modules\medusa-plugin-sendgrid\subscribers\user.js is missing a config

Is there any plan to fix this? It confuses me "or the issue has already been fixed". Where is the fix?

@sradevski
Copy link
Member

@NicolasGorga if it is still an issue, please submit a reproduction of the issue with some more information based on your debugging. As you can see in the thread, there have been many issues reported and many people resolved the issue on their own, as it was mostly a configuration issue.

We've tested the plugin and it works, so I would suggest you have a look at your configuration first, and ensure everything is set up correctly in sendgrid (domain verification and so on).

@NicolasGorga
Copy link

@sradevski I had already validated everything was okay with sendgrid, since i was able to send emails, by calling directly sendNotification method of the plugin service class, inside a custom API route. Created new issue with as much detail as possible of the different debugging i did and things i found, hope this gets solved, regardless of V2, since many of us use and will still use V1 for quite some time, thanks!

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

No branches or pull requests