How to Publish Products on Google Merchant Center Using Content API
If you want to automate product uploads or sync your product catalog from your website or app directly to Google Merchant Center, this guide will walk you through the entire process — from setting up your Google Cloud project to running a Django management command to upload your products.
Step 1: Create & Configure Your Google Merchant Center Account
-
Visit Google Merchant Center and sign in with your Google account.
-
Follow prompts to set up your Merchant Center account by adding your business details.
-
Add and verify your website domain under Business information > Website.
-
Make sure your website domain matches the URLs you plan to upload in your product feed.
Step 2: Enable Content API for Shopping in Google Cloud Console
To programmatically upload products, you need to enable the Content API.
-
Go to Google Cloud Console.
-
Select your existing project or create a new project.
-
From the left menu, click APIs & Services > Library.
-
Search for Content API for Shopping.
-
Click Enable to activate the API for your project.
Step 3: Create a Service Account and Download Credentials
-
In Google Cloud Console, go to APIs & Services > Credentials.
-
Click Create Credentials > Service account.
-
Fill in service account name and description, then click Create.
-
Assign Editor role (or the minimal role needed) and click Continue.
-
Skip granting users access, then click Done.
-
Click on your newly created service account.
-
Under Keys, click Add Key > Create new key.
-
Choose JSON format and download the file.
-
Save this file securely in your Django project folder (e.g.,
blog/management/commands/service-account-file.json).
Step 4: Get Your Google Merchant ID
-
Go to your Google Merchant Center account.
-
Your Merchant ID is displayed in the upper-right corner of the dashboard.
-
Note it down; you'll use this ID in your Django command.
Step 5: Grant Service Account Access to Your Merchant Center Account
The service account email looks like:
merchant-sync@your-project-id.iam.gserviceaccount.com
-
Go to Google Merchant Center.
-
Click on the gear ⚙️ icon > Account access.
-
Click Add users.
-
Enter the service account email.
-
Assign Admin role.
-
Click Add user.
This allows your service account to manage products in your Merchant Center.
Step 6: Prepare Your Django Project with the Sync Script
Create a management command sync_articles.py inside your Django app (blog/management/commands/sync_articles.py) with the following code:
from django.core.management.base import BaseCommand
from django.utils.html import strip_tags
from google.oauth2 import service_account
from googleapiclient.discovery import build
from blog.models import Article
import os
class Command(BaseCommand):
help = 'Sync articles with Google Merchant Center'
MERCHANT_ID = 'YOUR_MERCHANT_ID' # Replace with your actual Merchant ID
BASE_URL = 'https://yourdomain.com' # Replace with your actual website URL
def get_google_service(self):
scopes = ['https://www.googleapis.com/auth/content']
key_path = os.path.join('blog', 'management', 'commands', 'service-account-file.json')
credentials = service_account.Credentials.from_service_account_file(
key_path, scopes=scopes
)
return build('content', 'v2.1', credentials=credentials)
def format_article_data(self, article):
base_url = self.BASE_URL.rstrip('/')
return {
'offerId': str(article.id),
'title': article.article_title_h1,
'description': strip_tags(article.meta_description or article.description),
'link': f"{base_url}{article.get_absolute_url()}",
'imageLink': f"{base_url}{article.image.url}" if article.image else '',
'contentLanguage': 'en',
'targetCountry': 'IN',
'channel': 'online',
'availability': 'in stock',
'condition': 'new',
'price': {
'value': '10.00', # Must be > 0
'currency': 'INR'
},
'shipping': [
{
'country': 'IN',
'service': 'Standard shipping',
'price': {
'value': '0.00',
'currency': 'INR'
}
}
],
'identifierExists': False,
}
def handle(self, *args, **kwargs):
service = self.get_google_service()
articles = Article.objects.filter(show_status=True)
for article in articles:
self.stdout.write(f"Processing Article ID {article.id}: {article.article_title_h1}")
product_data = self.format_article_data(article)
try:
response = service.products().insert(
merchantId=self.MERCHANT_ID,
body=product_data
).execute()
self.stdout.write(self.style.SUCCESS(
f"✅ Uploaded Article ID {article.id}: {article.article_title_h1}"
))
except Exception as e:
self.stderr.write(f"❌ Error uploading Article ID {article.id}: {e}")
-
Replace
'YOUR_MERCHANT_ID'with your Merchant ID. -
Replace
'https://yourdomain.com'with your website URL. -
Put your service account JSON file in the specified folder.
Step 7: Run the Sync Script
-
Activate your Django environment.
-
Run the management command:
python manage.py sync_articles
-
The script will iterate through your
Articleobjects and upload them as products to Google Merchant Center. -
Check your Merchant Center dashboard to verify the products appeared.
Step 8: Troubleshooting Tips
-
401 Unauthorized errors usually mean your service account doesn't have permission — double-check Step 5.
-
Ensure the URLs in the product data exactly match your verified domain.
-
Prices must be greater than 0, or Google will reject products.
-
Wait for initial Google review (up to 3 business days) before your products fully show.
Conclusion
Using the Content API and a service account is a powerful way to automate product management on Google Merchant Center. This helps keep your product feed always up-to-date without manual CSV uploads.
0 Comments