Skip to content

Commit 3a1c213

Browse files
feat(accounts): [ShoppingMerchantAccounts] Add batch operations for custom regions (#8544)
* feat(accounts): Add batch operations for custom regions Added the following methods to the `RegionsService` in the Merchant API Accounts v1: - `BatchCreateRegions`: Create multiple regions in a single request. - `BatchUpdateRegions`: Update multiple regions in a single request. - `BatchDeleteRegions`: Delete multiple regions in a single request. These methods allow for more efficient management of custom regions. PiperOrigin-RevId: 800519608 Source-Link: googleapis/googleapis@c4c5ad7 Source-Link: googleapis/googleapis-gen@d1fd7b2 Copy-Tag: eyJwIjoiU2hvcHBpbmdNZXJjaGFudEFjY291bnRzLy5Pd2xCb3QueWFtbCIsImgiOiJkMWZkN2IyZjAwZDVjNDI5ZTMxNzg5Yzk2YjU0ZTJjNWI4ZWI1M2JmIn0= * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 0ac93dd commit 3a1c213

15 files changed

Lines changed: 1119 additions & 18 deletions
1.29 KB
Binary file not shown.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
/*
3+
* Copyright 2025 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START merchantapi_v1_generated_RegionsService_BatchCreateRegions_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\Shopping\Merchant\Accounts\V1\BatchCreateRegionsRequest;
28+
use Google\Shopping\Merchant\Accounts\V1\BatchCreateRegionsResponse;
29+
use Google\Shopping\Merchant\Accounts\V1\Client\RegionsServiceClient;
30+
use Google\Shopping\Merchant\Accounts\V1\CreateRegionRequest;
31+
use Google\Shopping\Merchant\Accounts\V1\Region;
32+
33+
/**
34+
* Creates one or more regions in your Merchant Center account.
35+
* Executing this method requires admin access.
36+
*
37+
* @param string $formattedParent The account to create one or more regions for.
38+
* Format: `accounts/{account}`
39+
* Please see {@see RegionsServiceClient::accountName()} for help formatting this field.
40+
* @param string $formattedRequestsParent The account to create a region for.
41+
* Format: `accounts/{account}`
42+
* Please see {@see RegionsServiceClient::accountName()} for help formatting this field.
43+
* @param string $requestsRegionId The identifier for the region, unique over all regions of the
44+
* same account.
45+
*/
46+
function batch_create_regions_sample(
47+
string $formattedParent,
48+
string $formattedRequestsParent,
49+
string $requestsRegionId
50+
): void {
51+
// Create a client.
52+
$regionsServiceClient = new RegionsServiceClient();
53+
54+
// Prepare the request message.
55+
$requestsRegion = new Region();
56+
$createRegionRequest = (new CreateRegionRequest())
57+
->setParent($formattedRequestsParent)
58+
->setRegionId($requestsRegionId)
59+
->setRegion($requestsRegion);
60+
$requests = [$createRegionRequest,];
61+
$request = (new BatchCreateRegionsRequest())
62+
->setParent($formattedParent)
63+
->setRequests($requests);
64+
65+
// Call the API and handle any network failures.
66+
try {
67+
/** @var BatchCreateRegionsResponse $response */
68+
$response = $regionsServiceClient->batchCreateRegions($request);
69+
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
70+
} catch (ApiException $ex) {
71+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
72+
}
73+
}
74+
75+
/**
76+
* Helper to execute the sample.
77+
*
78+
* This sample has been automatically generated and should be regarded as a code
79+
* template only. It will require modifications to work:
80+
* - It may require correct/in-range values for request initialization.
81+
* - It may require specifying regional endpoints when creating the service client,
82+
* please see the apiEndpoint client configuration option for more details.
83+
*/
84+
function callSample(): void
85+
{
86+
$formattedParent = RegionsServiceClient::accountName('[ACCOUNT]');
87+
$formattedRequestsParent = RegionsServiceClient::accountName('[ACCOUNT]');
88+
$requestsRegionId = '[REGION_ID]';
89+
90+
batch_create_regions_sample($formattedParent, $formattedRequestsParent, $requestsRegionId);
91+
}
92+
// [END merchantapi_v1_generated_RegionsService_BatchCreateRegions_sync]
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/*
3+
* Copyright 2025 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START merchantapi_v1_generated_RegionsService_BatchDeleteRegions_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\Shopping\Merchant\Accounts\V1\BatchDeleteRegionsRequest;
28+
use Google\Shopping\Merchant\Accounts\V1\Client\RegionsServiceClient;
29+
use Google\Shopping\Merchant\Accounts\V1\DeleteRegionRequest;
30+
31+
/**
32+
* Deletes multiple regions by name from your Merchant Center account.
33+
* Executing this method requires admin access.
34+
*
35+
* @param string $formattedParent The account to delete one or more regions from.
36+
* Format: `accounts/{account}`
37+
* Please see {@see RegionsServiceClient::accountName()} for help formatting this field.
38+
* @param string $formattedRequestsName The name of the region to delete.
39+
* Format: `accounts/{account}/regions/{region}`
40+
* Please see {@see RegionsServiceClient::regionName()} for help formatting this field.
41+
*/
42+
function batch_delete_regions_sample(string $formattedParent, string $formattedRequestsName): void
43+
{
44+
// Create a client.
45+
$regionsServiceClient = new RegionsServiceClient();
46+
47+
// Prepare the request message.
48+
$deleteRegionRequest = (new DeleteRegionRequest())
49+
->setName($formattedRequestsName);
50+
$requests = [$deleteRegionRequest,];
51+
$request = (new BatchDeleteRegionsRequest())
52+
->setParent($formattedParent)
53+
->setRequests($requests);
54+
55+
// Call the API and handle any network failures.
56+
try {
57+
$regionsServiceClient->batchDeleteRegions($request);
58+
printf('Call completed successfully.' . PHP_EOL);
59+
} catch (ApiException $ex) {
60+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
61+
}
62+
}
63+
64+
/**
65+
* Helper to execute the sample.
66+
*
67+
* This sample has been automatically generated and should be regarded as a code
68+
* template only. It will require modifications to work:
69+
* - It may require correct/in-range values for request initialization.
70+
* - It may require specifying regional endpoints when creating the service client,
71+
* please see the apiEndpoint client configuration option for more details.
72+
*/
73+
function callSample(): void
74+
{
75+
$formattedParent = RegionsServiceClient::accountName('[ACCOUNT]');
76+
$formattedRequestsName = RegionsServiceClient::regionName('[ACCOUNT]', '[REGION]');
77+
78+
batch_delete_regions_sample($formattedParent, $formattedRequestsName);
79+
}
80+
// [END merchantapi_v1_generated_RegionsService_BatchDeleteRegions_sync]
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/*
3+
* Copyright 2025 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START merchantapi_v1_generated_RegionsService_BatchUpdateRegions_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\Shopping\Merchant\Accounts\V1\BatchUpdateRegionsRequest;
28+
use Google\Shopping\Merchant\Accounts\V1\BatchUpdateRegionsResponse;
29+
use Google\Shopping\Merchant\Accounts\V1\Client\RegionsServiceClient;
30+
use Google\Shopping\Merchant\Accounts\V1\Region;
31+
use Google\Shopping\Merchant\Accounts\V1\UpdateRegionRequest;
32+
33+
/**
34+
* Updates one or more regions in your Merchant Center account.
35+
* Executing this method requires admin access.
36+
*
37+
* @param string $formattedParent The account to update one or more regions for.
38+
* Format: `accounts/{account}`
39+
* Please see {@see RegionsServiceClient::accountName()} for help formatting this field.
40+
*/
41+
function batch_update_regions_sample(string $formattedParent): void
42+
{
43+
// Create a client.
44+
$regionsServiceClient = new RegionsServiceClient();
45+
46+
// Prepare the request message.
47+
$requestsRegion = new Region();
48+
$updateRegionRequest = (new UpdateRegionRequest())
49+
->setRegion($requestsRegion);
50+
$requests = [$updateRegionRequest,];
51+
$request = (new BatchUpdateRegionsRequest())
52+
->setParent($formattedParent)
53+
->setRequests($requests);
54+
55+
// Call the API and handle any network failures.
56+
try {
57+
/** @var BatchUpdateRegionsResponse $response */
58+
$response = $regionsServiceClient->batchUpdateRegions($request);
59+
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
60+
} catch (ApiException $ex) {
61+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
62+
}
63+
}
64+
65+
/**
66+
* Helper to execute the sample.
67+
*
68+
* This sample has been automatically generated and should be regarded as a code
69+
* template only. It will require modifications to work:
70+
* - It may require correct/in-range values for request initialization.
71+
* - It may require specifying regional endpoints when creating the service client,
72+
* please see the apiEndpoint client configuration option for more details.
73+
*/
74+
function callSample(): void
75+
{
76+
$formattedParent = RegionsServiceClient::accountName('[ACCOUNT]');
77+
78+
batch_update_regions_sample($formattedParent);
79+
}
80+
// [END merchantapi_v1_generated_RegionsService_BatchUpdateRegions_sync]

ShoppingMerchantAccounts/src/V1/BatchCreateRegionsRequest.php

Lines changed: 109 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)