استخدِم UpdateCssProductInput
لتعديل منتج واحد حالي في CSS من خلال تحديد المنتج
cssProductInput.name
ونص JSON يحتوي على البيانات التي تريد
تعديلها للمنتج.
ملاحظة: لا تعدّل هذه الطريقة سوى السمات المقدّمة في طلب تعديل المحتوى. يحتوي الردّ على السمات نفسها الواردة في الطلب ولا يعكس
الحالة الكاملة لـ CssProductInput
بعد تطبيق التعديل.
يجب عدم الاعتماد على الاستجابة لتحديد الحالة النهائية لحالة
CssProductInput
.
PATCH https://css.googleapis.com/v1/accounts/{ACCOUNT_ID}/cssProductInputs/{CSS_PRODUCT_ID}
لإضافة سمة أو تعديلها في منتج، حدِّد الحقل بالقيمة الجديدة
في نص JSON. سيؤدي المثال المعروض إلى تعديل العنوان
ورابط المنتج المعروض في العنوان
لاسم منتج حالي 123/cssProductInputs/de~DE~B019G4
باستخدام قيمة السمة التي تم تقديمها في محتوى الطلب، مع إبقاء جميع الحقول الأخرى
بدون تغيير.
HTTP
PATCH https://css.googleapis.com/v1/accounts/{ACCOUNT_ID}/cssProductInputs/{CSS_PRODUCT_ID}
{
"attributes": {
"title": "new item title",
"headlineOfferLink": "headline-offer.com"
}
}
cURL
curl --location --request PATCH 'https://css.googleapis.com/v1/accounts/{ACCOUNT_ID}/cssProductInputs/{CSS_PRODUCT_ID}' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <API_TOKEN>' \
--data '{"attributes":{"numberOfOffers":"99","headlineOfferPrice":{"currency_code":"EUR","amount_micros":"1200000"}}}'
Java
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package shopping.css.samples.v1.cssproducts;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.protobuf.FieldMask;
import com.google.shopping.css.v1.CssProductInput;
import com.google.shopping.css.v1.CssProductInputsServiceClient;
import com.google.shopping.css.v1.CssProductInputsServiceSettings;
import com.google.shopping.css.v1.UpdateCssProductInputRequest;
import shopping.css.samples.utils.Authenticator;
import shopping.css.samples.utils.Config;
/** This class demonstrates how to update a CSS Product for a given Account */
public class UpdateCssProductInput {
private static String getName(String domainId, String productId) {
return String.format("accounts/%s/cssProductInputs/%s", domainId, productId);
}
public static void updateCssProductInput(Config config, String productId) throws Exception {
GoogleCredentials credential = new Authenticator().authenticate();
String name = getName(config.getDomainId().toString(), productId);
CssProductInputsServiceSettings cssProductInputsServiceSettings =
CssProductInputsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
try (CssProductInputsServiceClient cssProductInputsServiceClient =
CssProductInputsServiceClient.create(cssProductInputsServiceSettings)) {
// Updates the title of the CSS Product leaving the rest of the fields unchanged
UpdateCssProductInputRequest request =
UpdateCssProductInputRequest.newBuilder()
.setCssProductInput(
CssProductInput.newBuilder()
.setName(name)
.setAttributes(
com.google.shopping.css.v1.Attributes.newBuilder()
.setTitle("Attribute Title")
.setHeadlineOfferLink("abc.com")
.setHeadlineOfferCondition("New")
.setDescription("CSS Product description 0")
.build())
.build())
.setUpdateMask(FieldMask.newBuilder().addPaths("title").build())
.build();
System.out.println("Updating CSS Product");
CssProductInput response = cssProductInputsServiceClient.updateCssProductInput(request);
System.out.print("CSS product updated:");
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
final Config config = Config.load();
// The ID uniquely identifying each product. In
// the format languageCode~countryCode~rawProvidedId
final String productId = "de~DE~rawProvidedId17";
updateCssProductInput(config, productId);
}
}
يمكن تعديل حقول المستوى الأعلى فقط باستخدام طلب cssProductInputs.update
.
إذا كنت تريد تعديل الحقول المُدمجة، يجب تقديم العنصر بأكمله من المستوى الأعلى.
سيؤدي المثال المعروض إلى تعديل عنصر headlineOfferPrice
من المستوى الأعلى،
بما في ذلك الحقول المُدمجة لمنتج حالي، باستخدام بيانات المنتج
المقدَّمة في محتوى الطلب، مع ترك جميع الحقول الأخرى بدون تغيير.
PATCH https://css.googleapis.com/v1/accounts/{ACCOUNT_ID}/cssProductInputs/{CSS_PRODUCT_ID}
{
"attributes": {
"headlineOfferPrice": {
"amountMicros": "17.99",
"currencyCode": "USD"
}
}
}
لاختيار حقول معيّنة لتعديلها بدون إجراء تغييرات على الحقول الأخرى المضمّنة
في نص الطلب، يمكنك تحديد updateMask
. يجب أن تكون مَعلمة سلسلة طلب البحث
قائمة بحقول تحتاج إلى تعديلها ومفصولة بفواصل.
يكون الرمز updateMask
مفيدًا عندما تريد التأكيد على أنّه لن يتم تعديل سوى الحقول المُسمّاة.
ويؤدي عدم تحديد updateMask
إلى وضع علامة على جميع الحقول في
الطلب لتعديلها، كما هو موضّح في المثال. ومع ذلك، إذا لم يتم تحديد updateMask
بوضوح، لا يمكن حذف السمات الحالية.
سيؤدي المثال المعروض إلى تعديل title
للسلعة الحالية فقط باستخدام بيانات المنتج ذات الصلة المقدَّمة في
نص الطلب، مع ترك جميع الحقول الأخرى بما في ذلك headline offer link
بدون تغيير.
PATCH https://css.googleapis.com/v1/accounts/{ACCOUNT_ID}/cssProductInputs/{CSS_PRODUCT_ID}?updateMask=title
{
"attributes": {
"title":"item-title",
"headlineOfferLink":"headline-offer-newer.com"
}
}
إذا تم توفير حقل في قائمة updateMask ولكن ليس في نص الطلب، سيتم حذف هذا الحقل من مورد Product، في حال توفّره.
سيستخدم المثال المعروض updateMask لإزالة قيمة الحقل title
.
PATCH https://css.googleapis.com/v1/accounts/{ACCOUNT_ID}/cssProductInputs/{CSS_PRODUCT_ID}?updateMask=title
ACCOUNT_ID:
معرّف فريد للحساب، على سبيل المثال، 123
.
CSS_PRODUCT_ID:
رقم تعريف المنتج في CSS، على سبيل المثال، de~DE~B019G4
.
لحذف الحقل title
، اترك الحقل خارج محتوى الطلب. يمكنك أيضًا
إرسال الطلب بدون نص أساسي أو نص أساسي فارغ. لن تتغيّر الحقول التي لا تتضمّنها updateMask.