Get One Blog
Get One Blog Endpoint
Section titled “Get One Blog Endpoint”Use the following endpoint to get a blog post via the API.
Endpoint
Section titled “Endpoint”GET /api/v1/public/get-blog/{blogId}Authentication
Section titled “Authentication”Include your API key in the Authorization header:
Authorization: Bearer YOUR_API_KEYCode Examples
Section titled “Code Examples”// Replace "YOUR_UNIQUE_BLOG_ID" with the actual Blog ID// Endpoint: {API_ENDPOINTS.BLOGS.GET_ONE("YOUR_UNIQUE_BLOG_ID")}fetch(`https://api.blogz.ai/api/v1/public/get-blog/YOUR_UNIQUE_BLOG_ID`, { method: 'GET', // Method is GET to retrieve data headers: { 'Authorization': `Bearer YOUR_API_KEY`, 'Content-Type': 'application/json' // Good practice, though not strictly needed for GET }}).then(response => response.json()) // Expecting JSON data for a successful GET.then(blogData => { console.log('Blog retrieved successfully:', blogData); // Use the blogData object here}).catch(error => console.error('Error retrieving blog:', error));import { Blog } from './your-types-path'; // Assuming you have a Blog type client-side
// Replace "YOUR_UNIQUE_BLOG_ID" with the actual Blog ID// Endpoint: {API_ENDPOINTS.BLOGS.GET_ONE("YOUR_UNIQUE_BLOG_ID")}const apiUrlWithId = `https://api.blogz.ai/api/v1/public/get-blog/YOUR_UNIQUE_BLOG_ID`;
fetch(apiUrlWithId, { method: 'GET', // Method is GET to retrieve data headers: { 'Authorization': `Bearer YOUR_API_KEY`, 'Content-Type': 'application/json' }}).then(async (response: Response) => { // Expecting JSON data for a successful GET return response.json() as Promise<Blog>; // Cast to your Blog type}).then((blogData: Blog) => { console.log('Blog retrieved successfully:', blogData); // Use the typed blogData object here}).catch((error: Error) => console.error('Error retrieving blog:', error));import requestsimport json
# Replace "YOUR_UNIQUE_BLOG_ID" with the actual Blog ID# Endpoint: {API_ENDPOINTS.BLOGS.GET_ONE("YOUR_UNIQUE_BLOG_ID")}api_url_with_id = "https://api.blogz.ai/api/v1/public/get-blog/YOUR_UNIQUE_BLOG_ID"api_key = "YOUR_API_KEY"
headers = { "Authorization": f"Bearer {api_key}", "Accept": "application/json" # Indicate we expect JSON back}
try: # Use requests.get to retrieve data response = requests.get(api_url_with_id, headers=headers)
# Check for successful status code (usually 200 OK for GET) if response.status_code == 200: try: # Parse the JSON response body blog_data = response.json() print("Blog retrieved successfully:") print(json.dumps(blog_data, indent=2)) # Use the blog_data dictionary here except json.JSONDecodeError: # Handle cases where response is 200 but not valid JSON (unlikely for this API) print(f"Error: Received status code 200 but failed to decode JSON response body.") print(f"Response body: {response.text}") else: # Raise an exception for bad status codes (4xx or 5xx) response.raise_for_status()
except requests.exceptions.RequestException as e: print(f"Error retrieving blog: {e}") # Print details from the response if available if e.response is not None: print(f"Status Code: {e.response.status_code}") try: # Try to print JSON error message if possible error_details = e.response.json() print("Error details:", json.dumps(error_details, indent=2)) except json.JSONDecodeError: # Fallback to text if error response is not JSON print(f"Response body: {e.response.text}")# Use GET method (default for curl if no -X is specified, but explicit is clearer)
# Replace 'your-unique-blog-id' with the actual Blog ID# Endpoint: {API_ENDPOINTS.BLOGS.GET_ONE("YOUR_UNIQUE_BLOG_ID")}curl -X GET "https://api.blogz.ai/api/v1/public/get-blog/YOUR_UNIQUE_BLOG_ID" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Accept: application/json" # Request JSON response