ScaleLeap / amazon-advertising-api-sdk

Amazon Advertising API TypeScript and Node.js Unofficial SDK
https://npm.im/@scaleleap/amazon-advertising-api-sdk
MIT License
27 stars 21 forks source link

Error when requesting all sponsored brands campaigns. #748

Closed matthew-r-clark closed 3 years ago

matthew-r-clark commented 3 years ago

I'm receiving the following error whenever requesting all campaigns for sponsored brands via: new AmazonAdvertising(marketplace, auth).sponsoredBrandsCampaign.listCampaigns()

error: DecodeError: Invalid value undefined supplied to : Array<{| portfolioId:
     number, campaignId: Readonly<number>, name: string, budget: number, budget
    Type: ("lifetime" | "daily"), startDate: string, endDate: string, state: ("
    enabled" | "paused" | "archived"), servingStatus: Readonly<("asinNotBuyable
    " | "billingError" | "ended" | "landingPageNotAvailable" | "outOfBudget" | 
    "paused" | "pendingReview" | "ready" | "rejected" | "running" | "scheduled"
     | "terminated")>, brandEntityId: string, bidOptimization: boolean, bidMult
    iplier: number, creative: {| brandName: string, brandLogoAssetID: string, b
    randLogoUrl: Readonly<string>, headline: string, asins: Array<string> |}, l
    andingPage: ("productList" | "store" | "customUrl"), keywords: ({| keywordT
    ext: string, matchType: ("broad" | "exact" | "phrase") |} & Partial<{ bid: 
    number }>) |}>/0: {| portfolioId: number, campaignId: Readonly<number>, nam
    e: string, budget: number, budgetType: ("lifetime" | "daily"), startDate: s
    tring, endDate: string, state: ("enabled" | "paused" | "archived"), serving
    Status: Readonly<("asinNotBuyable" | "billingError" | "ended" | "landingPag
    eNotAvailable" | "outOfBudget" | "paused" | "pendingReview" | "ready" | "re
    jected" | "running" | "scheduled" | "terminated")>, brandEntityId: string, 
    bidOptimization: boolean, bidMultiplier: number, creative: {| brandName: st
    ring, brandLogoAssetID: string, brandLogoUrl: Readonly<string>, headline: s
    tring, asins: Array<string> |}, landingPage: ("productList" | "store" | "cu
    stomUrl"), keywords: ({| keywordText: string, matchType: ("broad" | "exact"
     | "phrase") |} & Partial<{ bid: number }>) |}/endDate: string

at new DecodeError (/app/node_modules/io-ts-promise/lib/index.js:55:28)
at /app/node_modules/io-ts-promise/lib/index.js:37:76
at /app/node_modules/fp-ts/lib/Either.js:245:57
at Object.decode (/app/node_modules/io-ts-promise/lib/index.js:37:171)
at /app/node_modules/@scaleleap/amazon-advertising-api-sdk/lib/decorators.js:34:97
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async /app/lib/node_modules/@@routes/amazon-adv-snaphots.js:18:31

However, whenever I request all campaigns for sponsored products or sponsored displays, it works as expected.

For all three (brands, products, and displays), I've used the respective module's listCampaigns() method, which all seem to take optional arguments for filtering results. In my usage, I'm not passing an argument into any of the listCampaigns() calls.

Here is a sample of the code which results in this error:

const {amazonMarketplaces, assertMarketplaceHasAdvertising} = require('@scaleleap/amazon-marketplaces');
const {AmazonAdvertising} = require('@scaleleap/amazon-advertising-api-sdk');
const {getHttpClientAuth} = require('./auth');
const marketplace = amazonMarketplaces.US;
assertMarketplaceHasAdvertising(marketplace);

const getCampaigns = async () => {
    try {
        const amazonAdvertising = new AmazonAdvertising(marketplace, await getHttpClientAuth());
        const sponsoredBrandCampaignOperation = amazonAdvertising.sponsoredBrandsCampaign;
        return sponsoredBrandCampaignOperation.listCampaigns();
    } catch (err) {
        console.error(err);
    }
};

