#No Processing order.placed logged in the backend when a order is processed -> SendGrid

36 messages · Page 1 of 1 (latest)

wintry coyote
#

Hi,
I am trying to debug my sendgrid workflow.
I want an email to be sent after the completion of an order.
I even added the src/subscribers/order-placed.ts file as it was recommended by an user having the same issue.
I am using the next starter medusa admin and storefront with a local docker postgresql database.
"@medusajs/medusa": "1.20.1",
"medusa-plugin-sendgrid": "^1.3.12",

But unlinke this user, I don't see any mention to Processing order.placed in my backend logs.
When I a make an order, the order appears on my admin but I have no mention of it in my backeng logs:

WARN: withTransaction called without custom implementation
WARN: withTransaction called without custom implementation
WARN: withTransaction called without custom implementation
info:    Processing cart.updated which has 0 subscribers
::1 - - [14/Feb/2024:13:23:45 +0000] "POST /store/carts/cart_01HPKWH9RMJ809QEMSZT40GGMH/complete HTTP/1.1" 200 4444 "-" "axios/0.24.0"
::1 - - [14/Feb/2024:13:23:45 +0000] "GET /store/regions HTTP/1.1" 200 2315 "-" "Next.js Middleware"
::1 - - [14/Feb/2024:13:23:45 +0000] "GET /store/orders/order_01HPKWK7Q4AQHR134WWXX1MJWQ HTTP/1.1" 200 4758 "-" "axios/0.24.0"
::1 - - [14/Feb/2024:13:23:45 +0000] "GET /store/collections?limit=100&offset=0 HTTP/1.1" 200 238 "-" "axios/0.24.0"
::1 - - [14/Feb/2024:13:23:45 +0000] "GET /store/regions HTTP/1.1" 200 2315 "-" "axios/0.24.0"
::1 - - [14/Feb/2024:13:23:45 +0000] "GET /store/regions HTTP/1.1" 200 2315 "-" "Next.js Middleware"
::1 - - [14/Feb/2024:13:23:46 +0000] "GET /store/product-categories?limit=100&offset=0 HTTP/1.1" 200 58 "-" "axios/0.24.0"
::1 - - [14/Feb/2024:13:23:46 +0000] "GET /store/orders/order_01HPKWK7Q4AQHR134WWXX1MJWQ HTTP/1.1" 200 4758 "-" "axios/0.24.0"
::1 - - [14/Feb/2024:13:23:46 +0000] "GET /store/collections?limit=100&offset=0 HTTP/1.1" 200 238 "-" "axios/0.24.0"
::1 - - [14/Feb/2024:13:23:46 +0000] "GET /store/regions HTTP/1.1" 200 2315 "-" "axios/0.24.0"

#
::1 - - [14/Feb/2024:13:23:46 +0000] "GET /store/product-categories?limit=100&offset=0 HTTP/1.1" 200 58 "-" "axios/0.24.0"
::1 - - [14/Feb/2024:13:23:46 +0000] "GET /store/products?id%5B0%5D=prod_01HPKMG0TCCFARMEWPGBCFVD94&region_id=reg_01HPKKYABAGKF5BCATA5RN0F0C HTTP/1.1" 200 3258 "-" "axios/0.24.0"
::1 - - [14/Feb/2024:13:23:47 +0000] "GET /store/products?id%5B0%5D=prod_01HPKMG0TCCFARMEWPGBCFVD94&region_id=reg_01HPKKYABAGKF5BCATA5RN0F0C HTTP/1.1" 200 3258 "-" "axios/0.24.0"
info:    Processing product-variant.updated which has 1 subscribers

I have also this warn: The subscriber in /Users/saadchraibi/playgrounds/medusa/medusa14/medusa14/node_modules/medusa-plugin-sendgrid/subscribers/order.js is missing a config.

yarn run v1.22.21
warning ../package.json: No license field
$ cross-env npm run build:server && medusa develop

> [email protected] build:server
> cross-env npm run clean && tsc -p tsconfig.server.json


> [email protected] clean
> cross-env ./node_modules/.bin/rimraf dist

