#Strapi Medusa Integration

47 messages · Page 1 of 1 (latest)

surreal pelican
#

Strapi Medusa Integration seems to be not working as expected.
After following the recently updated docs:

https://docs.medusajs.com/add-plugins/strapi/

When creating a product in Medusa it is expected the product to be created in Strapi.
The product is not created in the Strapi side.

This messages appear in the console:

In this document, you’ll learn how to integrate Strapi with Medusa to add rich Content Management System (CMS) functionalities.

sonic current
#

Can you show the logs on the Strapi server after you create a product? Also, can you share your environment variables and Medusa plugin configurations (without the passwords of course)

surreal pelican
sonic current
#

I can see you didn’t set the STRAPI_PROTOCOL environment variable to http which, as indicated in the docs, should be set if you are working with a local strapi server. Can you try setting it?

surreal pelican
#

Same outcome:

JWT_SECRET=something
COOKIE_SECRET=something
STRIPE_API_KEY=
STRIPE_WEBHOOK_SECRET=
STRAPI_USER=medusa_user
STRAPI_PASSWORD=stInterno#1
STRAPI_PROTOCOL=http

sonic current
#

Can you show me the logs on the strapi server when you add a product (not the medusa server)?

surreal pelican
#

checking...

#

no line gets written other than:
[2022-09-26 15:45:13.891] http: HEAD /_health (1 ms) 204

#

im creating the products by using the medusa admin interface

sonic current
#

Just to check: when you added the protocol environment variable you also added it in medusa-config.js right? And you also restarted the server afterwards?

surreal pelican
#

yes to all of the above

