Halaman ini menjelaskan cara mengupload dan mengelola produk secara terprogram. Dengan menggunakan Merchant Products API, Anda dapat menyisipkan atau memperbarui produk di sumber data, mengambil produk dari akun, dan menghapus produk dari sumber data.
Merchant Products API berisi dua resource.
productInputs
mewakili bagian input produk Anda.products
mewakili produk yang diproses yang dibuat dari bagian input Anda.
productInputs
dapat berupa utama dan tambahan, bergantung pada apakah data tersebut
diupload ke
sumber data utama
atau
sumber data tambahan.
Setiap product
akan dibuat dari satu productInput
utama dan sejumlah
productInputs
tambahan.
Anda dapat menggunakan Merchant Products API untuk membuat katalog toko lokal atau
online, yaitu produk yang dapat muncul di
beberapa tujuan belanja.
Anda dapat menggunakan resource productInputs
setelah membuat akun Merchant Center, menyiapkan sumber data pertama, dan siap mengupload kumpulan produk awal melalui API.
Meskipun penjual memiliki kemampuan untuk mengupload produk menggunakan file yang disebut PrimaryProductDataSource, ada beberapa keuntungan dalam membuat dan menghapus produk menggunakan Merchant API. Keuntungan ini mencakup waktu respons yang lebih cepat dan kemampuan untuk mengupdate produk secara real time, tanpa perlu mengelola file besar. Mungkin perlu waktu hingga beberapa jam agar perubahan produk yang dilakukan oleh panggilan API ditampilkan di database Shopping.
Prasyarat
Jika Anda tidak memiliki sumber data, buat sumber data menggunakan Merchant Data Sources API atau Merchant Center.
Jika sudah memiliki sumber data yang dibuat menggunakan UI Merchant Center atau menggunakan API, Anda dapat menggunakan Merchant Products API untuk menambahkan produk. Jika Anda menggunakan Content API for Shopping untuk menambahkan produk, lihat panduan migrasi untuk memahami cara memulai dengan Merchant Products API.
Anda bertanggung jawab untuk mematuhi kebijakan Iklan Shopping dan listingan gratis. Iklan Shopping berhak menerapkan kebijakan ini dan merespons dengan tepat jika kami menemukan konten atau perilaku yang melanggar kebijakan ini.
Resource
Resource products
memungkinkan Anda mengambil informasi produk dari database Shopping.
Resource
productInput
merepresentasikan data input yang Anda kirimkan untuk produk. API ini juga menyediakan
metode yang memungkinkan Anda memperbarui, atau menghapus informasi produk satu per satu, atau
banyak sekaligus dalam mode batch. Resource
productInput
harus memiliki kolom berikut:
channel
: Saluran produk.offerId
: ID unik untuk produk.contentLanguage
: Kode bahasa ISO 639-1 dua huruf untuk produk.feedLabel
: Label yang memungkinkan Anda mengategorikan dan mengidentifikasi produk. Karakter maksimum yang diizinkan adalah 20 dan karakter yang didukung adalahA-Z
,0-9
, tanda hubung, dan garis bawah. Label feed tidak boleh menyertakan spasi. Untuk mengetahui informasi selengkapnya, lihat Menggunakan label feed.
Mengupload input produk ke akun Anda
Untuk mengupload input produk ke akun Anda, gunakan metode accounts.productInputs.insert
. Anda harus meneruskan
ID unik sumber data utama atau tambahan.
Contoh permintaan berikut menunjukkan cara menggunakan
metode accounts.productInputs.insert
untuk mengupload input produk ke
akun penjual Anda. Permintaan menetapkan harga dan wilayah pengiriman, serta atribut kustom seperti tanggal pembuatan dan ukuran.
POST https://merchantapi.googleapis.com/products/v1beta/accounts/{ACCOUNT_ID}/productInputs:insert?dataSource={DATASOURCE}
{
"name": "{PRODUCT_TITLE}",
"versionNumber": {VERSION_NUMBER},
"contentLanguage": "{CONTENT_LANGUAGE}",
"feedLabel": "{FEED_LABEL}",
"offerId": "{OFFER_ID}",
"channel": "ONLINE",
"attributes": {
"availability": "in stock",
"imageLink": "{IMAGE_LINK}",
"link": "{PRODUCT_LINK}",
"brand": "{BRAND_NAME}",
"price": {
"currencyCode": "{CURRENCY_CODE}",
"amountMicros": {PRICE}
},
"color": "red",
"productWeight": {
"value": 320,
"unit": "g"
},
"adult": false,
"shipping": [
{
"country": "GB",
"price": {
"amountMicros": {SHIPPING_COST},
"currencyCode": "{CURRENCY_CODE_SHIPPING}"
},
"postalCode": "{SHIPPING_POSTALCODE}",
"service": "",
"region": "{SHIPPING_REGION}",
"maxHandlingTime": "{MAX_HANDLING_TIME}",
"minHandlingTime": "{MIN_HANDLING_TIME}",
"maxTransitTime": "{MAX_TRANSIT_TIME}",
"minTransitTime": "{MIN_TRANSIT_TIME}"
}
],
"gender": "Female"
},
"customAttributes": [
{
"name": "size",
"value": "Large"
},
{
"name": "Date of Manufacturing",
"value": "2024-05-05"
}
]
}
Ganti kode berikut:
- {ACCOUNT_ID}: ID unik akun Merchant Center Anda.
- {DATASOURCE}: ID unik sumber data. URL harus dalam format
accounts/
{ACCOUNT_ID}/dataSources/
{DATASOURCE_ID}. - {PRODUCT_TITLE}: Nama produk.
- {VERSION_NUMBER}: Nomor versi produk. Opsional.
- {CONTENT_LANGUAGE}: Kode bahasa ISO 639-1 dua huruf untuk produk. Wajib.
- {FEED_LABEL}: Label yang memungkinkan Anda mengategorikan
dan mengidentifikasi produk. Karakter maksimum yang diizinkan adalah 20 dan
karakter yang didukung adalah
A-Z
,0-9
, tanda hubung, dan garis bawah. Label feed tidak boleh menyertakan spasi. - {OFFER_ID}: ID unik produk. Wajib.
- {IMAGE_LINK}: Link ke gambar produk di situs Anda. Opsional.
- {PRODUCT_LINK}: Link ke produk di situs Anda. Opsional.
- {CURRENCY_CODE}: Mata uang harga menggunakan akronim tiga huruf sesuai dengan ISO 4217. Opsional.
- {PRICE}: Harga produk yang direpresentasikan sebagai angka dalam micros. Opsional.
- {SHIPPING_COST}: Harga pengiriman tetap yang direpresentasikan sebagai angka. Opsional.
- {SHIPPING_POSTALCODE}: Rentang kode pos tempat tarif pengiriman berlaku. Opsional.
- {MAX_HANDLING_TIME}: Waktu pemrosesan maksimum dalam hari kerja antara saat pesanan diterima dan saat dikirim. Opsional.
- {MIN_HANDLING_TIME}: Waktu pemrosesan minimum dalam hari kerja antara saat pesanan diterima dan saat dikirim. Nilai 0 berarti pesanan dikirim pada hari yang sama dengan hari penerimaan. Opsional.
- {MAX_TRANSIT_TIME}: Waktu transit maksimum dalam hari kerja antara saat pesanan dikirim dan saat pesanan dikirimkan. Opsional.
- {MIN_TRANSIT_TIME}: Waktu transit minimum dalam hari kerja antara saat pesanan dikirim dan saat pesanan diterima. Nilai 0 berarti pesanan dikirim pada hari yang sama dengan hari pengiriman. Opsional.
Jika permintaan berhasil berjalan, Anda akan melihat respons berikut:
{
"name": "{PRODUCT_NAME}",
"product": "{PRODUCT_ID}",
"channel": "ONLINE",
"offerId": "{OFFER_ID}",
"contentLanguage": "{CONTENT_LANGUAGE}",
"feedLabel": "{FEED_LABEL}",
"versionNumber": "{VERSION_NUMBER}",
"attributes": {
"link": "{PRODUCT_LINK}",
"imageLink": "{IMAGE_LINK}",
"adult": false,
"availability": "in stock",
"brand": "{BRAND_NAME}",
"color": "red",
"gender": "Female",
"price": {
"amountMicros": "{PRICE}",
"currencyCode": "{CURRENCY_CODE}"
},
"shipping": [
{
"price": {
"amountMicros": "{SHIPPING_COST}",
"currencyCode": "{CURRENCY_CODE}"
},
"country": "{SHIPPING_COUNTRY}",
"region": "{SHIPPING_REGION}",
"postalCode": "{SHIPPING_POSTALCODE}",
"minHandlingTime": "{MIN_HANDLING_TIME}",
"maxHandlingTime": "{MAX_HANDLING_TIME}",
"minTransitTime": "{MIN_TRANSIT_TIME}",
"maxTransitTime": "{MAX_TRANSIT_TIME}"
}
],
"productWeight": {
"value": 320,
"unit": "g"
}
},
"customAttributes": [
{
"name": "Size",
"value": "Large"
},
{
"name": "Date of Manufacturing",
"value": "2024-05-05"
}
]
}
Untuk menambahkan produk ke akun Merchant Center, Anda dapat menggunakan metode
google.shopping.merchant.accounts.v1beta.InsertProductInputSample
, seperti yang ditunjukkan dalam contoh berikut.
Java
public static void insertProductInput(Config config, String dataSource) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
ProductInputsServiceSettings productInputsServiceSettings =
ProductInputsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Creates parent to identify where to insert the product.
String parent = getParent(config.getAccountId().toString());
// Calls the API and catches and prints any network failures/errors.
try (ProductInputsServiceClient productInputsServiceClient =
ProductInputsServiceClient.create(productInputsServiceSettings)) {
// Price to be used for shipping ($33.45).
Price price = Price.newBuilder().setAmountMicros(33_450_000).setCurrencyCode("USD").build();
Shipping shipping =
Shipping.newBuilder()
.setPrice(price)
.setCountry("GB")
.setService("1st class post")
.build();
Shipping shipping2 =
Shipping.newBuilder()
.setPrice(price)
.setCountry("FR")
.setService("1st class post")
.build();
Attributes attributes =
Attributes.newBuilder()
.setTitle("A Tale of Two Cities")
.setDescription("A classic novel about the French Revolution")
.setLink("https://exampleWebsite.com/tale-of-two-cities.html")
.setImageLink("https://exampleWebsite.com/tale-of-two-cities.jpg")
.setAvailability("in stock")
.setCondition("new")
.setGoogleProductCategory("Media > Books")
.setGtin(0, "9780007350896")
.addShipping(shipping)
.addShipping(shipping2)
.build();
// The datasource can be either a primary or supplemental datasource.
InsertProductInputRequest request =
InsertProductInputRequest.newBuilder()
.setParent(parent)
// You can only insert products into datasource types of Input "API" and "FILE", and
// of Type "Primary" or "Supplemental."
// This field takes the `name` field of the datasource.
.setDataSource(dataSource)
// If this product is already owned by another datasource, when re-inserting, the
// new datasource will take ownership of the product.
.setProductInput(
ProductInput.newBuilder()
.setChannel(ChannelEnum.ONLINE)
.setContentLanguage("en")
.setFeedLabel("label")
.setOfferId("sku123")
.setAttributes(attributes)
.build())
.build();
System.out.println("Sending insert ProductInput request");
ProductInput response = productInputsServiceClient.insertProductInput(request);
System.out.println("Inserted ProductInput Name below");
// The last part of the product name will be the product ID assigned to a product by Google.
// Product ID has the format `channel~contentLanguage~feedLabel~offerId`
System.out.println(response.getName());
System.out.println("Inserted Product Name below");
System.out.println(response.getProduct());
} catch (Exception e) {
System.out.println(e);
}
}
Mengambil produk yang telah diproses dari akun Anda
Untuk mengambil produk yang diproses dari akun Anda, gunakan metode
accounts.products.get
. Diperlukan waktu beberapa menit agar produk yang diproses muncul setelah penyisipan.
GET https://merchantapi.googleapis.com/products/v1beta/accounts/{ACCOUNT_ID}/products/{PRODUCT_NAME}
Ganti {PRODUCT_NAME} dengan nama resource input produk
yang ingin Anda hapus. Misalnya, online~en~US~sku123
.
Anda bisa mendapatkan nama resource produk yang diproses dari kolom product
dalam
respons accounts.productInputs.insert
.
Untuk mengambil satu produk untuk akun Merchant Center tertentu, Anda dapat menggunakan metode
google.shopping.merchant.accounts.v1beta.GetProductRequest
, seperti yang ditunjukkan dalam contoh berikut.
Java
public static void getProduct(Config config, String product) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
ProductsServiceSettings productsServiceSettings =
ProductsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Calls the API and catches and prints any network failures/errors.
try (ProductsServiceClient productsServiceClient =
ProductsServiceClient.create(productsServiceSettings)) {
// The name has the format: accounts/{account}/products/{productId}
GetProductRequest request = GetProductRequest.newBuilder().setName(product).build();
System.out.println("Sending get product request:");
Product response = productsServiceClient.getProduct(request);
System.out.println("Retrieved Product below");
System.out.println(response);
} catch (Exception e) {
System.out.println(e);
}
}
Menghapus input produk dari akun Anda
Untuk menghapus input produk dari akun Anda, gunakan
metode accounts.productInputs.delete
. Anda harus meneruskan
ID unik sumber data utama atau tambahan tempat produk
tersebut berada untuk menghapus produk menggunakan Merchant Products API.
Permintaan berikut menunjukkan cara menggunakan metode accounts.productInputs.delete
untuk menghapus input produk:
DELETE https://merchantapi.googleapis.com/products/v1beta/accounts/{ACCOUNT_ID}/productInputs/{PRODUCT_NAME}?dataSource=accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}
Ganti {PRODUCT_NAME} dengan nama resource input produk
yang ingin Anda hapus. Misalnya, online~en~US~sku123
.
Untuk menghapus produk untuk akun Merchant Center tertentu, Anda dapat menggunakan metode
google.shopping.merchant.accounts.v1beta.DeleteProductInputRequest
, seperti yang ditunjukkan dalam contoh berikut.
Java
public static void deleteProductInput(Config config, String productId, String dataSource)
throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
ProductInputsServiceSettings productInputsServiceSettings =
ProductInputsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Creates product name to identify product.
String name =
ProductInputName.newBuilder()
.setAccount(config.getAccountId().toString())
.setProductinput(productId)
.build()
.toString();
// Calls the API and catches and prints any network failures/errors.
try (ProductInputsServiceClient productInputsServiceClient =
ProductInputsServiceClient.create(productInputsServiceSettings)) {
DeleteProductInputRequest request =
DeleteProductInputRequest.newBuilder().setName(name).setDataSource(dataSource).build();
System.out.println("Sending deleteProductInput request");
productInputsServiceClient.deleteProductInput(request); // no response returned on success
System.out.println(
"Delete successful, note that it may take a few minutes for the delete to update in"
+ " the system. If you make a products.get or products.list request before a few"
+ " minutes have passed, the old product data may be returned.");
} catch (Exception e) {
System.out.println(e);
}
}
Mencantumkan produk dari akun Anda
Untuk mencantumkan produk yang diproses di akun Anda, gunakan metode accounts.products.list
, seperti yang ditunjukkan dalam permintaan berikut.
GET https://merchantapi.googleapis.com/products/v1beta/accounts/{ACCOUNT_ID}/products
Untuk mencantumkan produk untuk akun Merchant Center tertentu, Anda dapat menggunakan metode
google.shopping.merchant.accounts.v1beta.ListProductsRequest
, seperti yang ditunjukkan dalam contoh berikut.
Java
public static void listProducts(Config config) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
ProductsServiceSettings productsServiceSettings =
ProductsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Creates parent to identify the account from which to list all products.
String parent = getParent(config.getAccountId().toString());
// Calls the API and catches and prints any network failures/errors.
try (ProductsServiceClient productsServiceClient =
ProductsServiceClient.create(productsServiceSettings)) {
// The parent has the format: accounts/{account}
ListProductsRequest request = ListProductsRequest.newBuilder().setParent(parent).build();
System.out.println("Sending list products request:");
ListProductsPagedResponse response = productsServiceClient.listProducts(request);
int count = 0;
// Iterates over all rows in all pages and prints the datasource in each row.
// Automatically uses the `nextPageToken` if returned to fetch all pages of data.
for (Product product : response.iterateAll()) {
System.out.println(product); // The product includes the `productStatus` field
// That shows approval and disapproval information.
count++;
}
System.out.print("The following count of products were returned: ");
System.out.println(count);
} catch (Exception e) {
System.out.println("An error has occured: ");
System.out.println(e);
}
}