Create Blog
Create Blog Endpoint
Section titled “Create Blog Endpoint”Use the following endpoint to create a new blog post via the API.
Ensure you send the parameters nested under a blogParams key in the JSON body.
Endpoint
Section titled “Endpoint”POST /api/v1/public/create-blogAuthentication
Section titled “Authentication”Include your API key in the Authorization header:
Authorization: Bearer YOUR_API_KEYCode Examples
Section titled “Code Examples”const blogParams = { topicKeywords: ["AI", "content creation", "API"], language: { name: "English", value: "en" }, toneStyle: { name: "Informal", value: "Informal", customValue: "" }, contentStructure: { name: "Listicles", value: "Listicles", customValue: "" }, callToAction: { name: "Learn More", value: "Learn more about our services.", customValue: "" }, targetAudience: { name: "Tech enthusiasts", value: "Tech enthusiasts", customValue: "" }, blogLength: { name: "Medium", value: "Medium", customValue: "" }, // Required: "Short", "Medium", or "Long" category: "ai-tools", // Optional hyperlinks: ["https://www.blogz.ai", "https://www.openai.com"], // Optional - Example hyperlinks baseUrlForLinkedBlog: "https://www.mywebsite.com", // Optional metaData: { customKey: "customValue" }, // Optional: Custom metadata externalOpenAiApiKey: "your-openai-api-key" // Optional: Use your own OpenAI API key};
// Endpoint: {API_ENDPOINTS.BLOGS.CREATE}fetch('https://api.blogz.ai/api/v1/public/create-blog', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify({ blogParams }) // IMPORTANT: Nest parameters under 'blogParams' key}).then(response => response.json() // Expecting JSON data for a successful POST).then(data => console.log('Blog created:', data)).catch(error => console.error('Error creating blog:', error));// Define interfaces for structured parameters (optional but recommended)interface Language { name: string; value: string;}interface CallToAction { name: string; value: string; customValue?: string;}interface TargetAudience { name: string; value: string; customValue?: string;}interface ToneStyle { name: string; value: string; customValue?: string;}interface ContentStructure { name: string; value: string; customValue?: string;}interface BlogLength { name: string; value: string; customValue?: string;}
interface BlogParams { topicKeywords: string[]; language: Language; toneStyle: ToneStyle; contentStructure: ContentStructure; callToAction: CallToAction; targetAudience: TargetAudience; blogLength: BlogLength; // "Short", "Medium", or "Long" category: string; // Optional hyperlinks?: string[]; // Optional baseUrlForLinkedBlog?: string; // Optional metaData?: Record<string, any>; // Optional: Custom metadata externalOpenAiApiKey?: string; // Optional: Use your own OpenAI API key}
const blogParams: BlogParams = { topicKeywords: ["AI", "content creation", "API"], language: { name: "English", value: "en" }, toneStyle: { name: "Informal", value: "Informal" }, contentStructure: { name: "Listicles", value: "Listicles" }, callToAction: { name: "Learn More", value: "Learn more about our services." }, targetAudience: { name: "Tech enthusiasts", value: "Tech enthusiasts" }, blogLength: { name: "Medium", value: "Medium", customValue: "" }, // Required: "Short", "Medium", or "Long" hyperlinks: ["https://www.blogz.ai", "https://www.openai.com"], // Optional - Example hyperlinks baseUrlForLinkedBlog: "https://www.mywebsite.com", // Optional category: "ai-tools", // Optional metaData: { customKey: "customValue", }, // Optional: Custom metadata externalOpenAiApiKey: "your-openai-api-key", // Optional: Use your own OpenAI API key};
// Endpoint: {API_ENDPOINTS.BLOGS.CREATE}fetch("https://api.blogz.ai/api/v1/public/create-blog", { method: "POST", headers: { Authorization: "Bearer YOUR_API_KEY", "Content-Type": "application/json", }, body: JSON.stringify({ blogParams }), // IMPORTANT: Nest parameters under 'blogParams' key}) .then((response) => response.json() as Promise<Blog>) // Cast to your Blog type .then((data: Blog) => console.log("Blog created:", data)) .catch((error: Error) => console.error("Error creating blog:", error));import requestsimport json
# Endpoint: {API_ENDPOINTS.BLOGS.CREATE}api_url = "https://api.blogz.ai/api/v1/public/create-blog"api_key = "YOUR_API_KEY"headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
blog_params = { "topicKeywords": ["AI", "content creation", "API"], "language": {"name": "English", "value": "en"}, "toneStyle": {"name": "Informal", "value": "Informal", "customValue": ""}, "contentStructure": {"name": "Listicles", "value": "Listicles", "customValue": ""}, "callToAction": {"name": "Learn More", "value": "Learn more about our services.", "customValue": ""}, "targetAudience": {"name": "Tech enthusiasts", "value": "Tech enthusiasts", "customValue": ""}, "blogLength": {"name": "Medium", "value": "Medium", "customValue": ""}, # Required: "Short", "Medium", or "Long" "hyperlinks": ["https://www.blogz.ai", "https://www.openai.com"], # Optional "category": "ai-tools", # Optional "baseUrlForLinkedBlog": "https://www.mywebsite.com", # Optional "metaData": { "customKey": "customValue" }, # Optional: Custom metadata "externalOpenAiApiKey": "your-openai-api-key" # Optional: Use your own OpenAI API key}
# IMPORTANT: Nest parameters under 'blogParams' key in the payloadpayload = json.dumps({"blogParams": blog_params})
try: response = requests.post(api_url, headers=headers, data=payload) response.raise_for_status() # Raises an HTTPError for bad responses (4XX or 5XX) blog_data = response.json() print("Blog created:", json.dumps(blog_data, indent=2))except requests.exceptions.RequestException as e: print(f"Error creating blog: {e}") # Print response text if available for more details if e.response is not None: print(f"Response body: {e.response.text}")except json.JSONDecodeError: print(f"Error decoding JSON response: {response.text}")# Endpoint: {API_ENDPOINTS.BLOGS.CREATE}curl -X POST https://api.blogz.ai/api/v1/public/create-blog \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "blogParams": { "topicKeywords": ["curl", "api", "example"], "language": {"name": "English", "value": "en"}, "toneStyle": {"name": "Technical", "value": "Technical"}, "contentStructure": {"name": "How-to guides", "value": "How-to guides"}, "callToAction": {"name": "Sign Up", "value": "Sign up for your free trial today!"}, "targetAudience": {"name": "Developers", "value": "Developers"}, "blogLength": {"name": "Medium", "value": "Medium", "customValue": ""}, "hyperlinks": ["https://www.blogz.ai", "https://www.openai.com"], "baseUrlForLinkedBlog": "https://www.mywebsite.com", "category": "ai-tools", "metaData": { "customKey": "customValue" }, "externalOpenAiApiKey": "your-openai-api-key" } }'{ "blogParams": { "topicKeywords": ["AI", "content creation", "API"], "language": { "name": "English", "value": "en" }, "category": "ai-tools", "toneStyle": { "name": "Informal", "value": "Informal", "customValue": "" }, "contentStructure": { "name": "Listicles", "value": "Listicles", "customValue": "" }, "callToAction": { "name": "Learn More", "value": "Learn more about our services.", "customValue": "" }, "targetAudience": { "name": "Tech enthusiasts", "value": "Tech enthusiasts", "customValue": "" }, "blogLength": { "name": "Medium", "value": "Medium", "customValue": "" }, "hyperlinks": ["https://www.blogz.ai", "https://www.openai.com"], "baseUrlForLinkedBlog": "https://www.mywebsite.com", "metaData": { "customKey": "customValue" }, "externalOpenAiApiKey": "your-openai-api-key" }}