#can't create a product

30 messages ยท Page 1 of 1 (latest)

hearty crescent
#

POST /admin/products im receving this errror

midnight pike
#

Can't really tell since you aren't showing the entire body of your request. But the payload should look like this:

{
  // ...product fields
  options: [
    { title: "Size" }
  ],
  variants: [
    {
       // ...variant fields
       options: [
         { value: "Small" }
       ]
    }
  ]
}
hearty crescent
#

Yeah it is like that

midnight pike
#

Could you share your payload, so I can have a look? ๐Ÿ™‚ And since I know you are doing a lot of custom overrides with the extender, can you confirm that you haven't overriden any of the default code associated with product creation?

hearty crescent
#

No no i havent, i overwritten the route and in the controller im calling .create

#

I Will share the payload one second

midnight pike
#

Okay but you have overritten the router then. Have you looked at how the default route works? It first calls productService.create, and then calls productVariantService.create for each variant that is part of the payload, and adds the option id to the payload, so I would guess you aren't doing that, hence you are getting this error.

hearty crescent
#

mmmm probably yeah

#

let me test

hearty crescent
#

so like that ?

#

cause im still receiving the same error

#

did i write it correctly?

midnight pike
hearty crescent
#

its not reaching the creation of products thats the thing

#

so like its not logging ```created product ...

midnight pike
#

Please take a look at the code I sent you. The call to productService.create will fail if you try to pass the variants along. That is why in our route we do this:

 const { variants } = validated
 delete validated.variants

You want to create the variants separately from the product.

hearty crescent
#

I tried to destructure the req.body

#

let { variants, ...data } = req.body

#

and received the same error aswell

#

i receive this error instead

midnight pike
#

Not really possible for you to get the initial error when you aren't passing the variants along. You might be getting a new error because you are not passing along a profile_id as we do in our implementation, and you could also be missing other required fields. I've given you all the info you need, I just think you have to dig a bit into our code to see how we are doing it and make sure you are following the same principles in your implementation ๐Ÿ™‚

hearty crescent
#
{
    "title": "winterr",
    "subtitle": "warma",
    "material": "100%",
    "handle": "winter handle e",
    "discountable": true,
    "is_giftcard": false,
    "profile_id":"sp_01GF9A8A19P0VHVVBMF18Q3WJ3",
    "collection_id": "pcol_01GF48ABPSMRTWMGPFEWQKXKHW",
    "description": "zczczxcz",
    "height": 100,
    "length": 100,
    "weight": 100,
    "width": 100,
    "hs_code": "ascsadassadfsdfdsaa",
    "mid_code": "adaaas",
    "tags": [
        {
            "value": "tags"
        }
    ],
    "origin_country": "LB",
    "options": [
        {
            "title":"_new"
        }
    ],
    "variants": [
        {
            "title": "One Size",
            "material": "80%",
            "inventory_quantity": 101,
            "prices": [
                {
                    "amount": 10000,
                    "currency_code": "usd"
                }
            ],
            "allow_backorder": false,
            "sku": "d3311",
            "barcode": "sdcdascds",
            "options": [
                {
                    "value": "One Size"
                }
            ],
            "ean": "asdaaaaaaaasd",
            "upc": "sddcsdcdaaaas",
            "height": 101,
            "length": 100,
            "weight": 101,
            "width": 100,
            "hs_code": "sddaaaacfdsds",
            "mid_code": "caaaaascac",
            "origin_country": "LB",
            "manage_inventory": true
        }
    ],
    "status": "published"
}
#

this is my full payload

hearty crescent
#
    "title": "string",
    "subtitle": "string",
    "description": "string",
    "is_giftcard": false,
    "discountable": true,
    "profile_id": "sp_01GF9A8A19P0VHVVBMF18Q3WJ3",
    "images": [
        "string"
    ],
    "thumbnail": "string",
    "handle": "string",
    "status": "draft",
    "type": {
        "value": "string"
    },
    "collection_id": "pcol_01GF48ABPSMRTWMGPFEWQKXKHW",
    "tags": [
        {
            "id": "value",
            "value": "value"
        }
    ],
    "options": [
        {
            "title": "string"
        }
    ],
    "variants": [
        {
            "title": "string",
            "sku": "string",
            "ean": "string",
            "upc": "string",
            "barcode": "string",
            "hs_code": "string",
            "inventory_quantity": 0,
            "allow_backorder": true,
            "manage_inventory": true,
            "weight": 0,
            "length": 0,
            "height": 0,
            "width": 0,
            "origin_country": "string",
            "mid_code": "string",
            "material": "string",
            "metadata": {},
            "prices": [
                {
                    "amount": 10000,
                    "currency_code": "usd"
                }
            ],
            "options": [
                {
                    "value": "One Size"
                }
            ]
        }
    ],
    "weight": 100,
    "length": 100,
    "height": 100,
    "width": 100,
    "hs_code": "string",
    "origin_country": "string",
    "mid_code": "string",
    "material": "string",
    "metadata": {}
}
#

@midnight pike still no luck bro

#

I have the id bug

hearty crescent
hearty crescent
#

I just tried the core medusa call, with only title as required in the documentation.