Update Google Merchant Center Products through API calls

Prerequiste

  • add JWT token to service account
  • add service account to Merchant API user
  • set the service account as developer
  • In Google Cloud Console enable Content API for Shopping for the project that owns the service account. Google for Developers
  • In Merchant Center, get the numeric merchantId shown in the Merchant Center settings (you’ll pass this to API calls). Google for Developers

Create simple Node project

mkdir gmc-content-demo && cd gmc-content-demo
npm init -y
npm install googleapis google-auth-library @google-shopping/products

Put your service account JSON somewhere safe

Save your downloaded JSON key file as service-account.json (or set path via env var). Never commit it to source control.

Create insert-product.js file

// insert-product-input.js
'use strict';

const path = require('path');
const { GoogleAuth } = require('google-auth-library');
const { ProductInputsServiceClient } = require('@google-shopping/products').v1;

async function main() {
  const merchantId = 'MERCHANT_ID';           // e.g. "123456789"
  const dataSourceId = 'DATA_SOURCE_ID';       // feed/data source ID
  const offerId = 'sku-12345';
  const productId = `en~online~${offerId}`;        // language~label~offerId

  // Full resource name for product input
  const productInputName = `accounts/${merchantId}/productInputs/${productId}`;

  // Authenticate
  const auth = new GoogleAuth({
    keyFile: path.join(__dirname, 'service-account.json'),
    scopes: ['https://www.googleapis.com/auth/content']
  });

  const authClient = await auth.getClient();

  // Create client
  const client = new ProductInputsServiceClient({ authClient });

  // Product attributes
  const productAttributes = {
    title: "New Jacket Product (Inserted via API)",
    description: "A stylish jacket added using ProductInputsServiceClient.",
    link: "https://example.com/jacket",
    imageLink: "https://example.com/jacket.jpg",
    availability: "IN_STOCK",
    condition: "NEW",
    price: { amountMicros: 49900000, currencyCode: "USD" },
    gtin: ["9780007350896"],
    brand: "MyBrand"
  };


  // Build productInput 
  const productInput = {
    name: productInputName,
    contentLanguage: 'en',
    offerId: "irrestistible-offer-12345",
    feedLabel: 'GB', // Check the feed label of the data source in the Merchant API account
    productAttributes
  };

  try {
    console.log("Inserting ProductInput…");

    const dataSource = `accounts/${merchantId}/dataSources/${dataSourceId}`;
    const parent = `accounts/${merchantId}`;

    const [response] = await client.insertProductInput({
      parent,
      dataSource,
      productInput
    });

    console.log("Product inserted successfully:");
    console.log(JSON.stringify(response, null, 2));

  } catch (err) {
    console.error("Insert failed:", err);
  } finally {
    if (client.close) await client.close();
  }
}

main().catch(err => {
  console.error("Fatal error", err);
});

Other examples

https://developers.google.com/merchant/api/samples/insert-product-input#node.js

Use dotenv in playwright node.js server

In order for dotenv to work, you need to add import “dotenv/config“; in playwright.config.js

Then in your test script import * as dotenv from 'dotenv'; in example.spec.ts

to call the environment variables:
const API_USER_ID: string = process.env.API_USER_ID || 'user_api';
const API_USER_PASSWORD: string = process.env.API_USER_PASSWORD || 'xyz-123';

Create .env with your environment variables:
USER_ID = user_api
API_USER_PASSWORD = xyz-123

Manage Meta product catalogue through API calls

  1. Create a Meta business portfolio
  2. Under Data sources, add a catalogue (click on the Add+ button)

3. Create a Facebook application

https://developers.facebook.com/docs/development/create-an-app

You will need to give it the Manage products with Catalog API use case.

4. Add this application to your Business portfolio

5. Create a system users and give the system users access to both the application and the catalogue. This user will be required to get the access token for your app.

6. generate a token https://developers.facebook.com/docs/news-indexing/guides/access-tokens/

