|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * Copyright 2026 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 cloudsupport_v2_generated_CaseAttachmentService_GetAttachment_sync] |
| 26 | +use Google\ApiCore\ApiException; |
| 27 | +use Google\Cloud\Support\V2\Attachment; |
| 28 | +use Google\Cloud\Support\V2\Client\CaseAttachmentServiceClient; |
| 29 | +use Google\Cloud\Support\V2\GetAttachmentRequest; |
| 30 | + |
| 31 | +/** |
| 32 | + * Retrieve an attachment associated with a support case. |
| 33 | + * |
| 34 | + * EXAMPLES: |
| 35 | + * |
| 36 | + * cURL: |
| 37 | + * |
| 38 | + * ```shell |
| 39 | + * attachment="projects/some-project/cases/23598314/attachments/0684M00000P3h1fQAB" |
| 40 | + * curl \ |
| 41 | + * --header "Authorization: Bearer $(gcloud auth print-access-token)" \ |
| 42 | + * "https://cloudsupport.googleapis.com/v2/$attachment" |
| 43 | + * ``` |
| 44 | + * |
| 45 | + * Python: |
| 46 | + * |
| 47 | + * ```python |
| 48 | + * import googleapiclient.discovery |
| 49 | + * |
| 50 | + * api_version = "v2" |
| 51 | + * supportApiService = googleapiclient.discovery.build( |
| 52 | + * serviceName="cloudsupport", |
| 53 | + * version=api_version, |
| 54 | + * discoveryServiceUrl=f"https://cloudsupport.googleapis.com/$discovery/rest?version={api_version}", |
| 55 | + * ) |
| 56 | + * request = ( |
| 57 | + * supportApiService.cases() |
| 58 | + * .attachments() |
| 59 | + * .get(name="projects/some-project/cases/43595344/attachments/0684M00000P3h1fQAB") |
| 60 | + * ) |
| 61 | + * print(request.execute()) |
| 62 | + * ``` |
| 63 | + * |
| 64 | + * @param string $formattedName The name of the attachment to get. Please see |
| 65 | + * {@see CaseAttachmentServiceClient::attachmentName()} for help formatting this field. |
| 66 | + */ |
| 67 | +function get_attachment_sample(string $formattedName): void |
| 68 | +{ |
| 69 | + // Create a client. |
| 70 | + $caseAttachmentServiceClient = new CaseAttachmentServiceClient(); |
| 71 | + |
| 72 | + // Prepare the request message. |
| 73 | + $request = (new GetAttachmentRequest()) |
| 74 | + ->setName($formattedName); |
| 75 | + |
| 76 | + // Call the API and handle any network failures. |
| 77 | + try { |
| 78 | + /** @var Attachment $response */ |
| 79 | + $response = $caseAttachmentServiceClient->getAttachment($request); |
| 80 | + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); |
| 81 | + } catch (ApiException $ex) { |
| 82 | + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +/** |
| 87 | + * Helper to execute the sample. |
| 88 | + * |
| 89 | + * This sample has been automatically generated and should be regarded as a code |
| 90 | + * template only. It will require modifications to work: |
| 91 | + * - It may require correct/in-range values for request initialization. |
| 92 | + * - It may require specifying regional endpoints when creating the service client, |
| 93 | + * please see the apiEndpoint client configuration option for more details. |
| 94 | + */ |
| 95 | +function callSample(): void |
| 96 | +{ |
| 97 | + $formattedName = CaseAttachmentServiceClient::attachmentName( |
| 98 | + '[ORGANIZATION]', |
| 99 | + '[CASE]', |
| 100 | + '[ATTACHMENT_ID]' |
| 101 | + ); |
| 102 | + |
| 103 | + get_attachment_sample($formattedName); |
| 104 | +} |
| 105 | +// [END cloudsupport_v2_generated_CaseAttachmentService_GetAttachment_sync] |
0 commit comments