Merchant API를 사용하면 파일 기반 데이터 소스의 처리 상태를 모니터링하고 즉시 가져오기를 수동으로 트리거할 수 있습니다.
최신 파일 업로드 상태 가져오기
파일 기반 데이터 소스의 가장 최근 처리 시도 상태를 확인하려면 fileUploads.get
메서드를 사용합니다. fileuploadId
의 별칭 latest
를 사용하여 최신 업로드 또는 가져오기의 상태를 검색해야 합니다.
이 메서드는 다음에 관한 세부정보를 반환합니다.
- 처리 상태 (예:
SUCCEEDED
,FAILED
,IN_PROGRESS
) - 처리된 항목 수
- 발생한 문제
- 업로드 타임스탬프
GET https://merchantapi.googleapis.com/datasources/v1beta/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
메서드를 사용하여 가장 최근 파일 업로드의 상태를 가져오는 방법을 보여줍니다.
자바
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.datasources.v1beta.FileUpload;
import com.google.shopping.merchant.datasources.v1beta.FileUploadName;
import com.google.shopping.merchant.datasources.v1beta.FileUploadsServiceClient;
import com.google.shopping.merchant.datasources.v1beta.FileUploadsServiceSettings;
import com.google.shopping.merchant.datasources.v1beta.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/v1beta/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/v1beta/accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}:fetch
가져오기를 시작하는 요청이 성공하면 실제 처리가 비동기적으로 이루어지므로 빈 응답이 반환됩니다. 앞에서 설명한 fileUploads.get
메서드를 사용하여 결과를 모니터링할 수 있습니다.
다음 코드 샘플은 dataSources.fetch
메서드를 사용하여 지정된 데이터 소스의 즉각적인 가져오기를 요청하는 방법을 보여줍니다.
자바
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.datasources.v1beta.DataSourceName;
import com.google.shopping.merchant.datasources.v1beta.DataSourcesServiceClient;
import com.google.shopping.merchant.datasources.v1beta.DataSourcesServiceSettings;
import com.google.shopping.merchant.datasources.v1beta.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/v1beta/accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}:fetch" \
-H "Authorization: Bearer <API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{}'