Hi community,
I’m running a python script that writes blog posts for my store using OpenAI. The script is producing the blog posts and is pulling relevant products from my store. However, I’m getting this error message that prevents the blogs from posting:
Error creating blog post:
- can’t be blank
Full error details:
Field ‘base’ - can’t be blank
I cannot find the base field it mentions in the shopify api language. Any ideas? below is the relevant part of the code:
Generate the blog content
blog_content = generate_blog_content(prompt)
def generate_blog_title(keyword):
primed_title_prompt = f"Create an engaging and SEO-optimized blog title about {keyword}:"
response = openai.Completion.create(
engine=“text-davinci-002”,
prompt=primed_title_prompt,
max_tokens=20,
temperature=0.7,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
return response.choices[0].text.strip()
post_title = generate_blog_title(selected_keyword)
Post-process the generated content: add subheadings, meta description, and image alt tags
Extract keywords from the content using SpaCy
… (rest of the code)
Post-process the generated content: add subheadings, meta description, and image alt tags
Extract keywords from the content using SpaCy
doc = nlp(blog_content)
extracted_keywords = [token.lemma_ for token in doc if token.is_alpha and not token.is_stop]
extracted_keywords = list(set(extracted_keywords))
Add subheadings using extracted keywords
subheadings = random.sample(extracted_keywords, min(3, len(extracted_keywords)))
for subheading in subheadings:
blog_content = blog_content.replace(subheading, f’
{subheading.capitalize()}
', 1)post_content = f"
{blog_content}
"Create a blog post on Shopify
import requests
import random
product_images = [
{“url”: “https://www.example.com/image1.jpg”, “tags”: [“ethical alternatives”]},
Add more product images with their corresponding tags
]
def get_random_image():
return random.choice(product_images)[“url”]
def get_relevant_product_image(tags):
relevant_images = [img for img in product_images if any(tag in img[“tags”] for tag in tags)]
if not relevant_images:
return get_random_image()
return random.choice(relevant_images)[“url”]
Replace the placeholder functions in your previous code with these functions
Extract the first paragraph as an excerpt and search engine listing preview
first_paragraph = post_content.split(‘
’)[0] + ‘’image_url = get_relevant_product_image(selected_keyword.split())
print(“post_title:”, post_title)
print(“post_content:”, post_content)
print(“selected_keyword:”, selected_keyword)
print(“image_url:”, image_url)
print(“first_paragraph:”, first_paragraph)
new_post = {
“article”: {
“title”: post_title,
“author”: “Thomas Lawrence”,
“blog_id”: removedbutthispartis,
“tags”: selected_keyword,
}
}
print(new_post) # Add this line
with shopify.Session.temp(shop_url, ‘2023-01’, password):
post = shopify.Article.create(new_post)
print(“Shopify API response:”, post.to_dict()) # Add this line to print the Shopify API response
if post.is_valid():
print(f"Successfully created blog post: {post_title}“)
else:
print(“Error creating blog post:”)
for error in post.errors.full_messages():
print(f”- {error}“)
print(“Full error details:”)
for field, error_list in post.errors.errors.items():
for error in error_list:
print(f"Field ‘{field}’ - {error}”)