• 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 kavitalay.
    • This topic was modified 5 years, 4 months ago by bcworkz. Reason: code fixed

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Eh, looks like you’re at the wrong place.

    You’re using WordPress.com, which is a hosted service and not quite the same as the DIY/self-hosted version of WordPress available and supported here at ww.wp.xz.cn.

    You’ll need to contact WordPress.com for help with this.

    If you’re like to find out more about the differences, please go here:

    WordPress vs WordPress.com

    Or, just please go to https://wordpress.com/support/ for help with your WordPress.com website.

    Good luck!

    Thread Starter kavitalay

    (@kavitalay)

    Oh.. Thanks buddy. I am using wordpress.com But customer support have asked me to post here https://ww.wp.xz.cn/support/
    Also, they said the backend is same.

    • This reply was modified 5 years, 4 months ago by kavitalay.
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Creating post using rest api and setting featured-image’ is closed to new replies.