Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

After uploading an asset using the API, it is not possible to query it through the API.

25 views
Skip to first unread message

xiaochuan li

unread,
Apr 18, 2025, 12:15:48 AMApr 18
to Google Ads API and AdWords API Forum
I uploaded some images to asset using the api. I followed `https://developers.google.com/google-ads/api/docs/assets/working-with-assets` to upload images. The API successfully returned `resource_name`, but I cannot query this asset in the ui or through `https://developers.google.com/google-ads/api/fields/v19/asset_query_builder`. Why is this?

This is the code I wrote to upload the image
```python
def create_image_asset():
    customer_id = "xxxxxxx"
    image_url = 'https://xxxxx.jpg'
    width_pixels = 160
    height_pixels = 600
    image_name = '250404-160-600.jpg'

    response = requests.get(image_url)
    image_content = response.content
    mime_type = response.headers['Content-Type']

    client = GoogleAdsClient.load_from_storage(client_path, version="v17")
    asset_service = client.get_service("AssetService")
    asset_operation = client.get_type("AssetOperation")
    asset = asset_operation.create
    asset.type_ = client.enums.AssetTypeEnum.IMAGE
    asset.image_asset.data = image_content
    asset.image_asset.file_size = len(image_content)
    if mime_type == 'image/jpeg':
        asset.image_asset.mime_type = client.enums.MimeTypeEnum.IMAGE_JPEG
    elif mime_type == 'image/png':
        asset.image_asset.mime_type = client.enums.MimeTypeEnum.IMAGE_PNG
    elif mime_type == 'image/gif':
        asset.image_asset.mime_type = client.enums.MimeTypeEnum.IMAGE_GIF
    else:
        asset.image_asset.mime_type = client.enums.MimeTypeEnum.UNSPECIFIED
    asset.image_asset.full_size.width_pixels = width_pixels
    asset.image_asset.full_size.height_pixels = height_pixels
    asset.name = image_name

    mutate_asset_response = asset_service.mutate_assets(
        customer_id=str(customer_id), operations=[asset_operation]
    )
    print(f'mutate_asset_response: {mutate_asset_response}')
```
Here is the return value of this code: `mutate_asset_response: results {
resource_name: "customers/xxxxx/assets/225688809944"
}`

I used this query, but couldn't get any information.
query = f"""
    SELECT
      asset.id,
      asset.image_asset.file_size,
      asset.image_asset.full_size.height_pixels,
      asset.image_asset.full_size.url,
      asset.image_asset.full_size.width_pixels,
      asset.image_asset.mime_type
    FROM asset
    """

PixPin_2025-04-18_12-14-59.pngPixPin_2025-04-18_12-14-36.png

Google Ads API Forum Advisor

unread,
Apr 18, 2025, 2:13:46 AMApr 18
to clixia...@gmail.com, adwor...@googlegroups.com

Hi,

Thank you for contacting the Google Ads API support team.

Upon reviewing your concern, I understand that you have uploaded image assets to your Google Ads account using the Google Ads API and now you are trying to retrieve those image assets using the Google Ads API. 

In order to investigate this issue, please provide your Google Ads customer Id and complete API logs (request and response with request-id and request header) generated at your end while uploading the image asset and while retrieving the image asset without redacting any information.

I understand that you are using the Python client library. So, if you haven't enabled the logging yet, I would request you to enable logging for the Python client library. You can refer to the guide Python to enable logging at your end. For REST interface requests, you can enable logging via the curl command by using the -i flag.

You can send the details via Reply privately to the author option, or direct private reply to this email.

Thanks,
 
Google Logo Google Ads API Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5
[2025-04-18 06:13:00Z GMT] This message is in relation to case "ref:!00D1U01174p.!500Ht01qUHff:ref" (ADR-00300394)



xiaochuan li

unread,
Apr 18, 2025, 2:41:15 AMApr 18
to Google Ads API and AdWords API Forum
Sorry, it was my mistake. My code was wrong and I couldn't get the asset information normally. I have solved it.
Reply all
Reply to author
Forward
0 new messages