Invalid type specified in payload


#1

When trying to add a product to a cart

my json code is as follow
{ "quantity": "2", "type": "cart_item", "id": "1121a4db-604b-4ba9-8f2e-15c77719209e" }

and the error I am getting is:
{ "errors": [ { "status": 400, "source": "request", "title": "Bad Request", "detail": "Invlaid type specified in payload." } ] }


#2

Hey @handre

Your payload needs to be inside data.

So something like:

{
  "data": { "quantity": "2", "type": "cart_item", "id": "1121a4db-604b-4ba9-8f2e-15c77719209e" }
}

would work :slight_smile:

Let me know if that helps


#3

Id must be the product ID correct?

{ "errors": [ { "status": 404, "title": "Product not found", "detail": "The requested product could not be found" } ] }


#4

That is correct, you specify the card reference in the url /carts/{{cartRef}}/items and the product id in the request body.

Hope this helps


#5

cartRef, must it be unique to each client or can it be a hard-coded reference?

Thanks in advance


#6

the cart should have a unique reference id, if you use our SDK when a cart is created it will be assigned a unique id. If you are coding this yourself you will need to create a unique id for each created cart. Carts are destroyed 7 days after they were last updated.

https://docs.moltin.com/carts-and-checkout/carts

Thanks


#7

Perfect that you very much!


#8

hi @drew

I still get a 404 product not found error. I triple checked and the id is definitely an existing product and valid.


#9

Hey @handre

This looks like it could use some further investigation. Could you raise an issue in our support portal at https://support.moltin.com and provide the request you are making including the url and if you could also provide your store id (you can find that on the dashboard) that would be great.

Thanks


#10

Hi @handre

Is the product status you are adding set to live?


#11

Hi @notrab

After changing the product to live it worked.

That’s great thank you very much.

Because I am still in development all of my test products are drafts. Maybe it can be nice to make it accessible for testing purposes?


#12

Hey @handre

live and draft statuses on products make it easier when using the implicit authentication type, which is often used with frontend applications to get only the products that are public facing.

client_credentials allows you to get all products, regardless of their status.

I’m glad we could help, can’t wait to hear more about your project :smile:


#13

Hi @notrab

I am using the client_credentials authentication? :thinking:

But all is working now, thanks once again.


#14

Hi @notrab,

When I did my testing in postman, it works.
However now that I am actually doing it in my code, I get a 401 (Unauthorized) error?

I know the client_credentials token has not expires as I refreshed it before I tried.

Any suggestions?


#15

Hi @handre

How are you setting the token in your code? Could we possibly take a look at your Auth call?

Thanks

Drew


#16

Hi Drew.

At the moment I am still manually calling through postman, then copying the token like shown below:
token = 'd5236e68ca0609cc6fef3cb9e3d9c948070aa1b7';
then using it as shown:

    return this.http.post(
      `${this.uri}/v2/carts/yourCart/items`,
      { headers: new HttpHeaders().set('Authorization', 'Bearer ' + `${this.token}`).set('Content-Type', 'application/json') }
    );
  }```

#17

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.