ফাইল-ভিত্তিক ডেটা সোর্স প্রসেসিং মনিটর ও ট্রিগার করা

Merchant API আপনাকে ফাইল-ভিত্তিক ডেটা সোর্সের প্রসেসিং স্ট্যাটাস মনিটর করতে এবং সেগুলি অবিলম্বে ম্যানুয়ালি ফেচ করতে দেয়।

লেটেস্ট ফাইল আপলোড স্ট্যাটাস পাওয়া

ফাইল-ভিত্তিক ডেটা সোর্সের জন্য সবচেয়ে সাম্প্রতিক প্রসেসিং প্রচেষ্টার স্ট্যাটাস চেক করতে, fileUploads.get মেথড ব্যবহার করুন। সবচেয়ে সাম্প্রতিক আপলোড বা ফেচ করা ডেটার স্ট্যাটাস পেতে হলে আপনাকে fileuploadId-এর জন্য latest ছদ্মনাম ব্যবহার করতে হবে।

এই পদ্ধতিটি এইসব বিষয় সম্পর্কে বিবরণ দেয়:

  • প্রসেসিং স্টেট (যেমন, SUCCEEDED, FAILED, IN_PROGRESS)
  • প্রসেস করা আইটেমের সংখ্যা
  • কোনও সমস্যা হয়ে থাকলে
  • আপলোড করার টাইমস্ট্যাম্প
GET https://merchantapi.googleapis.com/datasources/v1/accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}/fileUploads/latest

সফল অনুরোধের ফলে FileUpload রিসোর্স রিটার্ন করা হয়, যার মধ্যে স্ট্যাটাস বিবরণ থাকে।

সতর্কতা সহ সফল আপলোডের ক্ষেত্রে এটি হল উত্তরের একটি উদাহরণ।

{
  "name": "accounts/123456789/dataSources/111222333/fileUploads/latest",
  "dataSourceId": "111222333",
  "processingState": "SUCCEEDED",
  "issues": [
    {
      "title": "Missing recommended attribute",
      "description": "Products are missing a recommended attribute 'description'.",
      "code": "validation/missing_recommended_attribute",
      "count": "5",
      "severity": "WARNING",
      "documentationUri": "https://support.google.com/merchants/answer/6324468"
    }
  ],
  "itemsTotal": "100",
  "itemsCreated": "90",
  "itemsUpdated": "10",
  "uploadTime": "2023-10-26T10:30:00Z"
}

আপলোড প্রসেস চলাকালীন উত্তরের একটি উদাহরণ এখানে দেওয়া হল।

{
  "name": "accounts/123456789/dataSources/111222333/fileUploads/latest",
  "dataSourceId": "111222333",
  "processingState": "IN_PROGRESS",
  "uploadTime": "2023-10-26T11:00:00Z"
}

আপলোড করা না গেলে, তার উত্তরে কী বলা হবে, তার একটি উদাহরণ এখানে দেওয়া হল।

{
  "name": "accounts/123456789/dataSources/111222333/fileUploads/latest",
  "dataSourceId": "111222333",
  "processingState": "FAILED",
  "issues": [
    {
      "title": "Invalid file format",
      "description": "The uploaded file is not a valid XML or CSV file.",
      "code": "validation/invalid_file_format",
      "count": "1",
      "severity": "ERROR",
      "documentationUri": "https://support.google.com/merchants/answer/188494"
    }
  ],
  "uploadTime": "2023-10-26T11:15:00Z"
}

latest ছদ্মনাম সহ fileUploads.get পদ্ধতি ব্যবহার করে সবচেয়ে সাম্প্রতিক ফাইল আপলোডের স্ট্যাটাস কীভাবে পেতে হয় তা নিম্নলিখিত কোড স্যাম্পেল থেকে জানতে পারবেন।

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.datasources.v1.FileUpload;
import com.google.shopping.merchant.datasources.v1.FileUploadName;
import com.google.shopping.merchant.datasources.v1.FileUploadsServiceClient;
import com.google.shopping.merchant.datasources.v1.FileUploadsServiceSettings;
import com.google.shopping.merchant.datasources.v1.GetFileUploadRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/** This class demonstrates how to get the latest data source file upload. */
public class GetFileUploadSample {

