question

Jordan avatar image
Jordan asked

Load ad fails with error code = 0 in new Swift app. error desc = "An invalid request was sent."

I'm attempting to integrate AmazonAds with a new swift iOS app and I cannot understand why I am failing when I request an ad. My code is below. I installed the AmazonAds SDK via CocoaPods and I am using version 2.2.15.1

I basically copied the code from the SimpleAdSample sample app, and converted it to Swift. When my app loads, the main view controller waits 3 seconds then calls loadAd, but the delegate adViewDidFail is called with an error code of 0 and a message which reads "An invalid request was sent." - I've verified the app key is correct a dozen times. I've included also console log entries which look important - one of them includes a different error code than the one which was delivered to the delegate adViewDidFail:

2019-06-27 07:18:35.471319-0700 MyTestApp[51000:2941420] AmazonAd [Info]: Ad manager (0x283d038e0) received ad payload data string {"instrPixelURL":"https://aax-us-pdx.amazon-adsystem.com/x/px/p/null/","errorMessage":"INVALID_APPID","errorCode":"400","status":"error"}

This looks super important, the errorMessage says "INVALID_APPID" but again, I have verified my app key or app ID is correct - maybe I am using the wrong ID? I have included everything I can think of below. Hopefully someone here has seen this before. Thanks in advance.

AppDelegate.didFinishLaunchingWithOptions

        // setup amazon AD system
        if let awsReg = AmazonAdRegistration.shared()
        {
            awsReg.setAppKey("XXXXXXXXXXXXX")
            awsReg.setLogging(true)
        }

MyViewController.viewDidLoad

        if self.adView != nil
        {
            self.adView.removeFromSuperview()
            self.adView = nil
        }
        
        let frame = CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: 90.0)

        self.adView = AmazonAdView.init(frame: frame)
        self.adView.delegate = self
        self.adView.setHorizontalAlignment(.center)
        self.adView.setVerticalAlignment(.fitToContent)

        let options = AmazonAdOptions()
        options.isTestRequest = true
        self.adView.loadAd(option


I did not include the delegate callback functions, the "viewControllerForPresentingModalView" callback is called, and then adViewDidFail is called with the error message described above. None of the other delegates are called of course.


2019-06-27 07:18:35.218966-0700 MyTestApp[51000:2941420] AmazonAd [Info]: Ad manager (0x283d038e0) fired initial ad request.

Ad Request URL https://aax.amazon-adsystem.com/e/msdk/ads

Http headers {"User-Agent":"Mozilla\/5.0 (iPhone; CPU iPhone OS 12_1 like Mac OS X) AppleWebKit\/605.1.15 (KHTML, like Gecko) Mobile\/16B92 AmazonAdSDK-iOS\/2.2.15.1","Content-Type":"application\/json; charset=UTF-8","Accept":"application\/json"}

Http body{"isTest":"true","ats":"false","dinfo":{"make":"Apple","os":"iOS","country":"US","connectionType":"Wifi","osVersion":"12.1","model":"iPhone9,3","language":"en-US","carrier":"AT&T","orientation":"portrait","screenSize":"750x1334","scalingFactor":"2.0"},"ua":"Mozilla\/5.0 (iPhone; CPU iPhone OS 12_1 like Mac OS X) AppleWebKit\/605.1.15 (KHTML, like Gecko) Mobile\/16B92 AmazonAdSDK-iOS\/2.2.15.1","slots":[{"slot":"portrait","mxsz":"750x180","slotId":1,"sz":"auto","video":{"minAdDuration":0,"maxAdDuration":30000},"supportedMediaTypes":["DISPLAY","VIDEO"]}],"appId":"XXXXXXXXeXXXXXXXXXXXXXXXXXXXXXXX","ad-id":"A06xbMxDDED-vnhe0BpmW14","adsd

2019-06-27 07:18:35.470916-0700 MyTestApp[51000:2941420] AmazonAd [Info]: Ad view (0x283d038e0) received valid response from AAX server.

2019-06-27 07:18:35.471227-0700 MyTestApp[51000:2941420] AmazonAd [Debug]: METRIC Stop al

2019-06-27 07:18:35.471319-0700 MyTestApp[51000:2941420] AmazonAd [Info]: Ad manager (0x283d038e0) received ad payload data string {"instrPixelURL":"https://aax-us-pdx.amazon-adsystem.com/x/px/p/null/","errorMessage":"INVALID_APPID","errorCode":"400","status":"error"}


2019-06-27 07:18:35.471809-0700 MyTestApp[51000:2941420] AmazonAd [Debug]: METRIC Increment alf

2019-06-27 07:18:35.472217-0700 MyTestApp[51000:2941420] AmazonAd [Info]: MobileAdsiOSSDK_:Failure_LoadAdRequestError_amznAdSDK-ios-2.2.15.1 metric fired: https://fls-na.amazon.com/1/action-impressions/1/OE/mobile-ads-sas/action/MobileAdsiOSSDK_:Failure_LoadAdRequestError_amznAdSDK-ios-2.2.15.1?marketplaceId=583337915&requestId=583337915&session=583337915

2019-06-27 07:18:35.472799-0700 MyTestApp[51000:2941420] AmazonAd [Debug]: METRIC Increment lfre

2019-06-27 07:18:35.473245-0700 MyTestApp[51000:2941420] AmazonAd [Debug]: Ad Failed to load. Error code 0: An invalid request was sent.


Lastly, just to be sure, is this is the right App ID to pass to setAppKey? The docs seem to use the term App ID and App Key - are these the same thing? Is this the right one?

mobile adsios
amazonads-app-key.png (205.4 KiB)
1 comment
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

So, 8 hours later, and it just works now. I changed nothing since I posted the above. Who knows. I wasted at least 4 hours trying to make this work and my code was correct all along. Thanks Amazon.

0 Likes 0 ·
Levon@Amazon avatar image
Levon@Amazon answered

Hi Jordan,

I noticed that you are using an older version of SDK (2.2.15.1). There are issues with older versions, and certain versions no longer work with the ads service, that's why we always recommend using only the latest version of SDK (2.2.17.0 as of today). Please download it here: https://developer.amazon.com/sdk-download -- thanks!

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jordan avatar image
Jordan answered

I don't suppose you plan to update CocoaPods so it delivers the most recent version? As I am already set up to use the cocoa pod, it will be a pain in the ass to switch. Frankly, I dont understand why you have a CocoaPod deployment if you are not going to keep it up to date, just wasting our time basically. At least there should be a note on the Cocoa Pod page for AdmazonAd stating that you cannot get the most recent version there...

1 comment
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hi Jordan,

The Mobile Ads team is aware of this issue. In the meantime, please download the latest version manually. Thanks!

0 Likes 0 ·