#
  `medusa-fulfillment-manual`,
  `medusa-payment-manual`,
  // Uncomment to add Stripe support.
  // You can create a Stripe account via: https://stripe.com
  // {
  //   resolve: `medusa-payment-stripe`,
  //   options: {
  //     api_key: STRIPE_API_KEY,
  //     webhook_secret: STRIPE_WEBHOOK_SECRET,
  //   },
  // }, 
  {
    resolve: `medusa-plugin-strapi`,
    options: {
      strapi_medusa_user: process.env.STRAPI_USER,
      strapi_medusa_password: process.env.STRAPI_PASSWORD,
      // strapi_url: process.env.STRAPI_URL, //optional
      // strapi_port: process.env.STRAPI_PORT, //optional
      strapi_protocol: process.env.STRAPI_PROTOCOL //optional
    }
  }   
];```
#

looking like this right now

sonic current
#

Can you try sending a POST request to your strapi server on the endpont /api/auth/local with a JSON body that has identifier property set to the username and a password property set to the password? Looking at your Medusa logs it seems like there’s an issue with logging into Strapi or with the role of the user

#

If you send a POST request like I mentioned and you get no errors then please check that the user you’re using has the Authenticated role and that this role has permissions to create products

surreal pelican
#

ok i will try that. right now the user is "medusa_user" and it has the Authenticated role.

#

i've added permissions for products, products variants on that role.

sonic current
#

Can you also try to show me the strapi logs once you start the Medusa server until adding the product?

surreal pelican
sonic current
#

Cool those are the Medusa server logs, please send me the strapi logs as well

surreal pelican
#
strapi-medusa % npm run develop

> strapi-medusa@0.1.0 develop
> strapi develop

Building your admin UI with development configuration...
Admin UI built successfully

 Project information                                                          

┌────────────────────┬──────────────────────────────────────────────────┐
│ Time               │ Mon Sep 26 2022 15:47:16 GMT-0400 (Atlantic Sta… │
│ Launched in        │ 1476 ms                                          │
│ Environment        │ development                                      │
│ Process PID        │ 21264                                            │
│ Version            │ 4.3.9 (node v16.15.1)                            │
│ Edition            │ Community                                        │
└────────────────────┴──────────────────────────────────────────────────┘

 Actions available                                                            

Welcome back!
To manage your project 🚀, go to the administration panel at:
http://localhost:1337/admin

To access the server ⚡️, go to:
http://localhost:1337

[2022-09-26 15:47:39.922] http: HEAD /_health (20 ms) 204
[2022-09-26 15:50:18.738] http: HEAD /_health (1 ms) 204
[2022-09-26 15:50:41.133] http: HEAD /_health (0 ms) 204
#

not much happens after adding products in that log

sonic current
#

It’s strange since it seems like Medusa isn’t receiving the expected response from Strapi on initialization. Can you send what versions are you using of Medusa and the Strapi plugin?

surreal pelican
#

how can i confirm that?

surreal pelican
#

i believe i was able to sync two ways finally.

sonic current
#

You can check the versions using the commands npm list @medusajs/medusa and npm list medusa-plugin-strapi

sonic current
surreal pelican
#

i have restarted things from zero after confirming every piece.
once i've made sure the 'http' as protocol since testing locally, right permissions are set for the user (Product, Product-Variant) in the Authenticated role and restarted both medusa-server and strapi-medusa things started to work as expected

#

thanks a lot for helping out in an expedite way, really appreciate it.

sonic current
#

Glad it worked out!

spiral canopy
#

is that ok that some of the relations in strapi are broken when I'm using template?

#

@sonic current

sonic current
#

@spiral canopy not really sure. This is a community plugin/template, we just fixed it up to make sure it works for v4 of Strapi

spiral canopy
#

maybe someone already fixed this issue with relations?

surreal pelican
#

i would have preferred a separate role and not Authenticated role. but i haven't tested like that yet.

#

if the plugin / template for the integration expects the "Authenticated" hard coded that might not work, but im not sure.

spiral canopy
spiral canopy
#

@surreal pelican looks like strapi-medusa-template has schema from v3 which is not working as expected with v4 have you solved it? Or you are using strapi just for extra pages etc.?

surreal pelican
spiral canopy
knotty swift
#

unrelated question, may I ask why would you add products to stripe too, when it can generate dynamically chcekouts? Sorry, I'm new here

crimson stirrup
#

Hi @sonic current and @surreal pelican ! I just followed your conversation and it helped me a lot, but I got an unexpected error when creating the product on the admin website. It looks like the event is well triggered but the obj is not created on the strapi site with the below error.

This is Strapi log error:

[2023-03-21 19:45:42.482] http: GET /api/products (57 ms) 200
[2023-03-21 19:45:42.772] error: Cannot read properties of undefined (reading 'response')
TypeError: Cannot read properties of undefined (reading 'response')
    at Object.create (C:\helios-strapi\src\api\product\controllers\product.js:36:38)
    at dispatch (C:\helios-strapi\node_modules\koa-compose\index.js:42:32)
    at returnBodyMiddleware (C:\helios-strapi\node_modules\@strapi\strapi\lib\services\server\compose-endpoint.js:52:24)
    at dispatch (C:\helios-strapi\node_modules\koa-compose\index.js:42:32)
    at policiesMiddleware (C:\helios-strapi\node_modules\@strapi\strapi\lib\services\server\policy.js:24:11)
    at dispatch (C:\helios-strapi\node_modules\koa-compose\index.js:42:32)
    at C:\helios-strapi\node_modules\@strapi\strapi\lib\services\server\compose-endpoint.js:33:12
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async C:\helios-strapi\node_modules\@strapi\strapi\lib\middlewares\body.js:58:9
    at async C:\helios-strapi\node_modules\@strapi\strapi\lib\middlewares\logger.js:25:5

And this is the log from the Medusa server:

info:    Processing product.created which has 2 subscribers
warn:    An error occurred while processing product.created: Error: Error while trying to create entry in strapi - products
crimson stirrup
#

Also, I used this template for my strapi Kyle772/strapi-medusa-template... maybe that is where the error comes from? If unsured, I will try with the template shahednasser/strapi-medusa-template