  public static void getFileUpload(Config config, String datasourceId) throws Exception {

    // Obtains OAuth token based on the user's configuration.
    GoogleCredentials credential = new Authenticator().authenticate();

    // Creates service settings using the credentials retrieved above.
    FileUploadsServiceSettings fileUploadsServiceSettings =
        FileUploadsServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Creates FileUpload name with datasource id to identify datasource.
    String name =
        FileUploadName.newBuilder()
            .setAccount(config.getAccountId().toString())
            .setDatasource(datasourceId)
            .setFileupload("latest")
            .build()
            .toString();

    // Calls the API and catches and prints any network failures/errors.
    try (FileUploadsServiceClient fileUploadsServiceClient =
        FileUploadsServiceClient.create(fileUploadsServiceSettings)) {

      // The name has the format: accounts/{account}/datasources/{datasource}/fileUploads/latest
      GetFileUploadRequest request = GetFileUploadRequest.newBuilder().setName(name).build();

      System.out.println("Sending get FileUpload request:");
      FileUpload response = fileUploadsServiceClient.getFileUpload(request);

      System.out.println("Retrieved FileUpload below");
      System.out.println(response);
      //   return response;
    } catch (Exception e) {
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();
    // An ID assigned to a datasource by Google.
    String datasourceId = "123456789";

    getFileUpload(config, datasourceId);
  }
}

cURL

curl \
"https://merchantapi.googleapis.com/datasources/v1/accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}/fileUploads/latest" \
-H "Authorization: Bearer <API_TOKEN>" \
-H "Content-Type: application/json"

অবিলম্বে ডেটা সোর্স ফেচ করা

এই পদ্ধতি আপনাকে dataSources.fetch পদ্ধতি ব্যবহার করে ফাইল-ভিত্তিক ডেটা সোর্স অবিলম্বে ফেচ ও প্রসেস করার অনুরোধ করতে দেয়। আপনি সোর্স ফাইল আপডেট করে থাকলে এবং Google-কে পরবর্তী শিডিউল করা ফেচ করার আগেই সেটি রিট্রিভ করতে চাইলে এটি কাজে লাগে।

POST https://merchantapi.googleapis.com/datasources/v1/accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}:fetch

ফেচ শুরু করার জন্য সফল অনুরোধ করলে, কোনও উত্তর পাওয়া যায় না, কারণ আসল প্রসেসিং অ্যাসিঙ্ক্রোনাস পদ্ধতিতে হয়। আপনি fileUploads.get আগে বর্ণিত পদ্ধতি ব্যবহার করে ফলাফল মনিটর করতে পারবেন।

নিম্নলিখিত কোড স্যাম্পল থেকে বোঝা যায় যে কীভাবে dataSources.fetch পদ্ধতি ব্যবহার করে কোনও নির্দিষ্ট ডেটা সোর্স অবিলম্বে ফেচ করার অনুরোধ করা যায়।

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.datasources.v1.DataSourceName;
import com.google.shopping.merchant.datasources.v1.DataSourcesServiceClient;
import com.google.shopping.merchant.datasources.v1.DataSourcesServiceSettings;
import com.google.shopping.merchant.datasources.v1.FetchDataSourceRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/**
 * This class demonstrates how to fetch a specific FileInput DataSource for a given Merchant Center
 * account.
 */
public class FetchFileDataSourceSample {

  public static void fetchDataSource(Config config, String dataSourceId) throws Exception {

    // Obtains OAuth token based on the user's configuration.
    GoogleCredentials credential = new Authenticator().authenticate();

    // Creates service settings using the credentials retrieved above.
    DataSourcesServiceSettings dataSourcesServiceSettings =
        DataSourcesServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Creates datasource name to identify datasource.
    String name =
        DataSourceName.newBuilder()
            .setAccount(config.getAccountId().toString())
            .setDatasource(dataSourceId)
            .build()
            .toString();

    // Calls the API and catches and prints any network failures/errors.
    try (DataSourcesServiceClient dataSourcesServiceClient =
        DataSourcesServiceClient.create(dataSourcesServiceSettings)) {

      // The name has the format: accounts/{account}/datasources/{datasource}
      FetchDataSourceRequest request = FetchDataSourceRequest.newBuilder().setName(name).build();

      System.out.println("Sending FETCH DataSource request:");
      // Fetch works ONLY for FileInput DataSource type.
      dataSourcesServiceClient.fetchDataSource(request); // No response returned on success

      System.out.println("Successfully fetched DataSource.");

    } catch (Exception e) {
      System.out.println(e);
      System.exit(1);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();
    String datasourceId = "<DATASOURCE_ID>"; // Replace with your FileInput DataSource ID.

    fetchDataSource(config, datasourceId);
  }
}

cURL

curl -X POST \
"https://merchantapi.googleapis.com/datasources/v1/accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}:fetch" \
-H "Authorization: Bearer <API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{}'