7. Install the SDK

8. use the token and the app id to make query to you application

Google Merchant Center test account

How to manage your product feed for google adds through API.

Google ads account -> test account
Google Merchant account -> test account

Set Google API access

Navigate to console.cloud.google.com and create a new project

Click on API & Services

In library, look for Merchant API

Click on the Merchant API result and then click on the Enable button

Create Credentials

Click on Credentials > create credentials

Click on Help me choose

Select Merchant API and User Data

Click on Next

Add A scope: search for Merchant API and tick the box

Click on save and continue
in OAuth choose Web application

Add Authorized redirect URI for the postman application: https://oauth.pstmn.io/v1/callback

(you can add serveral URI)

Click on Create
On the next sceen click on Download your credentials and then click on done.

Add test users in google cloud API

in google cloud, navigate to audience and then scroll down to add users.

Add developers in Merchant Account

in Merchant Center, add a user in Setting > Access and services > add person (or manage an existing user) untick admin and make sure to to tick API developer.

Alternatively you can do that though API call

Set up postman

You can follow the steps here https://quickstarts.postman.com/guide/google-oauth-in-postman/index.html?#3 but you’ll need to change the scope for the appropriate scope for the Merchant API. Scopes can be found here:

https://developers.google.com/identity/protocols/oauth2/scopes

Look for merchant API


Install a python library in python virtual environment venv: Could not install packages due to an OSError: [WinError 2] The system cannot find the file specified

Error: When running pip install in venv, on Windows 10, the following error is displayed:

WARNING: Failed to write executable - trying to use .deleteme logic
ERROR: Could not install packages due to an OSError: [WinError 2] The system cannot find the file specified: 'C:\Python311\Scripts\google-oauthlib-tool.exe' -> 'C:\Python311\Scripts\google-oauthlib-tool.exe.deleteme'

Solution: run

py -m pip install [the package you want to install]

Script cannot be loaded because running scripts is disabled on this system. For moreinformation, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.

Error: when running the activation script for my python virtual environment, the I had the following error on Win10

Activate.ps1 cannot be loaded because running scripts is disabled on this system. For more
information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.

Solution: Open a powershell as admin and run the following command

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

hit Y and press the Enter key.

tensorflow error: internal: libdevice not found at ./libdevice.10.bc Ubuntu – Solved

Context: I got this error when running tensorflow with python on Ubuntu 20.04, after installing the cuda toolkit by choosing the local deb installation file.

Solution: the solution was to download and install the deb network file instead

https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04

Google Cloud Vision Set Up on Windows. google module not found in virutalenv

Issue:
The following error is displayed when trying to import google vision in the virtualenv after following the installation process.

Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'google'

Google cloud installation instruction:

https://cloud.google.com/python/docs/reference/vision/latest#installation

pip install virtualenv
virtualenv <your-env>
<your-env>\Scripts\activate
<your-env>\Scripts\pip.exe install google-cloud-vision

Solution:

To run python in the virtual environment, use the python command instead of python3

git returns ” is a merge but no -m option was given.”

Error:

git revert 75a690a642b71768dad36ade65839a6da62d8d6a
error: commit 75a690a642b71768dad36ade65839a6da62d8d6a is a merge but no -m option was given.
fatal: revert failed

Solution:

run the following command in the terminal:

git cat-file -p 75a690a642b71768dad36ade65839a6da62d8d6a

Output:

git cat-file -p 75a690a642b71768dad36ade65839a6da62d8d6a
tree 6ee9397d91ed42ad3d130b93c5c5587d1ad6c67c
parent 95beda2bfbfa1523cb14c1285d80a5faa9b7f6f0
parent a3e9ddabca322e52b141a001dc5eb9c2c789ff22

run

git revert 75a690a642b71768dad36ade65839a6da62d8d6a -m 1 

if you want to use the first parent as mainline, choose 1, else choose 2