App reviews, troubleshooting, and recommendations
I'm trying to run a code which writes blog content for my online store using open AI. It's close to working but I'm getting this error when the code attempts to post the generated blogs:
- can't be blank
Full error details:
Field 'base' - can't be blank
Does anybody know what field 'base' is? The shopify API credentials appear to be correct as I'm able to pull relevant products from my store to include in the blogs. I'm pretty certain the blog ID is correct too.
Here's the relevant piece of code I've been using:
# 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'<h2>{subheading.capitalize()}</h2>', 1)
post_content = f"<p>{blog_content}</p>"
# 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('</p>')[0] + '</p>'
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": myblogidisherebutiveremoved,
"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}")
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024