I also tried hitting the amazon advertising api directly (https://advertising-api.amazon.com/sb/campaigns) and successfully received the sponsored brands campaigns in the response body.

moltar commented 3 years ago

Hi @matthew-r-clark, could you please post the responses from the API, when you are hitting the API directly.

Ofc, please delete any sensitive data.

It looks like there is some undocumented data difference in these responses, potentially and our validator is missing that.

matthew-r-clark commented 3 years ago

Thank you for following up, @moltar!

Here is the response that I'm getting from https://advertising-api.amazon.com/sb/campaigns

[
    {
        "name": "[brand] Store.Image",
        "budget": 200.0,
        "bidOptimization": true,
        "portfolioId": --portfolioId--,
        "adFormat": "productCollection",
        "campaignId": --campaignId--,
        "budgetType": "daily",
        "startDate": "20210309",
        "state": "enabled",
        "servingStatus": "running",
        "creative": {
            "brandName": --brandName--,
            "brandLogoAssetID": "amzn1.assetlibrary.asset1.edbceb790b7a538eb4ec2509b7e14fa5:version_v1",
            "headline": --headline--,
            "shouldOptimizeAsins": false,
            "asins": [
                "B07H8NS5MS"
            ],
            "brandLogoUrl": --brandLogoUrl--
        },
        "landingPage": {
            "pageType": "store",
            "url": --landingPageUrl--
        }
    },
    {
        "name": "[brand] Store.Product",
        "budget": 800.0,
        "bidOptimization": false,
        "bidMultiplier": -95.0,
        "portfolioId": --portfolioId--,
        "adFormat": "productCollection",
        "campaignId": --campaignId--,
        "budgetType": "daily",
        "startDate": "20210312",
        "state": "enabled",
        "servingStatus": "running",
        "creative": {
            "brandName": --brandName--,
            "brandLogoAssetID": "amzn1.assetlibrary.asset1.edbceb790b7a538eb4ec2509b7e14fa5:version_v1",
            "headline": --headline--,
            "shouldOptimizeAsins": false,
            "asins": [
                "B07H8NS5MS"
            ],
            "brandLogoUrl": --brandLogoUrl--
        },
        "landingPage": {
            "pageType": "store",
            "url": --landingPageUrl--
        }
    },
    {
        "name": "[brand] Store.Image_DEV",
        "budget": 50.0,
        "bidOptimization": true,
        "portfolioId": --portfolioId--,
        "adFormat": "productCollection",
        "campaignId": --campaignId--,
        "budgetType": "daily",
        "startDate": "20210402",
        "state": "paused",
        "servingStatus": "paused",
        "creative": {
            "brandName": --brandName--,
            "brandLogoAssetID": "amzn1.assetlibrary.asset1.edbceb790b7a538eb4ec2509b7e14fa5:version_v1",
            "headline": --headline--,
            "shouldOptimizeAsins": false,
            "asins": [
                "B07H8NS5MS"
            ],
            "brandLogoUrl": --brandLogoUrl--
        },
        "landingPage": {
            "pageType": "store",
            "url": --landingPageUrl--
        }
    },
    {
        "name": "Brand Video Campaign",
        "budget": 40.0,
        "adFormat": "video",
        "campaignId": --campaignId--,
        "budgetType": "daily",
        "startDate": "20200729",
        "state": "paused",
        "servingStatus": "paused",
        "creative": {
            "asins": [
                "B07H8NS5MS"
            ],
            "videoMediaIds": [
                "amzn1.adex.media1.b93c1a17-d818-4eb3-90fd-3713580c7c5f"
            ],
            "type": "video"
        },
        "landingPage": {
            "pageType": "detailPage",
            "url": --landingPageUrl--
        }
    },
    {
        "name": "Campaign - 9/23/2020 15:26:16",
        "budget": 150.0,
        "portfolioId": --portfolioId--,
        "adFormat": "video",
        "campaignId": --campaignId--,
        "budgetType": "daily",
        "startDate": "20200923",
        "state": "paused",
        "servingStatus": "paused",
        "creative": {
            "asins": [
                "B07H8NS5MS"
            ],
            "videoMediaIds": [
                "amzn1.adex.media1.18f85b0c-5c32-4320-9b58-d4aa9a252d1b"
            ],
            "type": "video"
        },
        "landingPage": {
            "pageType": "detailPage",
            "url": --landingPageUrl--
        }
    },
    {
        "name": "Video",
        "budget": 150.0,
        "portfolioId": --portfolioId--,
        "adFormat": "video",
        "campaignId": --campaignId--,
        "budgetType": "daily",
        "startDate": "20210305",
        "state": "paused",
        "servingStatus": "paused",
        "creative": {
            "asins": [
                "B07H8NS5MS"
            ],
            "videoMediaIds": [
                "amzn1.adex.media1.18f85b0c-5c32-4320-9b58-d4aa9a252d1b"
            ],
            "type": "video"
        },
        "landingPage": {
            "pageType": "detailPage",
            "url": --landingPageUrl--
        }
    },
    {
        "name": "Video v2",
        "budget": 200.0,
        "portfolioId": --portfolioId--,
        "adFormat": "video",
        "campaignId": --campaignId--,
        "budgetType": "daily",
        "startDate": "20210319",
        "state": "enabled",
        "servingStatus": "running",
        "creative": {
            "asins": [
                "B07H8NS5MS"
            ],
            "videoMediaIds": [
                "amzn1.adex.media1.65782f90-9b18-4400-9b09-45d22d7a2fb3"
            ],
            "type": "video"
        },
        "landingPage": {
            "pageType": "detailPage",
            "url": --landingPageUrl--
        }
    },
    {
        "name": "Video v3",
        "budget": 400.0,
        "portfolioId": --portfolioId--,
        "adFormat": "video",
        "campaignId": --campaignId--,
        "budgetType": "daily",
        "startDate": "20210330",
        "state": "enabled",
        "servingStatus": "running",
        "creative": {
            "asins": [
                "B07H8NS5MS"
            ],
            "videoMediaIds": [
                "amzn1.adex.media1.d0938098-2c53-4c53-84fe-d66e80564f57"
            ],
            "type": "video"
        },
        "landingPage": {
            "pageType": "detailPage",
            "url": --landingPageUrl--
        }
    }
]
github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 3.1.15 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

matthew-r-clark commented 3 years ago

@moltar, thank you so much for the quick response!

However, it appears after installing the updated package, the issue persists.

I was checking the request params within the scaleleap package and it appears it is sending the request to the wrong amazon api endpoint.

This is what I'm seeing in my console when I test it: image

And this is what's in the amazon documentation: image

matthew-r-clark commented 3 years ago

I was checking the two amazon api endpoints directly to see what the difference in response data was.

I get this for https://advertising-api.amazon.com/v2/hsa/campaigns:

[
    {
        "campaignId": --campaignId--,
        "name": "[brand] Store.Image",
        "budget": 200.0,
        "budgetType": "daily",
        "startDate": "20210309",
        "state": "enabled",
        "servingStatus": "running",
        "spendingPolicy": "asap",
        "portfolioId": --portfolioId--,
        "bidOptimization": true
    },
    {
        "campaignId": --campaignId--,
        "name": "[brand] Store.Product",
        "budget": 800.0,
        "budgetType": "daily",
        "startDate": "20210312",
        "state": "enabled",
        "servingStatus": "running",
        "spendingPolicy": "asap",
        "portfolioId": --portfolioId--,
        "bidOptimization": false,
        "bidMultiplier": -95.0
    },
    {
        "campaignId": --campaignId--,
        "name": "[brand] Store.Image_DEV",
        "budget": 50.0,
        "budgetType": "daily",
        "startDate": "20210402",
        "state": "paused",
        "servingStatus": "paused",
        "spendingPolicy": "asap",
        "portfolioId": --portfolioId--,
        "bidOptimization": true
    }
]

And then this for https://advertising-api.amazon.com/sb/campaigns (should be the same as what I sent previously):

[
    {
        "name": "[brand] Store.Image",
        "budget": 200.0,
        "bidOptimization": true,
        "portfolioId": --portfolioId--,
        "adFormat": "productCollection",
        "campaignId": --campaignId--,
        "budgetType": "daily",
        "startDate": "20210309",
        "state": "enabled",
        "servingStatus": "running",
        "creative": {
            "brandName": --brandName--,
            "brandLogoAssetID": "amzn1.assetlibrary.asset1.edbceb790b7a538eb4ec2509b7e14fa5:version_v1",
            "headline": --headline--,
            "shouldOptimizeAsins": false,
            "asins": [
                "B07H8NS5MS"
            ],
            "brandLogoUrl": --brandLogoUrl--
        },
        "landingPage": {
            "pageType": "store",
            "url": --landingPageUrl--
        }
    },
    {
        "name": "[brand] Store.Product",
        "budget": 800.0,
        "bidOptimization": false,
        "bidMultiplier": -95.0,
        "portfolioId": --portfolioId--,
        "adFormat": "productCollection",
        "campaignId": --campaignId--,
        "budgetType": "daily",
        "startDate": "20210312",
        "state": "enabled",
        "servingStatus": "running",
        "creative": {
            "brandName": --brandName--,
            "brandLogoAssetID": "amzn1.assetlibrary.asset1.edbceb790b7a538eb4ec2509b7e14fa5:version_v1",
            "headline": --headline--,
            "shouldOptimizeAsins": false,
            "asins": [
                "B07H8NS5MS"
            ],
            "brandLogoUrl": --brandLogoUrl--
        },
        "landingPage": {
            "pageType": "store",
            "url": --landingPageUrl--
        }
    },
    {
        "name": "[brand] Store.Image_DEV",
        "budget": 50.0,
        "bidOptimization": true,
        "portfolioId": --portfolioId--,
        "adFormat": "productCollection",
        "campaignId": --campaignId--,
        "budgetType": "daily",
        "startDate": "20210402",
        "state": "paused",
        "servingStatus": "paused",
        "creative": {
            "brandName": --brandName--,
            "brandLogoAssetID": "amzn1.assetlibrary.asset1.edbceb790b7a538eb4ec2509b7e14fa5:version_v1",
            "headline": --headline--,
            "shouldOptimizeAsins": false,
            "asins": [
                "B07H8NS5MS"
            ],
            "brandLogoUrl": --brandLogoUrl--
        },
        "landingPage": {
            "pageType": "store",
            "url": --landingPageUrl--
        }
    },
    {
        "name": "Brand Video Campaign",
        "budget": 40.0,
        "adFormat": "video",
        "campaignId": --campaignId--,
        "budgetType": "daily",
        "startDate": "20200729",
        "state": "paused",
        "servingStatus": "paused",
        "creative": {
            "asins": [
                "B07H8NS5MS"
            ],
            "videoMediaIds": [
                "amzn1.adex.media1.b93c1a17-d818-4eb3-90fd-3713580c7c5f"
            ],
            "type": "video"
        },
        "landingPage": {
            "pageType": "detailPage",
            "url": --landingPageUrl--
        }
    },
    {
        "name": "Campaign - 9/23/2020 15:26:16",
        "budget": 150.0,
        "portfolioId": --portfolioId--,
        "adFormat": "video",
        "campaignId": --campaignId--,
        "budgetType": "daily",
        "startDate": "20200923",
        "state": "paused",
        "servingStatus": "paused",
        "creative": {
            "asins": [
                "B07H8NS5MS"
            ],
            "videoMediaIds": [
                "amzn1.adex.media1.18f85b0c-5c32-4320-9b58-d4aa9a252d1b"
            ],
            "type": "video"
        },
        "landingPage": {
            "pageType": "detailPage",
            "url": --landingPageUrl--
        }
    },
    {
        "name": "Video",
        "budget": 150.0,
        "portfolioId": --portfolioId--,
        "adFormat": "video",
        "campaignId": --campaignId--,
        "budgetType": "daily",
        "startDate": "20210305",
        "state": "paused",
        "servingStatus": "paused",
        "creative": {
            "asins": [
                "B07H8NS5MS"
            ],
            "videoMediaIds": [
                "amzn1.adex.media1.18f85b0c-5c32-4320-9b58-d4aa9a252d1b"
            ],
            "type": "video"
        },
        "landingPage": {
            "pageType": "detailPage",
            "url": --landingPageUrl--
        }
    },
    {
        "name": "Video v2",
        "budget": 200.0,
        "portfolioId": --portfolioId--,
        "adFormat": "video",
        "campaignId": --campaignId--,
        "budgetType": "daily",
        "startDate": "20210319",
        "state": "enabled",
        "servingStatus": "running",
        "creative": {
            "asins": [
                "B07H8NS5MS"
            ],
            "videoMediaIds": [
                "amzn1.adex.media1.65782f90-9b18-4400-9b09-45d22d7a2fb3"
            ],
            "type": "video"
        },
        "landingPage": {
            "pageType": "detailPage",
            "url": --landingPageUrl--
        }
    },
    {
        "name": "Video v3",
        "budget": 400.0,
        "portfolioId": --portfolioId--,
        "adFormat": "video",
        "campaignId": --campaignId--,
        "budgetType": "daily",
        "startDate": "20210330",
        "state": "enabled",
        "servingStatus": "running",
        "creative": {
            "asins": [
                "B07H8NS5MS"
            ],
            "videoMediaIds": [
                "amzn1.adex.media1.d0938098-2c53-4c53-84fe-d66e80564f57"
            ],
            "type": "video"
        },
        "landingPage": {
            "pageType": "detailPage",
            "url": --landingPageUrl--
        }
    }
]

The incorrect endpoint is not returning any arrays, which seems to be the likely reason why we are receiving that original error message. Also fyi, I'm not sure how the scaleleap package determines the api version (v2) and if this is always included, but if I try sending a GET request to https://advertising-api.amazon.com/v2/sb/campaigns, it returns a NOT_FOUND error.

moltar commented 3 years ago

Also fyi, I'm not sure how the scaleleap package determines the api version (v2) and if this is always included, but if I try sending a GET request to https://advertising-api.amazon.com/v2/sb/campaigns, it returns a NOT_FOUND error.

Their API organization is a huge mess and the version is not always included.

So it all depends on which version of the API you are looking at.

It appears that SB has been switched to v3 already, and we do not have support for that.

There is the API version switch at the top left, if you want to see the old docs.

We don't have the capacity to add this at the moment. If you wish to create a PR and migrate to v3 of SB API, we'll happily accept it.

NishealJ commented 3 years ago

@moltar I get this for list campaigns? can we move the landingPage attribute to partials instead of strict?

  {
      campaignId: ---campaignId-----,
      name: ' ---campaign_name-----',
      budget: 100,
      budgetType: 'daily',
      startDate: '20190612',
      state: 'paused',
      servingStatus: 'paused',
      spendingPolicy: 'asap',
      bidOptimization: true
    },
moltar commented 3 years ago

@NishealJ sure, please send a PR. Thanks