Create Posts in Bulk
In this example we will look at how to create multiple posts in a single request using Predis.ai API. We will pass the n_posts parameter to 3 to generate 3 posts in a single request. You can also pass multiple template_ids if you want these posts in specific designs/templates.
If the length of template_ids and n_posts don't match, then minimum of both will be used to generate multiple posts.
import json
import requests
url = "https://brain.predis.ai/predis_api/v1/create_content/"
payload = {
"brand_id": "YOUR_BRAND_ID",
"text": "3 tips for a healthy morning breakfast",
"media_type": "carousel",
"template_ids": json.dumps(["TEMPLATE_ID_1", "TEMPLATE_ID_2", "TEMPLATE_ID_3"]), # pass template_ids if you want video in specific design
"n_posts": 3, # generate these many posts
"model_version": "2", # template_ids not supported by model_version 4
}
headers = {"Authorization": "YOUR_API_KEY"}
response = requests.request("POST", url, data=payload, headers=headers)
if response.status_code == 200:
json_response = response.json()
post_id = json_response.get("post_id")
post_status = json_response.get("status")
else:
print("Error occurred - {}".format(response.text))
If you get a inProgress status in response, your request is successful and the posts are getting generated. Once the posts get generated successfully (or fail), you will get a request on your configured webhook URL with more details about the posts. In the case of multiple posts, you will receive the webhook event for each post separately.