1

How do I attach images and videos on my post via WP REST API?
I was trying via /wp-json/wp/v2/posts/3372/meta including form-data key and value (images) but returns the following

{
    "code": "rest_forbidden",
    "message": "Sorry, you cannot view this post.",
    "data": {
        "status": 401
    }
}
dingo_d
  • 11,160
  • 11
  • 73
  • 132
Daniel Junior
  • 11
  • 1
  • 1

1 Answers1

0

WPAPI Official has a good article about this.

You need to do the following two steps.

  1. Upload media via REST API. This is done in a POST request, for more info, see this answer .
  2. If you wish to set the uploaded media as featured image, include the media id in featured_media field in your POST request, see this doc.
  3. If you wish to attach image in to content of a post, then you'll need to create an image tag in content html. Like <img src="linkToUploadedMedia">
Jack Song
  • 1,355
  • 13
  • 22