• I can create an image just fine using the REST API, by sending a POST request to …/media. This returns me an entity including a post ID.

    I’d like then to send a PATCH request to update the content of the image (not just the metadata). When I do this, however, with

    PATCH …/media/<id>

    and send another attachment, it accepts the request (returns a 200), but the image doesn’t actually get updated. I’ve tried with another POST too, but get the same result.

    Am I missing something? Is there a way of doing this?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    POST httр://example.com/wp/v2/media/<id> is supposed to work. I’ve not confirmed it though. Be sure you are logged into the site as a user capable of updating media. (or are using an alternative authentication) The <id> at the end of the URL should be the attachment ID for the image. This is the same ID that was returned when you created the image. The post ID it relates to would have been in the JSON response, tagged ‘post’.

    What’s odd is the arguments listed for updating media in the API Handbook does not include a source_url argument, which would be required in order to update the image itself. You should provide it anyway, or there would be no point to this.

    If all else fails, write an Ajax handler to manage this and send your update POST request to /wp-admin/admin-ajax.php.

Viewing 1 replies (of 1 total)
  • The topic ‘Updating existing image using the REST API’ is closed to new replies.