Successfully compiled 0 files with Babel (7ms).
2:09:42 PM [@medusajs/admin] Started development server on http://localhost:7001/
<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: http://localhost:7001/
<i> [webpack-dev-server] On Your Network (IPv4): http://192.168.11.103:7001/
<i> [webpack-dev-server] On Your Network (IPv6): http://[fe80::1]:7001/
<i> [webpack-dev-server] Content not from webpack is served from '/Users/saadchraibi/playgrounds/medusa/medusa14/medusa14/public' directory
<i> [webpack-dev-server] 404s will fallback to '/'
info:    Connection to Redis established

....
....

⠴ Initializing modules
✔ Modules initialized – 2381ms
✔ Express intialized – 79ms
⠋ Initializing plugins
⠹ Initializing plugins
warn:    The subscriber in /Users/saadchraibi/playgrounds/medusa/medusa14/medusa14/node_modules/medusa-plugin-sendgrid/subscribers/order.js is missing a config.
#

This is the content of my src/subscribers/order-placed.ts

import {
  type SubscriberConfig,
  type SubscriberArgs,
  OrderService,
} from "@medusajs/medusa";

export default async function handleOrderPlaced({
  data,
  eventName,
  container,
  pluginOptions,
}: SubscriberArgs<Record<string, string>>) {
  const sendGridService = container.resolve("sendgridService");
  const orderService: OrderService = container.resolve("orderService");

  const order = await orderService.retrieve(data.id, {
    // you can include other relations as well
    relations: ["items"],
  });

  sendGridService.sendEmail({
    templateId: "d-efb0c8d3de0448e3b0b397b89bd2be26",
    from: "[email protected]",
    to: order.email,
    dynamic_template_data: {
      // any data necessary for your template...
      items: order.items,
      status: order.status,
      email: order.email,
    },
  });
}

export const config: SubscriberConfig = {
  event: OrderService.Events.PLACED,
  context: {
    subscriberId: "order-placed-handler",
  },
};

And this the detail of the plugin configuration

 {
    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_ID,
    },
  },
plush scaffold
#

could it be that you are missing an await on sendGridService.sendEmail({ ?
I also have a suscriber with sendgrid that works well and comparing the codes is the only thing I see different (besides the function name and susbcriber id that I used the word create insted of placed, but I don't think that's relevant as is the same event id)

wintry coyote
#

I resolved the issue by running a local docker redis instead of pointing to an remote railway one

shell merlin
wintry coyote
#

I had no issue with railway. Are you able to see the connection with redis , and redis events ?

shell merlin
#

Can I ask how to check all this?

Currently on my deployed backend , I had run the redis with the remote redis url from Railway

When I created an order, the backend logged oreder.placed perfectly, but the Redis is not logging anything on Railway Redis logs

At the same time, on SendGrid dashboard, it's request was increased but none of them is delivered.

So I am not sure about which part is doing wrong

Appreciate for your response

#

This is the backend logs I got when created an order

#

This is my "/src/subscribers/order-placed.ts" file

#

This is medusa-cofig.js file

lavish tree
#

But your issue is not Redis. Sendgrid.

#

You can see your subscriber running.

shell merlin
#

I see.
On my Sendgrid, I had set the template email , api key and also the sender properly, is that any other possible reason that make the email failed to deliver out?

#

Btw, I am using a gmail email as my sender

lavish tree
#

Have you verified it

shell merlin
#

Yes I had verified it

lavish tree
#

I don't know, check Sendgrid logs

#

And check spam.

shell merlin
#

All email is still on "pending" status 🥲

#

I'm not sure is it because of using Gmail as sender.
Because when I created the sender and get a helper message said that "gmail is not recommended", but I think it's shouldn't be a problem to use gmail on Sendgrid right?

lavish tree
#

Are those the actual logs?

#

There aren't any more logs?

#

What's in the details of the event?

#

Do some search, I don't use Sendgrid.

shell merlin
#

Okay thanks so much

#

Can I know which notification plugin do you use or any recommendation from you?

lavish tree
#

I manualy send emails in subscribers using nodemailer, postmark and react-mjml templates

shell merlin
#

okay thanks! I think I will try manually sending emails too instead of using plugin

lavish tree
#

I pay for Postmark service, because I use it on other websites and apps too, but there are cheaper ones.
Then I use nodemailer in subscribers to connect with Postmark. I craete the temapltes manually in react-mjml

shell merlin
#

Alright, I will have a look on all these options, I think Resend is much more user friendly to use it

lavish tree
#

By the way you don't need to use nodemailer and just use the api client.