음수 ID를 사용하도록 새 리소스의 resource_name를 지정하면 됩니다. 예를 들어 캠페인을 만들고 리소스 이름을 customers/<YOUR_CUSTOMER_ID>/campaigns/-1로 지정한다고 가정해 보겠습니다. 나중에 작업을 통해 광고 그룹을 만들 때 해당 리소스 이름으로 참조하면 지정한 -1가 생성된 캠페인의 실제 ID로 자동으로 대체됩니다.
임시 리소스 이름을 사용할 때 유의해야 할 사항은 다음과 같습니다.
임시 리소스 이름은 리소스에 정의된 후에만 사용할 수 있습니다. 다음 예에서 광고 그룹 작업은 작업 목록에서 캠페인 작업 뒤에 표시되어야 합니다.
임시 리소스 이름은 작업 또는 변이 요청 간에 기억되지 않습니다.
이전 작업 또는 변이 요청에서 생성된 리소스를 참조하려면 실제 리소스 이름을 사용합니다.
단일 작업 또는 변이 요청의 경우 임시 리소스 이름이 서로 다른 리소스 유형에서 온 것이더라도 각 임시 리소스 이름은 고유한 음수를 사용해야 합니다. 단일 작업 또는 변이 요청에서 임시 ID가 재사용되면 오류가 반환됩니다.
예
단일 API 요청에 캠페인, 광고 그룹, 광고를 추가한다고 가정해 보겠습니다. 다음과 유사한 요청 구조를 만듭니다.
캠페인에 사용된 -1를 재사용할 수 없으므로 광고 그룹에 새 임시 ID가 사용됩니다. 광고 그룹 광고를 만들 때도 이 광고 그룹을 참조합니다. 광고 그룹 자체는 요청의 이전 작업에서 캠페인에 대해 설정한 리소스 이름을 참조하는 반면 ad_group_ad_operation의 resource_name는 더 이상 참조하는 작업이 없으므로 필요하지 않습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-05(UTC)"],[[["\u003cp\u003e\u003ccode\u003eBatchJobService\u003c/code\u003e allows the use of temporary IDs (negative numbers) for new resources within a single job, enabling you to reference them in subsequent operations within the same request.\u003c/p\u003e\n"],["\u003cp\u003eTemporary resource names must be unique within a single job or mutate request and are not remembered across different jobs or requests; use actual resource names for referencing resources created earlier.\u003c/p\u003e\n"],["\u003cp\u003eResources with temporary IDs must be defined before being referenced by other operations within the same request, ensuring the order of operations reflects dependencies.\u003c/p\u003e\n"]]],[],null,["# Using temporary IDs\n\nA powerful feature of [`BatchJobService`](/google-ads/api/reference/rpc/v21/BatchJobService) is that\nit supports the use of temporary IDs.\n\nYou can do this by specifying the new resource's `resource_name` to use a\nnegative ID. For example, suppose you create a campaign and specify its resource name\nas `customers/\u003cYOUR_CUSTOMER_ID\u003e/campaigns/-1`. When you create the\nad group in a later operation, you can then reference it by that resource name\nand the `-1` you specified will be replaced by the actual ID of the created\ncampaign automatically.\n\nHere are some things to keep in mind when using temporary resource names:\n\n- A temporary resource name can only be used after it's been defined in a resource. In the following example, the ad group operation would have to appear after the campaign operation in the list of operations.\n- Temporary resource names are not remembered across jobs or mutate requests. To reference a resource created in a previous job or mutate request, use its actual resource name.\n- For a single job or mutate request, each temporary resource name must use a unique negative number, even if they are from different resource types. If a temporary ID is reused in a single job or mutate request, then an error is returned.\n\n### Example\n\nSuppose you want to add a campaign, an ad group, and an ad in a single API\nrequest. You would create a structure for your request analogous to the\nfollowing: \n\n mutate_operations: [\n {\n campaign_operation: {\n create: {\n resource_name: \"customers/\u003cYOUR_CUSTOMER_ID\u003e/campaigns/-1\",\n ...\n }\n }\n },\n {\n ad_group_operation: {\n create: {\n resource_name: \"customers/\u003cYOUR_CUSTOMER_ID\u003e/adGroups/-2\",\n campaign: \"customers/\u003cYOUR_CUSTOMER_ID\u003e/campaigns/-1\"\n ...\n }\n }\n },\n {\n ad_group_ad_operation: {\n create: {\n ad_group: \"customers/\u003cYOUR_CUSTOMER_ID\u003e/adGroups/-2\"\n ...\n }\n }\n },\n ]\n\nA new temporary ID is used for the ad group, since we can't reuse the `-1` that\nwe used for the campaign. We also reference this ad group when creating an ad\ngroup ad. The ad group itself references the resource name we established for\nthe campaign in an earlier operation in the request, while `resource_name` in\n`ad_group_ad_operation` is not necessary since no further operation is\nreferencing it."]]