Complete Guide to Google Merchant API Authorization for Shopify Apps
Watch Video Tutorial
Introduction
Setting up Google Merchant API authorization can seem daunting, especially if you're new to Google Cloud Platform (GCP). This comprehensive guide will walk you through every step, from creating a service account to successfully authenticating your Shopify app with the Merchant API.
What you'll learn:
- How to create and configure a Google Cloud service account
- Two different authentication methods (with and without key files)
- How to register your GCP project with Merchant Center
- Common troubleshooting steps
Prerequisites:
- A Google Cloud Platform account
- A Google Merchant Center account
- Basic understanding of command line operations
- Node.js installed on your computer
Step 1: Create a Google Cloud Service Account
1.1 Access Google Cloud Console
- Go to Google Cloud Console
- Select your project (or create a new one)
- Navigate to IAM & Admin -> Service Accounts
1.2 Create New Service Account
- Click "Create Service Account"
- Enter a descriptive name (e.g.,
shopify-merchant-api) - Add description:
Service account for Shopify app Merchant API access - Click "Create and Continue"
1.3 Assign Roles
- In the "Grant this service account access to project" section
- Add the following roles:
- Editor (for general project access)
- Service Account User (for authentication)
- Click "Continue" then "Done"
Step 2: Add Service Account to Merchant Center (Recommended Method)
This is the easiest and most secure approach. No key files needed!
2.1 Get Your Service Account Email
- In Google Cloud Console, go to Service Accounts
- Find your newly created service account
- Copy the email address (it looks like:
your-service-account@your-project.iam.gserviceaccount.com)
2.2 Add to Merchant Center
- Go to Google Merchant Center
- Navigate to Settings -> Account access -> Users
- Click "Add User"
- Enter your service account email
- Select "Admin" role
- Click "Save"
Important: Wait 5-10 minutes for permissions to propagate.
Step 3: Install Required Dependencies
Create a new directory for your project and install the necessary packages:
mkdir merchant-api-auth
cd merchant-api-auth
npm init -y
npm install google-auth-library axios
Step 4: Create the Registration Script
Create a file called register-gcp-developer.js:
const { GoogleAuth } = require('google-auth-library');
const axios = require('axios');
// Configuration
const MERCHANT_ID = 'YOUR_MERCHANT_ID'; // Replace with your Merchant Center ID
const DEVELOPER_EMAIL = 'your-email@gmail.com'; // Replace with your email
const GCP_PROJECT_ID = 'your-project-id'; // Replace with your GCP project ID
async function registerGcpDeveloper() {
try {
console.log('🔐 Authenticating with Google Cloud...');
// Initialize Google Auth
const auth = new GoogleAuth({
scopes: ['[https://www.googleapis.com/auth/content](https://www.googleapis.com/auth/content)'],
});
// Get authenticated client
const authClient = await auth.getClient();
console.log('✅ Authentication successful');
console.log('📡 Registering GCP project with Merchant Center...');
// Prepare API request
const url = `https://merchantapi.googleapis.com/accounts/v1beta/accounts/${MERCHANT_ID}/developerRegistration:registerGcp`;
const requestBody = {
developerEmail: DEVELOPER_EMAIL
};
// Make API request
const response = await authClient.request({
url: url,
method: 'POST',
data: requestBody,
});
console.log('✅ Registration successful!');
console.log('📋 Response:', JSON.stringify(response.data, null, 2));
console.log('\n>>> Your Shopify app can now access Merchant API! <<<');
} catch (error) {
console.error('❌ Registration failed:', error.message);
if (error.response) {
console.error('📋 Error details:', JSON.stringify(error.response.data, null, 2));
}
}
}
// Run the registration
registerGcpDeveloper();
Step 5: Authenticate and Run the Script
Method 1: Using gcloud CLI (Recommended)
- Install Google Cloud CLI:
- Download from: https://cloud.google.com/sdk/docs/install
- Follow installation instructions for your operating system
- Authenticate:
gcloud auth application-default login
This will open a browser window for authentication.
- Run the script:
node register-gcp-developer.js
Method 2: Using Service Account Key File (Fallback)
If Method 1 doesn't work, use this approach:
- Download Service Account Key:
- Go to Google Cloud Console -> Service Accounts
- Click on your service account
- Go to Keys tab -> Add Key -> Create New Key
- Choose JSON format and download
- Place the key file:
- Rename the downloaded file to
service-account-key.json - Place it in your project directory
- Rename the downloaded file to
- Update your script:Add this line at the top of your script:
process.env.GOOGLE_APPLICATION_CREDENTIALS = './service-account-key.json';
- Run the script:
node register-gcp-developer.js
Step 6: Verify Success
When successful, you should see output like:
✅ Registration successful!
📋 Response: {
"name": "accounts/YOUR_MERCHANT_ID/developerRegistration",
"gcpIds": [
"YOUR_GCP_PROJECT_NUMBER"
]
}
Troubleshooting Common Issues
Issue 1: "Request had insufficient authentication scopes"
Solution: Ensure your service account has the correct roles and is added to Merchant Center as an Admin user.
Issue 2: "The caller does not have access to the accounts"
Solution:
- Verify the service account email is added to Merchant Center
- Wait 5-10 minutes for permissions to propagate
- Ensure you're using the correct Merchant ID
Issue 3: "gcloud command not found"
Solution:
- Install Google Cloud CLI properly
- Restart your terminal/command prompt
- Use Method 2 (key file) as an alternative
Issue 4: "Authentication failed"
Solution:
- Run
gcloud auth application-default loginagain - Ensure you're logged in with the correct Google account
- Check that your service account has proper roles
Security Best Practices
- Never commit key files to version control
- Add
service-account-key.jsonto your.gitignore
- Add
- Use environment variables in production:
const MERCHANT_ID = process.env.MERCHANT_ID;
const DEVELOPER_EMAIL = process.env.DEVELOPER_EMAIL;
- Regularly rotate service account keys
- Delete old keys after creating new ones
- Use least privilege principle
- Only grant necessary permissions to service accounts
Next Steps
Once registration is complete, you can:
- Start making Merchant API calls from your Shopify app
- Implement product feed management
- Set up automated inventory synchronization
- Build custom reporting dashboards
Conclusion
Setting up Google Merchant API authorization might seem complex initially, but following this step-by-step guide ensures a smooth setup process. The key is properly configuring your service account and adding it to Merchant Center with appropriate permissions.
Remember: Method 1 (using gcloud CLI) is more secure and easier to maintain than Method 2 (key files). Always prefer the CLI approach when possible.
.jpg)
