Toplu Gönderiler Oluşturun
Bu örnekte, tek bir istekte birden fazla gönderinin nasıl oluşturulacağına bakacağız. Predis.ai API. biz geçeceğiz n_posts parametresi 3 tek bir istekte 3 gönderi oluşturmak için. Ayrıca birden fazla iletebilirsiniz template_ids Bu gönderilerin belirli tasarımlarda/şablonlarda olmasını istiyorsanız.
Eğer uzunluğu template_ids ve n_posts eşleşmezse, birden fazla gönderi oluşturmak için her ikisinin de minimumu kullanılacaktır.
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))
Eğer alırsan inProgress yanıt olarak durum, isteğiniz başarılı oldu ve gönderiler oluşturuluyor. Gönderiler başarıyla oluşturulduktan (veya başarısız olduktan) sonra, yapılandırılmış webhook URL'nizde gönderiler hakkında daha fazla ayrıntı içeren bir istek alacaksınız. Birden fazla gönderi olması durumunda, her gönderi için webhook etkinliğini ayrı ayrı alacaksınız.