Ads Script newImageBuilder() "Invalid input: image/jpeg" Error using New Scripts Experience

215 views
Skip to first unread message

James Anderson

unread,
Nov 3, 2022, 1:00:29 PM11/3/22
to Google Ads Scripts Forum
Issue
When getting image data from an image in Google Drive and then attempting to build the adMedia I get the following error:

Invalid input: image/jpeg.
Expected (optional) one of ["UNSPECIFIED","UNKNOWN","IMAGE_JPEG","IMAGE_GIF","IMAGE_PNG","FLASH","TEXT_HTML","PDF","MSWORD","MSEXCEL","RTF","AUDIO_WAV","AUDIO_MP3","HTML5_AD_ZIP"]

Section of Code that applies to this error
        newImageFound = true;
        imageFile = driveFiles.next();
        imageName = imageFile.getName();
        imageSizeString = imageName.replace(currentMemberNumber + "_", '').split('.')[0];

        imageSizeIndex = imageSizes.indexOf(imageSizeString);

        if (imageSizeIndex === -1) {
            // this is an excess image
            continue;
        }

        imageBlob = imageFile.getBlob();

        try {
            var mediaOperation = AdWordsApp.adMedia().newImageBuilder()
                .withName(imageSizes[imageSizeIndex])
                .withData(imageBlob)
                .build();
        } catch (e) {
            errors.push("Fatal: Ad Media for " + imageName + " ("+ imageSizes[imageSizeIndex] + ") could not be built (" + e.message + "[L" + e.lineNumber + "])");

            return {
                Success: false,
                Errors: errors,
                Message: '',
                MemberNumber: currentMemberNumber
            };
        }

Additional Test
I used imageBlob.setContentType("IMAGE_JPEG") and an error wasn't thrown for the build() operation but the mediaOperation contains the following errors object

["An internal error has occurred. ({\"errorCode\":{\"internalError\":\"INTERNAL_ERROR\"},\"message\":\"An internal error has occurred.\",\"trigger\":{\"stringValue\":\"\"},\"location\":{\"fieldPathElements\":[{\"fieldName\":\"mutate_operations\",\"index\":0},{\"fieldName\":\"media_file_operation\"}]}})"]

Additional Details
  • The script runs fine when "new scripts experience" is turned off.
  • CID: 288-911-7548
  • Script Name: Bulk Image Update (New scripts experience)
Not sure what to test next?

Google Ads Scripts Forum

