Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

403 Forbidden when updating a MediaItem I just created? #256

Open
audigex opened this issue May 3, 2021 · 4 comments
Open

403 Forbidden when updating a MediaItem I just created? #256

audigex opened this issue May 3, 2021 · 4 comments

Comments

@audigex
Copy link

audigex commented May 3, 2021

I create a MediaItem (uploading an image) ma, then create a post p using WooCommerce. This works fine, both the media item and post are created fine

I then try to update the MediaItem such that mi.Post = p.ID At that point, I get a 403 Forbidden on the call to Media.Update

This happens regardless of whether I use the original returned ma item, or create a new MediaItem and just set Id and Post

Am I doing something wrong, or is this a bug? I don't understand why I would get a 403 when Updating an image when I was just able to successfully create the image

@audigex
Copy link
Author

audigex commented May 3, 2021

Further details: Here's the request:

{
   "Method":"POST",
   "RequestUri":"https://<redacted>/wp-json/wp/v2/media/140200",
   "Version":1.1,
   "Content":"System.Net.Http.StringContent",
   "Headers":{
	  "Authorization":"Bearer <redacted>  Content-Type":"application/json; charset=utf-8  Content-Length":233
   }
}

And response:

{
   "StatusCode":403,
   "ReasonPhrase":"Forbidden",
   "Version":1.1,
   "Content":"System.Net.Http.HttpConnectionResponseContent",
   "Headers":{
      "Date":"Mon",
      "03 May 2021 13":"05":"39 GMT  Server":"Apache  x-backend-server":"<redacted>  x-service-level":"wordpress  x-via":"LHR2  Content-Length":"199  Content-Type":text/html; charset=iso-8859-1
   }
}

And this is all I see in the server access logs (with comments for what I believe is happening at each stage

// Search for the post
[03/May/2021:14:13:36 +0100] "GET /wp-json/wc/v3/products?sku=G-0003-999997 HTTP/1.1" 200 2 "-" "-"
// Upload the media item
[03/May/2021:14:13:38 +0100] "POST /wp-json/wp/v2/media HTTP/1.1" 201 7714 "-" "-"
// I'm pretty sure this is the woocommmerce library retrieving the image I've just created
[03/May/2021:14:13:40 +0100] "GET /wp-content/uploads/2021/05/G-0003-999997.jpg HTTP/1.1" 200 64607 "https://<redacted>/wp-content/uploads/2021/05/G-0003-999997.jpg" "WordPress/5.7.1; https://<redacted>.co.uk"
// Create the product
[03/May/2021:14:13:39 +0100] "POST /wp-json/wc/v3/products HTTP/1.1" 201 6793 "-" "-"
// Attempt to update the media item
[03/May/2021:14:13:41 +0100] "POST /wp-json/wp/v2/media/140203 HTTP/1.1" 403 199 "-" "-"

Is there anything else I can retrieve that would help debug this?

@ThomasPe
Copy link
Member

ThomasPe commented May 3, 2021

can you link it to a regular (non-Woocommerce) post?

@audigex
Copy link
Author

audigex commented May 6, 2021

I don't think the site has any non-WooCommerce posts, but I'll see if I can get one created and try it out

@NewcodeTechnology
Copy link

Hi I am having a similar issue with uploading media images and I am getting 403 did you get a fix for this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants