OnePost

FREEMIUM
By Adam Darrah | Updated a month ago | Social
Popularity

8.6 / 10

Latency

950ms

Service Level

100%

Health Check

N/A

Back to All Tutorials (10)

Create a Post with Image Upload

By default, the API documentation assumes that you’re sending all API requests with a JSON request body. You can see how this works for creating a new Post from the Create a Post API documentation. For most cases, this works great! However, when it comes to attaching an image to the post, this will only work for posts that have already been uploaded to the internet (so that you have the URL). So, what happens if you need to upload the image?

Luckily, the “Create a Post” endpoint also supports creation via form-data parameters, which makes it possible to upload an image using the image parameter. Here is an example of how this works with cURL:

curl --location --request POST 'https://onepost1.p.rapidapi.com/api/v1/posts?secret_key=sk-cbe...' \
> --header 'x-rapidapi-host: onepost1.p.rapidapi.com' \
> --header 'x-rapidapi-key: 9d0...' \
> --form 'post[body]="Red Rocks!"' \
> --form 'post[authorized_page_ids][]="10"' \
> --form 'post[authorized_page_ids][]="11"' \
> --form 'post[image]=@"/Users/adam/Downloads/redrockseaster.jpg"'

{"id":11,"body":"Red Rocks!","created_at":"2021-02-23T08:00:49.885-05:00","updated_at":"2021-02-23T08:00:49.919-05:00","state":"draft","publish_at":null,"authorized_page_ids":[10,11],"image_url":"https://onepost-aws-assets.s3.amazonaws.com/jue4mlp2vf63v5brq3s572qmmdye?response-content-disposition=inline%3B%20filename%3D%22redrockseaster.jpg%22%3B%20filename%2A%3DUTF-8%27%27redrockseaster.jpg\u0026response-content-type=image%2Fjpeg\u0026X-Amz-Algorithm=AWS4-HMAC-SHA256\u0026X-Amz-Credential=AKIAZN2CXLF3YEIHHHFZ%2F20210223%2Fus-east-1%2Fs3%2Faws4_request\u0026X-Amz-Date=20210223T130050Z\u0026X-Amz-Expires=300\u0026X-Amz-SignedHeaders=host\u0026X-Amz-Signature=f87ac5afbcc2ef2bd24306b1af8f505f587cc5fa93ee4943cec91f983f4fdcbf","social_posts":[{"id":12,"post_id":11,"created_at":"2021-02-23T08:00:49.896-05:00","updated_at":"2021-02-23T08:00:49.896-05:00","type":"SocialPosts::Twitter","state":"unsent","authorized_page_id":10},{"id":13,"post_id":11,"created_at":"2021-02-23T08:00:49.904-05:00","updated_at":"2021-02-23T08:00:49.904-05:00","type":"SocialPosts::Facebook","state":"unsent","authorized_page_id":11}]}

If you’re using a tool like Postman, here is what this might look like;