unread,
Nov 10, 2022, 3:28:42 AM11/10/22
to Google Ads Scripts Forum
Reposting the last inquiry (https://groups.google.com/g/adwords-scripts/c/eEvzWvNa1Ps) from the forum as it wasn't routed to our support queue. 

Cheers, 
James
Google Ads Scripts Team

James Anderson

unread,
Nov 28, 2022, 9:31:39 AM11/28/22
to Google Ads Scripts Forum
This issue still exists and I am following up to see if anyone can help?

James Anderson

unread,
Dec 5, 2022, 1:58:37 PM12/5/22
to Google Ads Scripts Forum
I created a new script (DEV Image Builder) and used the Add an Image Ad Example and it threw the following error:

InputError: Invalid input: image/jpeg.
Expected (optional) one of ["UNSPECIFIED","UNKNOWN","IMAGE_JPEG","IMAGE_GIF","IMAGE_PNG","FLASH","TEXT_HTML","PDF","MSWORD","MSEXCEL","RTF","AUDIO_WAV","AUDIO_MP3","HTML5_AD_ZIP"]
    at Na.check (adsapp_compiled:403:11)
    at rq.withData (adsapp_compiled:7195:61)
    at Object.<anonymous> (adsapp_compiled:19246:54)

Google Ads Scripts Forum Advisor

unread,
Dec 6, 2022, 1:50:09 AM12/6/22
to adwords...@googlegroups.com

Hello James,

Thank you for reaching out to us.

Upon checking your given script, I observed that you implemented our Large Manager Hierarchy Template which is built for the Legacy version of script and you’re executing it using the new script experience version. Take note that running our Large Manager Hierarchy Template solution script which is built for the legacy version in the new script experience environment is expected to encounter any errors or unusual behaviors because there are some code functionalities that are no longer compatible with the new script experience version. Instead, can you please use this latest Large Manager Hierarchy Template which is now built for the new script experience environment and let me know if you will still encounter the same issue or behavior?

Regards,

Google Logo
James Howell
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2gir1l:ref

James Anderson

unread,
Dec 6, 2022, 6:36:53 AM12/6/22
to Google Ads Scripts Forum
Thank you I will look into the new version.

Sadly, as mentioned in my message from yesterday (Dec 5, 2022, 1:58:37 PM), making that update won't resolve the issue because I created a new script named DEV Image Builder. It doesn't use Large Manager Hierarchy Template and still has the same error.

James Anderson

unread,
Dec 6, 2022, 12:56:31 PM12/6/22
to Google Ads Scripts Forum
I have updated the script named "Bulk Image Update (New scripts experience)" with the changes from the new Large Manager Hierarchy Template and am still getting the same error(s) as before.

James Anderson

unread,
Dec 6, 2022, 2:07:27 PM12/6/22
to Google Ads Scripts Forum
Also Note, the Large Manager Hierarchy Template may have a bug: I had to add "stateManager = new StateManager();" to "function parallelCallback()" because "stateManager.loadState();" was an undefined object and the script could not complete.

Google Ads Scripts Forum Advisor

unread,
Dec 7, 2022, 2:30:20 AM12/7/22
to adwords...@googlegroups.com

Hello James,

Thank you for your clarification. I tested your script and I was able to replicate the same issue on my end. Having said that, I’ll be raising this issue to our internal team for further investigation and troubleshooting. For any updates, we will keep this thread posted.

Regards,

Google Ads Scripts Forum Advisor

unread,
Dec 7, 2022, 5:03:32 AM12/7/22
to adwords...@googlegroups.com

Hello,

Upon utilizing this line of code – imageBlob.setContentType("IMAGE_JPEG"), could you confirm if you’re only experiencing the internal error upon previewing your script? If yes, can you please try to actually run your script and observe if the same issue will persist? 

I asked this because based on my further investigation, I was able to execute the newImageBuilder and able to add a new image ad successfully when I run the script. The reason behind this is because there’s a key difference between the preview modes in the legacy infra and the new new script experience, whereas the legacy version did not do any validation (it would just assume the changes would succeed) whereas the new experience relies on Google Ads API validate-only mode. That’s the reason why it works as expected in the Legacy version.

On the other hand, the team is still looking if it’s possible to implement the same behavior in the preview mode of the new script experience. Still, we will keep this thread posted for any updates.

Regards,

James Anderson

unread,
Dec 7, 2022, 11:51:03 AM12/7/22
to Google Ads Scripts Forum
With the code - imageBlob.setContentType("IMAGE_JPEG") - enabled and when I Run instead of Preview the script the newImageBuilder succeeds. I will have to add in other Image mime types in order to make sure all types are accounted for.

I ran into some other errors I was able to resolve as they were syntax errors but it was a pain because they only happen during Run and the line numbers are part of "adsapp_compiled" so I don't know which line of my script is causing the issue. Case in point I'm still getting an error but I don't know what it means (and if I need to start a new thread for this error please let me know since my original issue is resolved)

Bulk Image Update (New scripts experience)
12/7/2022 11:02:08 AM
Error: Not implemented yet.
    at Object.a (adsapp_compiled:7065:13)
    at Object.<anonymous> (adsapp_compiled:19246:54)

I was able to track this down to getDimensions() being deprecated [ OldImageAd.getImage().getDimensions().getFullDimensions() ] - is there a replacement for this?

Google Ads Scripts Forum Advisor

unread,
Dec 8, 2022, 1:00:49 AM12/8/22
to adwords...@googlegroups.com

Hello James,

I’m glad that I was able to resolve your initial issue. However, I’m still checking with the team if it's possible to implement the same behavior in the preview mode of the new script experience, so that testing can be easily executed. 

On the other hand, regarding your new issue with the getDimension method, I’ll be checking this also to our internal team. Rest assured that we will update this thread for any updates.

Regards,

James Anderson

unread,
Dec 8, 2022, 8:57:38 AM12/8/22
to Google Ads Scripts Forum
Thank you

I have found an additional issue with Large Manager Hierarchy Template
Statuses.IN_PROGRESS is referenced in setStatus() but it doesn't exist anywhere else in the code

Google Ads Scripts Forum Advisor

unread,
Dec 9, 2022, 1:40:17 AM12/9/22
to adwords...@googlegroups.com

Hello James,

Would you be able to provide more context about the additional issue you have encountered with our Large Manager Hierarchy Template solutions script so that we can have a clear understanding and so that we can check this properly? It would be helpful also if you can share screenshots via Reply privately to the author option.

Regards, 

James Anderson

unread,
Dec 9, 2022, 8:07:52 AM12/9/22
to Google Ads Scripts Forum
I cannot "reply to author" (the button is disabled) but it's fairly obvious just by visiting the page for the Large Manager Hierarchy Template - when you search the page for "IN_PROGRESS" it only appears once, and it's never defined in the Statuses object (screenshots attached). The same exists in the code copied from that page. It doesn't through an error but the code may not be functioning as intended.

It was never 100% confirmed you saw my first issue with this this script (attaching screenshot of this as well - i commented out the line I added to simulate the original LMHT code):
Also Note, the Large Manager Hierarchy Template may have a bug: I had to add "stateManager = new StateManager();" to "function parallelCallback()" because "stateManager.loadState();" was an undefined object and the script could not complete.

Large Manager Hierarchy Template IN_PROGRESS 01.png
Reply to Author Disabled.png
Large Manager Hierarchy Template stateManager02.png
Large Manager Hierarchy Template stateManager 01.png
Large Manager Hierarchy Template IN_PROGRESS 02.png

Google Ads Scripts Forum Advisor

unread,
Dec 13, 2022, 4:49:32 AM12/13/22
to adwords...@googlegroups.com

Hello James,

Thank you for providing additional information and screenshots. I already also raised this issue to our team. For any updates, rest assured that we will get back to you as soon as we have information.

Regards,

Reply all
Reply to author
Forward
0 new messages