इस गाइड का इस्तेमाल करके, Merchant API को अपने मौजूदा Content API for Shopping के साथ इंटिग्रेट किया जा सकता है.
Merchant API की मदद से, Merchant Center में खाते, प्रॉडक्ट, और इन्वेंट्री से जुड़े मैनेजमेंट वर्कफ़्लो को अपने-आप मैनेज किया जा सकता है. Merchant API के इस्तेमाल के उदाहरणों में ये शामिल हैं:
- खाते का अपने-आप मैनेज होना
- प्रॉडक्ट का अपने-आप मैनेज होना
- ऑटोमेटेड इन्वेंट्री मैनेजमेंट
- कस्टम रिपोर्टिंग
Content API के मुकाबले बेहतर सुविधाएं
Merchant API, Content API की तुलना में इन मामलों में बेहतर है:
- आपके यूनीक इंटिग्रेशन के लिए, नई सुविधाओं वाले सब-एपीआई
- इन्वेंट्री, प्रॉडक्ट डेटा, और अन्य एपीआई के लिए नए तरीके
- न सिर्फ़ प्राइमरी डेटा सोर्स, बल्कि एक से ज़्यादा डेटा सोर्स बनाने की सुविधा, जैसे कि:
- प्रॉडक्ट की समीक्षाएं और कारोबारी/कंपनी की समीक्षाएं अपलोड करने की सुविधा जोड़ी गई
- Merchant API की मदद से, खाते के डेटा में होने वाले बदलावों के लिए सूचनाएं चालू की जा सकती हैं
अपनी प्रोफ़ाइल बनाना शुरू करें
Merchant API और इसके सब-एपीआई के बारे में जानकारी के लिए, Merchant API का डिज़ाइन देखें.
Merchant API का इस्तेमाल शुरू करने के लिए, अपने अनुरोध के यूआरएल को इस फ़ॉर्मैट में बदलें:
https://merchantapi.googleapis.com/{SUB_API}/{VERSION}/{RESOURCE_NAME}:{METHOD}…
ज़्यादा जानकारी के लिए, क्विकस्टार्ट गाइड और Merchant API का रेफ़रंस देखें.
gRPC सहायता
Merchant API, gRPC और REST के साथ काम करता है. Merchant API के लिए gRPC और Content API for Shopping के लिए REST का एक साथ इस्तेमाल किया जा सकता है.
Merchant API की क्लाइंट लाइब्रेरी के लिए, gRPC की ज़रूरत होती है.
ज़्यादा जानकारी के लिए, gRPC का इस्तेमाल करना देखें.
इनके साथ काम करता है
इस गाइड में, Merchant API के पूरे वर्शन पर लागू होने वाले सामान्य बदलावों के बारे में बताया गया है. कुछ खास सुविधाओं में हुए बदलावों के बारे में जानने के लिए, ये गाइड देखें:
- खाते के मैनेजमेंट को माइग्रेट करना
- शिपिंग की सेटिंग माइग्रेट करना
- प्रॉडक्ट मैनेजमेंट को माइग्रेट करना
- डेटा सोर्स मैनेजमेंट को माइग्रेट करना
- इन्वेंट्री मैनेजमेंट को माइग्रेट करना
- प्रमोशन मैनेजमेंट को माइग्रेट करना
- रिपोर्टिंग मैनेजमेंट को माइग्रेट करना
- कन्वर्ज़न सोर्स मैनेजमेंट को माइग्रेट करना
- Local Feeds Partnership Program (LFP) को माइग्रेट करना
Merchant API को Content API for Shopping के मौजूदा वर्शन 2.1 की सुविधाओं के साथ काम करने के लिए डिज़ाइन किया गया है.
उदाहरण के लिए, Merchant Inventories API का इस्तेमाल, Content API for Shopping के मौजूदा वर्शन 2.1 products
के साथ किया जा सकता है. Content API for Shopping का इस्तेमाल करके, नया स्थानीय प्रॉडक्ट अपलोड किया जा सकता है. यह ऐसा प्रॉडक्ट होता है जिसे स्थानीय स्टोर में बेचा जाता है. इसके बाद, उस प्रॉडक्ट के लिए स्टोर में मौजूद जानकारी को मैनेज करने के लिए, Merchant Inventories API LocalInventory
संसाधन का इस्तेमाल किया जा सकता है.
एक साथ कई अनुरोध करना
Merchant API, Content API for Shopping में दिखाए गए customBatch
तरीके के साथ काम नहीं करता. इसके बजाय, एक साथ कई अनुरोध भेजें लेख पढ़ें या कॉल को अलग-अलग समय पर चलाएं.
यहां दिए गए सैंपल में, प्रॉडक्ट इनपुट डालने का तरीका बताया गया है.
Java
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutureCallback;
import com.google.api.core.ApiFutures;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.shopping.merchant.products.v1beta.Attributes;
import com.google.shopping.merchant.products.v1beta.InsertProductInputRequest;
import com.google.shopping.merchant.products.v1beta.ProductInput;
import com.google.shopping.merchant.products.v1beta.ProductInputsServiceClient;
import com.google.shopping.merchant.products.v1beta.ProductInputsServiceSettings;
import com.google.shopping.merchant.products.v1beta.Shipping;
import com.google.shopping.type.Channel.ChannelEnum;
import com.google.shopping.type.Price;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to insert a product input */
public class InsertProductInputAsyncSample {
private static String getParent(String accountId) {
return String.format("accounts/%s", accountId);
}
private static String generateRandomString() {
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
Random random = new Random();
StringBuilder sb = new StringBuilder(8);
for (int i = 0; i < 8; i++) {
sb.append(characters.charAt(random.nextInt(characters.length())));
}
return sb.toString();
}
private static ProductInput createRandomProduct() {
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();
return ProductInput.newBuilder()
.setChannel(ChannelEnum.ONLINE)
.setContentLanguage("en")
.setFeedLabel("CH")
.setOfferId(generateRandomString())
.setAttributes(attributes)
.build();
}
public static void asyncInsertProductInput(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)) {
// Creates five insert product input requests with random product IDs.
List<InsertProductInputRequest> requests = new ArrayList<>(5);
for (int i = 0; i < 5; i++) {
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(createRandomProduct())
.build();
requests.add(request);
}
System.out.println("Sending insert product input requests");
List<ApiFuture<ProductInput>> futures =
requests.stream()
.map(
request ->
productInputsServiceClient.insertProductInputCallable().futureCall(request))
.collect(Collectors.toList());
// Creates callback to handle the responses when all are ready.
ApiFuture<List<ProductInput>> responses = ApiFutures.allAsList(futures);
ApiFutures.addCallback(
responses,
new ApiFutureCallback<List<ProductInput>>() {
@Override
public void onSuccess(List<ProductInput> results) {
System.out.println("Inserted products below");
System.out.println(results);
}
@Override
public void onFailure(Throwable throwable) {
System.out.println(throwable);
}
},
MoreExecutors.directExecutor());
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
// Identifies the data source that will own the product input.
String dataSource = "accounts/" + config.getAccountId() + "/dataSources/{datasourceId}";
asyncInsertProductInput(config, dataSource);
}
}
अगर Content API में customBatch
का इस्तेमाल किया जाता है और आपको Merchant API के लिए इस सुविधा की ज़रूरत है, तो हमें सुझाव, राय या शिकायत में इसकी वजह बताएं.
आइडेंटिफ़ायर
Google के एपीआई को बेहतर बनाने के सिद्धांतों के मुताबिक, हमने Merchant API के संसाधनों के आइडेंटिफ़ायर में कुछ बदलाव किए हैं.
नाम, आईडी की जगह ले लेता है
Merchant API के सभी संसाधन, अपने यूनीक आइडेंटिफ़ायर के तौर पर name
फ़ील्ड का इस्तेमाल करते हैं.
अपने कॉल में name
फ़ील्ड का इस्तेमाल करने का उदाहरण यहां दिया गया है:
POST https://merchantapi.googleapis.com/inventories/v1beta/{PARENT}/regionalInventories:insert
Merchant API में, सभी रीड और लिखने के कॉल के लिए, यह नया name
फ़ील्ड, संसाधन आइडेंटिफ़ायर के तौर पर दिखाया जाता है.
उदाहरण के लिए, किसी संसाधन से name
को वापस पाने के लिए getName()
तरीका लागू करें. साथ ही, व्यापारी/कंपनी और संसाधन आईडी से name
को खुद बनाने के बजाय, आउटपुट को वैरिएबल के तौर पर सेव करें.
चाइल्ड रिसॉर्स के लिए पैरंट फ़ील्ड
Merchant API में, सभी चाइल्ड रिसॉर्स में parent
फ़ील्ड होता है. पूरे पैरंट रिसॉर्स को पास करने के बजाय, parent
फ़ील्ड का इस्तेमाल करके, उस रिसॉर्स का name
तय किया जा सकता है जिसमें चाइल्ड रिसॉर्स को डालना है.
parent
के चाइल्ड रिसॉर्स की सूची बनाने के लिए, list
तरीकों के साथ parent
फ़ील्ड का भी इस्तेमाल किया जा सकता है.
उदाहरण के लिए, किसी प्रॉडक्ट की स्थानीय इन्वेंट्री की सूची बनाने के लिए, list
के तरीके के लिए, parent
फ़ील्ड में प्रॉडक्ट का name
डालें. इस मामले में, दिया गया product
, दिखाए गए LocalInventory
संसाधनों में से parent
है.
टाइप
यहां Merchant API के सब-एपीआई में शेयर किए जाने वाले कुछ सामान्य टाइप दिए गए हैं.
कीमत
Merchant Common पैकेज में Price
के लिए ये बदलाव किए गए हैं:
Content API | Merchant API | |
---|---|---|
रकम वाला फ़ील्ड | value:string |
amountMicros:int64 |
मुद्रा फ़ील्ड | currency:string
|
currencyCode:string |
Price
की रकम अब माइक्रो में रिकॉर्ड की जाती है. यहां 10 लाख माइक्रो, आपकी मुद्रा की स्टैंडर्ड यूनिट के बराबर होते हैं.
Content API for Shopping में, Price
एक दशमलव संख्या थी, जो स्ट्रिंग के तौर पर थी.
रकम वाले फ़ील्ड का नाम value
से बदलकर amountMicros
हो गया है
मुद्रा फ़ील्ड का नाम currency
से बदलकर currencyCode
हो गया है. मुद्रा का फ़ॉर्मैट ISO 4217 बना रहेगा.