মার্চেন্ট এপিআই-এর সাথে ইন্টারঅ্যাক্ট করার এই পদ্ধতিতে আপনি প্রি-বিল্ট লাইব্রেরিগুলি ব্যবহার করেন যা অনুরোধ করা এবং প্রতিক্রিয়া পরিচালনা করার নিম্ন-স্তরের বিশদগুলিকে এনক্যাপসুলেট করে, API-এর সাথে ইন্টারঅ্যাক্ট করার আরও সুবিধাজনক এবং প্রায়শই ভাষা-বাক্যপূর্ণ উপায় প্রদান করে। তারা প্রমাণীকরণ, অনুরোধ এবং প্রতিক্রিয়া সিরিয়ালাইজেশন/ডিসারিয়ালাইজেশন এবং অন্যান্য বয়লারপ্লেট কোড পরিচালনা করে।
ধাপ 1. প্রমাণীকরণ সেট আপ করুন এবং কোড নমুনা কনফিগার করুন
নির্দেশাবলীর জন্য, মার্চেন্ট API-এর জন্য প্রমাণীকরণ এবং নমুনা কনফিগারেশন নমুনা সেট আপ করা দেখুন।
ধাপ 2. ক্লায়েন্ট লাইব্রেরি এবং কোড নমুনা ডাউনলোড এবং ইনস্টল করুন
ক্লায়েন্ট লাইব্রেরি ডাউনলোড এবং ইনস্টল করার নির্দেশাবলীর জন্য এবং GitHub থেকে কোড নমুনাগুলি ব্যবহার করার জন্য, Google Merchant API Python Samples দেখুন।
ধাপ 3. একজন বিকাশকারী হিসাবে নিবন্ধন করুন
মার্চেন্ট API ব্যবহার করতে, আপনাকে অবশ্যই আপনার বিকাশকারীর যোগাযোগের তথ্য নিবন্ধন করতে হবে।
নিবন্ধন নিম্নলিখিত সম্পন্ন করে:
- একজন ব্যবহারকারীকে
API developer
ভূমিকা অর্পণ করে আপনার Merchant Center অ্যাকাউন্টের জন্য একটি প্রযুক্তিগত যোগাযোগ তৈরি করে। এটি Google-কে বিশেষভাবে API এবং বিকাশকারী যে বৈশিষ্ট্যগুলি ব্যবহার করছে সে সম্পর্কে গুরুত্বপূর্ণ আপডেট পাঠাতে দেয়, যেমন পরিষেবার ঘোষণা এবং নতুন বৈশিষ্ট্য সম্পর্কে তথ্য, যা অ-বিকাশকারীদের কাছে কম আগ্রহী হতে পারে৷ - একাধিকবার নিবন্ধন না করেই আপনাকে একাধিক মার্চেন্ট অ্যাকাউন্টের সাথে কাজ করতে দেয়। আপনি যখন নিবন্ধন করেন, তখন মার্চেন্ট এপিআইকে প্রমাণীকরণ করতে ব্যবহৃত Google ক্লাউড প্রজেক্ট আইডি আপনার বণিক কেন্দ্র অ্যাকাউন্টের সাথে যুক্ত থাকে, যার প্রযুক্তিগত পরিচিতি রয়েছে (
API developer
)। এইভাবে, নিবন্ধিত Google ক্লাউড প্রকল্পের সাথে প্রমাণীকরণ সম্পন্ন হওয়া পর্যন্ত আপনি আপনার পরিচালনা করা সমস্ত বণিক অ্যাকাউন্টগুলির জন্য গুরুত্বপূর্ণ আপডেট পেতে পারেন৷
রেজিস্ট্রেশন করার সময়, রেজিস্ট্রেশনে বিস্তারিত পূর্বশর্ত এবং সীমাবদ্ধতাগুলি পর্যবেক্ষণ করুন।
ক্লায়েন্ট লাইব্রেরি ব্যবহার করে কীভাবে আপনার প্রকল্প নিবন্ধন করবেন তার উদাহরণের জন্য, পাইথন নমুনা ব্যবহার করে একটি বিকাশকারী ইমেল ঠিকানা সরবরাহ করে একটি Google ক্লাউড প্রকল্প নিবন্ধন করুন :
পাইথন
# -*- coding: utf-8 -*-
# Copyright 2025 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.
"""This example registers a GCP project with a developer email."""
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_accounts_v1 import DeveloperRegistrationServiceClient
from google.shopping.merchant_accounts_v1 import RegisterGcpRequest
def register_gcp(account_id: str, developer_email: str) -> None:
"""Registers the GCP project used to call the Merchant API with a developer email.
Args:
account_id: The ID of your Merchant Center account.
developer_email: The email address of the developer to register.
"""
# Get OAuth credentials.
credentials = generate_user_credentials.main()
# Create a client to the Developer Registration Service.
client = DeveloperRegistrationServiceClient(credentials=credentials)
# The name has the format: accounts/{account}/developerRegistration
name = f"accounts/{account_id}/developerRegistration"
# Create the request to register the GCP project.
request = RegisterGcpRequest(
name=name,
developer_email=developer_email,
)
# Make the API call and handle potential errors.
try:
print("Sending RegisterGcp request:")
response = client.register_gcp(request=request)
print("Registered GCP project successfully:")
print(response)
except RuntimeError as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
# Your Merchant Center account ID.
# This can be found in the Merchant Center UI.
_account_id = configuration.Configuration().read_merchant_info()
# The developer email to associate with the GCP project.
_developer_email = "YOUR_EMAIL_HERE"
register_gcp(_account_id, _developer_email)
ধাপ 4. বিকাশকারীর পরিচিতি এবং অনুমতিগুলি পরিচালনা করুন৷
আপনি যখন নিবন্ধন করবেন:
- যদি ইমেল ঠিকানাটি Merchant Center অ্যাকাউন্টের কোনো ব্যবহারকারীর হয়, তাহলে সেই ব্যবহারকারীকে
API_DEVELOPER
ভূমিকা দেওয়া হয়। - যদি ইমেল ঠিকানাটি বিদ্যমান ব্যবহারকারীর না হয়, তাহলে সেই ঠিকানায় একটি আমন্ত্রণ পাঠানো হয়।
API_DEVELOPER
ভূমিকা সহ একজন নতুন ব্যবহারকারী হিসাবে যোগ করার জন্য প্রাপককে আমন্ত্রণ গ্রহণ করতে হবে৷
প্রাথমিক নিবন্ধনের পরে, আমরা সুপারিশ করি যে আপনি একাধিক বিকাশকারীকে যুক্ত করুন এবং তাদের অতিরিক্ত অ্যাক্সেসের অধিকার প্রদান করুন৷
ধাপ 4a। অতিরিক্ত অনুমতি দিন
গুরুত্বপূর্ণ বিজ্ঞপ্তিগুলি পাওয়ার জন্য API_DEVELOPER
ভূমিকার প্রয়োজন, তবে এটির Merchant Center-এর মধ্যে ন্যূনতম অনুমতি রয়েছে৷ এই ব্যবহারকারীকে অন্য API কল করতে বা Merchant Center UI-তে সেটিংস পরিচালনা করার অনুমতি দিতে, আপনাকে তাদের অতিরিক্ত ভূমিকা দিতে হবে, যেমন STANDARD
বা ADMIN
৷ আরও তথ্যের জন্য, অ্যাক্সেসের ধরন দেখুন।
আপনি accounts.users.patch
পদ্ধতির মাধ্যমে ব্যবহারকারীর অ্যাক্সেসের অধিকার আপডেট করতে পারেন।
নমুনা কোড দেখায় কিভাবে একজন ব্যবহারকারীকে ADMIN
এবং API_DEVELOPER
উভয় ভূমিকা প্রদান করতে আপডেট করতে হয়। এটি তাদের সম্পূর্ণরূপে অ্যাকাউন্ট পরিচালনা করতে দেয় এবং এর অর্থ তারা API-সম্পর্কিত যোগাযোগগুলিও পাবে।
পাইথন
# -*- coding: utf-8 -*-
# Copyright 2024 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
#
# http://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.
"""A module to update a user."""
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.protobuf import field_mask_pb2
from google.shopping.merchant_accounts_v1 import AccessRight
from google.shopping.merchant_accounts_v1 import UpdateUserRequest
from google.shopping.merchant_accounts_v1 import User
from google.shopping.merchant_accounts_v1 import UserServiceClient
FieldMask = field_mask_pb2.FieldMask
_ACCOUNT = configuration.Configuration().read_merchant_info()
def update_user(user_email, user_access_right):
"""Updates a user to make it an admin of the MC account."""
credentials = generate_user_credentials.main()
client = UserServiceClient(credentials=credentials)
# Create user name string
name = "accounts/" + _ACCOUNT + "/users/" + user_email
user = User(name=name, access_rights=[user_access_right])
field_mask = FieldMask(paths=["access_rights"])
try:
request = UpdateUserRequest(user=user, update_mask=field_mask)
print("Sending Update User request")
response = client.update_user(request=request)
print("Updated User Name below")
print(response.name)
except RuntimeError as e:
print(e)
if __name__ == "__main__":
# Modify this email to update the right user
email = "USER_MAIL_ACCOUNT"
access_right = AccessRight.ADMIN
update_user(email, access_right)
ধাপ 4 খ. ব্যাকআপ ডেভেলপার যোগ করুন
যদি আপনার প্রাথমিক বিকাশকারী পরিচিতি আপনার সংস্থা ছেড়ে চলে যায় তাহলে আপনার API অ্যাক্সেস ব্যাহত হওয়া থেকে আটকাতে, আপনাকে অন্তত একজন ব্যাকআপ বিকাশকারী যোগ করা উচিত।
আপনি accounts.users.create
পদ্ধতির সাথে একজন ব্যবহারকারীকে যোগ করতে পারেন বা accounts.users.patch
পদ্ধতির সাথে একটি বিদ্যমান আপডেট করতে পারেন। আমরা এই ব্যবহারকারীকে ADMIN
এবং API_DEVELOPER
উভয় ভূমিকা দেওয়ার সুপারিশ করি৷
ধাপ 5. একটি প্রাথমিক পণ্য ডেটা উৎস তৈরি করুন
আপনি একটি পণ্য সন্নিবেশ করার আগে, আপনি একটি প্রাথমিক পণ্য তথ্য উৎস প্রয়োজন. একটি ডেটা উত্স তৈরি করে এমন নমুনা কোডের জন্য, পাইথনের সাথে একাধিক ভাষার নমুনা সমর্থন করে এমন একটি প্রাথমিক পণ্য ডেটা উত্স তৈরি করুন দেখুন৷
পাইথন
# -*- coding: utf-8 -*-
# Copyright 2024 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
#
# http://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.
"""This class demonstrates how to create a Primary product datasource all `feedLabel` and `contentLanguage` combinations.
This works only for API primary feeds.
"""
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_datasources_v1 import CreateDataSourceRequest
from google.shopping.merchant_datasources_v1 import DataSource
from google.shopping.merchant_datasources_v1 import DataSourcesServiceClient
from google.shopping.merchant_datasources_v1 import PrimaryProductDataSource
_ACCOUNT = configuration.Configuration().read_merchant_info()
_PARENT = f"accounts/{_ACCOUNT}"
def create_primary_product_data_source_multiple_languages():
"""Creates a `DataSource` resource."""
# Gets OAuth Credentials.
credentials = generate_user_credentials.main()
# Creates a client.
client = DataSourcesServiceClient(credentials=credentials)
# Creates a PrimaryProductDataSource.
primary_datasource = PrimaryProductDataSource()
primary_datasource.countries = ["GB"]
# Creates a DataSource and populates its attributes.
data_source = DataSource()
data_source.display_name = "Example Multiple Languages Primary DataSource"
data_source.primary_product_data_source = primary_datasource
# Creates the request.
request = CreateDataSourceRequest(parent=_PARENT, data_source=data_source)
# Makes the request and catches and prints any error messages.
try:
response = client.create_data_source(request=request)
print(f"DataSource successfully created: {response}")
except RuntimeError as e:
print("DataSource creation failed")
print(e)
if __name__ == "__main__":
create_primary_product_data_source_multiple_languages()
আপনি Merchant Center UI-তে এই ডেটা উৎস দেখতে পারেন। আরও তথ্যের জন্য, ডেটা উত্স ট্যাবটি কীভাবে সন্ধান করবেন তা দেখুন।
ধাপ 6. একটি পণ্য সন্নিবেশ করান
একবার আপনি ডেটা উত্স তৈরি করার পরে, এটিতে একটি পণ্য সন্নিবেশ করার চেষ্টা করুন। নমুনা কোডের জন্য যা দেখায় কিভাবে ক্লায়েন্ট লাইব্রেরিগুলির সাথে এটি করতে হয়, দেখুন পাইথনের সাথে একটি পণ্য ইনপুট নমুনা সন্নিবেশ করান ।
পাইথন
# -*- coding: utf-8 -*-
# Copyright 2024 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
#
# http://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.
"""A module to insert a Product Input."""
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping import merchant_products_v1
from google.shopping.merchant_products_v1 import Availability
from google.shopping.merchant_products_v1 import Condition
from google.shopping.type import Price
_ACCOUNT = configuration.Configuration().read_merchant_info()
_PARENT = f"accounts/{_ACCOUNT}"
# You can only insert products into datasource types of Input "API" and
# "FILE", and of Type "Primary" or "Supplemental."
_DATA_SOURCE = "[INSERT_DATA_SOURCE_HERE]"
_DATA_SOURCE_NAME = f"accounts/{_ACCOUNT}/dataSources/{_DATA_SOURCE}"
def create_product_input():
"""Creates a `ProductInput` resource."""
# Creates a shipping setting
price = Price()
price.amount_micros = 33_450_000
price.currency_code = "GBP"
shipping_option_1 = merchant_products_v1.Shipping()
shipping_option_1.price = price
shipping_option_1.country = "GB"
shipping_option_1.service = "1st class post"
price2 = Price()
price2.amount_micros = 33_450_000
price2.currency_code = "EUR"
shipping_option_2 = merchant_products_v1.Shipping()
shipping_option_2.price = price2
shipping_option_2.country = "FR"
shipping_option_2.service = "2nd class post"
# Sets product attributes. Make sure to replace these values with your own.
attributes = merchant_products_v1.ProductAttributes()
attributes.title = "A Tale of Two Cities"
attributes.description = "A classic novel about the French Revolution"
attributes.link = "https://exampleWebsite.com/tale-of-two-cities.html"
attributes.image_link = "https://exampleWebsite.com/tale-of-two-cities.jpg"
attributes.price = price
attributes.availability = Availability.IN_STOCK
attributes.condition = Condition.NEW
attributes.google_product_category = "Media > Books"
attributes.gtins = ["9780007350896"]
attributes.shipping = [shipping_option_1, shipping_option_2]
return merchant_products_v1.ProductInput(
content_language="en",
feed_label="GB",
offer_id="sku123",
product_attributes=attributes,
)
def insert_product_input():
"""Inserts the specified `ProductInput` resource."""
# Gets OAuth Credentials.
credentials = generate_user_credentials.main()
# Creates a client.
client = merchant_products_v1.ProductInputsServiceClient(
credentials=credentials
)
# Creates the request.
request = merchant_products_v1.InsertProductInputRequest(
parent=_PARENT,
# If this product is already owned by another datasource, when
# re-inserting, the new datasource will take ownership of the product.
product_input=create_product_input(),
data_source=_DATA_SOURCE_NAME,
)
# Makes the request and catches and prints any error messages.
try:
response = client.insert_product_input(request=request)
# The last part of the product name will be the product ID assigned to a
# product by Google. Product ID has the format
# `contentLanguage~feedLabel~offerId`
print(f"Input successful: {response}")
except RuntimeError as e:
print("Input failed")
print(e)
# After the product is inserted, the product ID will be returned in the
# response. We recommend that you check the Merchant Center to ensure that
# the product is approved and visible to users before using the product ID
# in any downstream processes.
if __name__ == "__main__":
insert_product_input()
ধাপ 7. আপনার পণ্য তালিকা
নমুনা কোডের জন্য যা আপনার ডেটা উৎসে পণ্য তালিকাভুক্ত করে, পাইথনের সাথে পণ্যের নমুনা তালিকা দেখুন।
পাইথন
# -*- coding: utf-8 -*-
# Copyright 2024 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
#
# http://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.
"""A module to list Products."""
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping import merchant_products_v1
_ACCOUNT = configuration.Configuration().read_merchant_info()
_PARENT = f"accounts/{_ACCOUNT}"
def list_products():
"""Lists the `Product` resources for a given account."""
# Gets OAuth Credentials.
credentials = generate_user_credentials.main()
# Creates a client.
client = merchant_products_v1.ProductsServiceClient(
credentials=credentials
)
# Creates the request. Set the page size to the maximum value.
request = merchant_products_v1.ListProductsRequest(
parent=_PARENT, page_size=1000
)
# Makes the request and catches and prints any error messages.
try:
response = client.list_products(request=request)
for product in response:
print(product)
print("List request successful!")
except RuntimeError as e:
print("List request failed")
print(e)
if __name__ == "__main__":
list_products()