Creating post using rest api and setting featured-image
-
Hi All,
I am using WordPress rest API to dynamically create my posts without going into the website.
I am able to OAuth2 and got the token too. I am able to create the post by sending the POST req on this link –
https://public-api.wordpress.com/rest/v1.2/sites/$siteID/posts/new
This is the req I am sending using request library in python-my_image = (open('aa.jpg', 'rb')) data = {'slug': 'apitest', 'title': title, 'content':"this is a new post created using rest api> It has tag, category, title", 'tags': 'restAPI', 'categories': 'Shayri', #'featured_image': my_image, } files = {'featured_image': my_image,, 'Content-Type': 'image/jpg', # 'ID':post_ID } response = requests.post(create_post_url, headers = {'Authorization': 'Bearer ' + access_token}, data = data, files = files)I have gone through documents and saw that the featured image is set using a multipart-form post request This is what I am doing in the above code, but I am not able to set the featured image but I am able to set all other things.
Can anyone help with this? I am using python 3.9v and request library for HTTPS req.Thanks
- This topic was modified 5 years, 4 months ago by .
- This topic was modified 5 years, 4 months ago by . Reason: code fixed
The page I need help with: [log in to see the link]
The topic ‘Creating post using rest api and setting featured-image’ is closed to new replies.