App Campaign Create Asset API questions

129 views
Skip to first unread message

Naomi Shao

unread,
Nov 19, 2019, 3:40:42 AM11/19/19
to AdWords API and Google Ads API Forum
Hi there,

I was trying to create ad group ad by referring to these docs - guide1 & guide2. I don't quite understand how to add Image and Video assets - for AdImageAsset what should i put for resource name, is it the url? And for AdVideoAsset, i tried with the youtube_video_id (11 char id), getting "RESOURCE_NAME_MALFORMED is malformed: expected \'customers/{customer_id}/assets/{part_1}\'." error. Could you please help?  Below is my code snippet and my confused part is highlighted in red. Would be great if you could provide working example.

Thanks, Naomi


AdTextAsset headline =
AdTextAsset.newBuilder()
.setText(StringValue.of(String.format("This is a headline.")))
.build();

AdTextAsset description =
AdTextAsset.newBuilder()
.setText(StringValue.of(String.format("This is a description.")))
.build();

AdVideoAsset video =
AdVideoAsset.newBuilder()
.setAsset(StringValue.of(String.format("Eq8pzzqq7xE")))
.build();


AppAdInfo appAdInfo = AppAdInfo.
newBuilder()
.addHeadlines(headline)
.addDescriptions(description)
.addYoutubeVideos(video)
.build();



// Wraps the info in an Ad object.
Ad ad =
Ad.
newBuilder()
.setAppAd(appAdInfo)
.build();

// Builds the final ad group ad representation.
AdGroupAd adGroupAd =
AdGroupAd.
newBuilder()
.setAdGroup(StringValue.
of(adGroupResourceName))
.setStatus(AdGroupAdStatusEnum.AdGroupAdStatus.
ENABLED)
.setAd(ad)
.build();

Google Ads API Forum Advisor Prod

unread,
Nov 19, 2019, 11:31:45 AM11/19/19
to adwor...@googlegroups.com
Hi Naomi, 

The error indicates that the image asset and video asset resource names are not formed correctly. You will need to use the Asset resource as part of the resource name. Please find the code snippet below:

AdVideoAsset video = AdVideoAsset.newBuilder()
.setAsset(StringValue.of(ResourceNames.asset(customerId, 6544940770L)))
.build();

AdImageAsset image = AdImageAsset.newBuilder()
.setAsset(StringValue.of(ResourceNames.asset(customerId, 27398859L)))
.build();

AppAdInfo appadinfo = AppAdInfo.newBuilder()
.addDescriptions(text)
.addAllHeadlines(ImmutableList.of(text, text1))
.addAllDescriptions(ImmutableList.of(description))
.addAllImages(ImmutableList.of(image))
.addAllYoutubeVideos(ImmutableList.of(video))
.build();

Please give this a try and let me know if you have any questions.

Thanks,
Bharani, Google Ads API Team
 

ref:_00D1U1174p._5001UOCaSg:ref

Naomi Shao

unread,
Nov 19, 2019, 9:50:55 PM11/19/19
to AdWords API and Google Ads API Forum
Hi Bharani,

Thanks for the reply. However it is still not working properly on my end. Below is the error. 
And could you pls help me understand the resource name in setAsset(StringValue.of(ResourceNames.asset(customerId, 6544940770L))), where exactly can I find the string '6544940770L'? Let's say I want to create asset with a youtube video.

Thank you,
Naomi

Response
--------
Headers: Metadata(content-type=application/grpc,request-id=JNDapajHOqzoe95NLssjHQ,x-google-esf-cloud-client-params=client_project_number: 38977083346 backend_service_name: "googleads.googleapis.com" backend_fully_qualified_method: "google.ads.googleads.v2.services.AdGroupAdService.MutateAdGroupAds" ,x-google-session-info=CNXvz9aUBxoEGBAoCzpqEhhnb29nbGVhZHMuZ29vZ2xlYXBpcy5jb20Y0q_cmZEBIkczODk3NzA4MzM0Ni1tNG1lN28yODVoNXVvNjVqYWZrampsNXJhOHNvbHY4NS5hcHBzLmdvb2dsZXVzZXJjb250ZW50LmNvbUoPOg0xLy8wZVZodTRuQW1-,date=Wed, 20 Nov 2019 02:42:21 GMT,x-google-gfe-request-trace=tlei5:443,tlac73:9832,/bns/im/borg/im/bns/adwords-simply/aw-webapi-esfproxy-prod.server/29,tlac73:9832,tlei5:443,x-google-gslb-service=adwords-frontend-webapi-esfproxy,x-google-backends=[2002:a05:681c:84::]:4232,/bns/im/borg/im/bns/adwords-simply/aw-webapi-esfproxy-prod.server/29,tlac73:9832,/bns/tl/borg/tl/bns/traffic-prod/shared-layer2-gfe/58,tlei5:443,x-google-dos-service-trace=main:adwords-frontend-webapi-esfproxy,main:shared-layer2-gfe,x-google-service=adwords-frontend-webapi-esfproxy,shared-layer2-grpc-aggregate,x-google-gfe-response-code-details-trace=response_code_set_by_backend,response_code_set_by_backend,x-google-gfe-response-body-transformations=chunked,chunked,x-google-shellfish-status=CA0gBEBG,alt-svc=quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,x-google-gfe-service-trace=adwords-frontend-webapi-esfproxy,shared-layer2-grpc-aggregate)
Body: null
Failure message: errors {
  error_code {
    collection_size_error: TOO_FEW
  }
  message: "Too few."
  trigger {
    string_value: ""
  }
  location {
    field_path_elements {
      field_name: "operations"
      index {
      }
    }
    field_path_elements {
      field_name: "create"
    }
    field_path_elements {
      field_name: "ad"
    }
    field_path_elements {
      field_name: "app_ad"
    }
    field_path_elements {
      field_name: "headlines"
    }
    field_path_elements {
      field_name: "pinned_field"
    }
  }
}
errors {
  error_code {
    mutate_error: RESOURCE_NOT_FOUND
  }
  message: "Resource was not found."
  trigger {
    string_value: ""
  }
  location {
    field_path_elements {
      field_name: "operations"
      index {
      }
    }
    field_path_elements {
      field_name: "create"
    }
    field_path_elements {
      field_name: "ad"
    }
    field_path_elements {
      field_name: "app_ad"
    }
    field_path_elements {
      field_name: "images"
      index {
      }
    }
    field_path_elements {
      field_name: "asset"
    }
  }
}
errors {
  error_code {
    mutate_error: RESOURCE_NOT_FOUND
  }
  message: "Resource was not found."
  trigger {
    string_value: ""
  }
  location {
    field_path_elements {
      field_name: "operations"
      index {
      }
    }
    field_path_elements {
      field_name: "create"
    }
    field_path_elements {
      field_name: "ad"
    }
    field_path_elements {
      field_name: "app_ad"
    }
    field_path_elements {
      field_name: "youtube_videos"
      index {
      }
    }
    field_path_elements {
      field_name: "asset"

Google Ads API Forum Advisor Prod

unread,
Nov 20, 2019, 11:13:05 AM11/20/19
to adwor...@googlegroups.com
Hi Naomi, 

You may use the Asset resource to retrieve the specific asset details. You may then use the asset Id to associate them with the ads. If you're looking to create new assets, please refer to this code snippet which might be helpful. Code snippets in other languages can be found here. Can you please give this a try replacing the assetIds? If you're facing any issue, could you please share the complete request and response using Reply privately to author option, to investigate further? 
Reply all
Reply to author
Forward
0 new messages