Publish existing product

Solved
Highlighted
New Member
8 0 0

Hi everyone, 

 

I'd like to know how can I publish an existing product via the REST API.

 

I've tried to send something like that :

{
"product": {
"id": xxxxxxxxxxx,
"published": true
}
}

But I keep getting a 400 Bad Request.

 

0 Likes
Highlighted
Excursionist
80 19 19

This is an accepted solution.

Hi

We'll need a little more information than this if possible.

What's the endpoint you're hitting?

What method is the request? (i.e. GET, POST, PUT etc.)

Are you sending the data in your post as the body of a POST request?

I believe for this kind of update you'll want to PUT to an endpoint that includes the product ID in the URL:

// PUT /admin/api/2020-07/products/xxxxxxxxxxx.json
{
  "product": {
    "id": xxxxxxxxxxx,
    "published": true
  }
}

 

0 Likes
Highlighted
New Member
8 0 0

Endpoint is : /admin/api/2020-01/orders/xxxxxxxxxxxxx.json

Request type : PUT

And yes, the JSON is the body of the request.

0 Likes
Highlighted
Excursionist
80 19 19

Hi There

So you're hitting the /orders/ endpoint from your post above?

That should be going to the /products/ endpoint?

Might just be a typo but worth checking?

 

0 Likes
Highlighted
New Member
8 0 0

Oh sorry that was a typo in my post.

I'm hitting the /products/ endpoint not the /order/ one

 

Also, I actually get a 406 error, I thought it was a 400 but it is not.

0 Likes
Highlighted
Excursionist
80 19 19

Hi Nicolas

So a 406 normally means some kind of misformed request.

Do you have the full headers object for the request?

How are you making the request?

Would you be able to share the code for how you're making the request?

Do the keys your using have the correct Product Write permissions?

Sorry hard to know exactly what to tell you unless we get a bit more info.

0 Likes