epicstore_api icon indicating copy to clipboard operation
epicstore_api copied to clipboard

get_offers_data ignores first OfferData Object passed

Open PureFallen opened this issue 1 year ago • 4 comments

The current implementation of get_offers_data seems to ignore the first OfferData Object passed. This leads to the API responding with an error when only passing one argument directly or in a list (Variable x of required type y was not provided) and only returning results starting with the second object when multiple are passed within a list, as shown in the example code in the README.

Here an example with hardcoded values to reproduce the behavior:

from epicstore_api import EpicGamesStoreAPI, OfferData

if __name__ == '__main__':
    api = EpicGamesStoreAPI()

    # Doesn't work
    print(api.get_offers_data(OfferData('fn', '09176f4ff7564bbbb499bbe20bd6348f')))
    print()

    # Doesn't work
    offers = []
    offers.append(OfferData('fn', '09176f4ff7564bbbb499bbe20bd6348f'))
    print(api.get_offers_data(*offers))
    print()

    # Only returns the second offer
    offers = []
    offers.append(OfferData('fn', '09176f4ff7564bbbb499bbe20bd6348f'))
    offers.append(OfferData('bf333e6236914222a95a536389c05813', 'f6fb771bec434d1082cc419b9b4b8bfb'))
    print(api.get_offers_data(*offers))
    print()

    # Only returns starting from the second offer
    offers = []
    offers.append(OfferData('bf333e6236914222a95a536389c05813', 'f6fb771bec434d1082cc419b9b4b8bfb'))
    offers.append(OfferData('fn', '09176f4ff7564bbbb499bbe20bd6348f'))
    offers.append(OfferData('crab', '29dc519a46d341ad9abcd13d86809c8a'))
    print(api.get_offers_data(*offers))

PureFallen avatar May 04 '24 16:05 PureFallen

Ahah, I was wondering what was happening here. You are right. Here is another example.

from epicstore_api import EpicGamesStoreAPI, OfferData

api = EpicGamesStoreAPI()
offer = OfferData("9c1a74145a9145ec803d7452e80819a0", "3d74927b4c31440b999949f86b3ab6d8")
print(api.get_offers_data(offer))
{
   "errors":[
      {
         "message":"Variable \"$productNamespace\" of required type \"String!\" was not provided.",
         "locations":[
            {
               "line":2,
               "column":24
            }
         ],
         "correlationId":"f2560590-0f0d-11ef-bf17-d73754e263b0",
         "serviceResponse":"{\"errorStatus\":500}",
         "stack":"None"
      },
      {
         "message":"Variable \"$offerId\" of required type \"String!\" was not provided.",
         "locations":[
            {
               "line":2,
               "column":52
            }
         ],
         "correlationId":"f2560590-0f0d-11ef-bf17-d73754e263b0",
         "serviceResponse":"{\"errorStatus\":500}",
         "stack":"None"
      },
      {
         "message":"Variable \"$includeSubItems\" of required type \"Boolean!\" was not provided.",
         "locations":[
            {
               "line":2,
               "column":107
            }
         ],
         "correlationId":"f2560590-0f0d-11ef-bf17-d73754e263b0",
         "serviceResponse":"{\"errorStatus\":500}",
         "stack":"None"
      }
   ],
   "extensions":{
      
   }
}
print(api.get_offers_data(offer, offer))
[
   {
      "data":{
         "Catalog":{
            "catalogOffer":{
               "title":"Fallout 4",
               "id":"3d74927b4c31440b999949f86b3ab6d8",
               "namespace":"9c1a74145a9145ec803d7452e80819a0",
               "description":"As the sole survivor of Vault 111, do whatever you want in a massive open world Commonwealth with hundreds of locations, characters and quests. Welcome home to Fallout 4, from Bethesda Game Studios, the award-winning creators of The Elder Scrolls V: Skyrim.",
               "effectiveDate":"2024-04-25T14:00:00.000Z",
               "expiryDate":"None",
               "isCodeRedemptionOnly":false,
               "keyImages":[
                  {
                     "type":"OfferImageTall",
                     "url":"https://cdn1.epicgames.com/offer/9c1a74145a9145ec803d7452e80819a0/EGS_Fallout4_BethesdaGameStudios_S2_1200x1600-2b307b78180f2a6a2dc89ab1c20b3c1b"
                  },
                  {
                     "type":"OfferImageWide",
                     "url":"https://cdn1.epicgames.com/offer/9c1a74145a9145ec803d7452e80819a0/EGS_Fallout4_BethesdaGameStudios_S1_2560x1440-fb0e82fa71a74e750c95b57b91fc558d"
                  },
                  {
                     "type":"Thumbnail",
                     "url":"https://cdn1.epicgames.com/offer/9c1a74145a9145ec803d7452e80819a0/EGS_Fallout4_BethesdaGameStudios_S2_1200x1600-2b307b78180f2a6a2dc89ab1c20b3c1b"
                  }
               ],
               "seller":{
                  "id":"o-bthbhn6wd7fzj73v5p4436ucn3k37u",
                  "name":"Bethesda Softworks LLC"
               },
               "productSlug":"fallout-4",
               "urlSlug":"fallout-4",
               "url":"None",
               "tags":[
                  {
                     "id":"21122"
                  },
                  {
                     "id":"21894"
                  },
                  {
                     "id":"1367"
                  },
                  {
                     "id":"19847"
                  },
                  {
                     "id":"1307"
                  },
                  {
                     "id":"21147"
                  },
                  {
                     "id":"9547"
                  }
               ],
               "items":[
                  {
                     "id":"9cf98c9fdec24dfc8b092aad789ef55d",
                     "namespace":"9c1a74145a9145ec803d7452e80819a0"
                  }
               ],
               "customAttributes":[
                  {
                     "key":"com.epicgames.app.productSlug",
                     "value":"fallout-4"
                  }
               ],
               "categories":[
                  {
                     "path":"games"
                  },
                  {
                     "path":"games/edition"
                  },
                  {
                     "path":"games/edition/base"
                  },
                  {
                     "path":"applications"
                  }
               ],
               "price":{
                  "totalPrice":{
                     "discountPrice":1999,
                     "originalPrice":1999,
                     "voucherDiscount":0,
                     "discount":0,
                     "currencyCode":"USD",
                     "currencyInfo":{
                        "decimals":2
                     },
                     "fmtPrice":{
                        "originalPrice":"$19.99",
                        "discountPrice":"$19.99",
                        "intermediatePrice":"$19.99"
                     }
                  },
                  "lineOffers":[
                     {
                        "appliedRules":[
                           
                        ]
                     }
                  ]
               }
            }
         }
      },
      "extensions":{
         
      }
   }
]

woctezuma avatar May 10 '24 20:05 woctezuma

I can fix this error.

woctezuma avatar May 11 '24 13:05 woctezuma

Done in my pull request:

  • #25 for refurbishment along the fix
  • #26 for the fix only

woctezuma avatar May 11 '24 13:05 woctezuma

Merged two PRs from woctezuma. PyPI version was updated accordingly.

Should work now.

SD4RK avatar May 16 '24 15:05 SD4RK