I'm trying to get a list of offers for an item sold on opensea.io
def getHighestOffer(self):
query = """query OrdersQuery(\n $cursor: String\n $count: Int = 10\n $excludeMaker: IdentityInputType\n $isExpired: Boolean\n $isFilled: Boolean\n $isValid: Boolean\n $maker: IdentityInputType\n $makerArchetype: ArchetypeInputType\n $makerAssetIsPayment: Boolean\n $takerArchetype: ArchetypeInputType\n $takerAssetCategories: [CollectionSlug!]\n $takerAssetCollections: [CollectionSlug!]\n $takerAssetIsOwnedBy: IdentityInputType\n $takerAssetIsPayment: Boolean\n $sortAscending: Boolean\n $sortBy: OrderSortOption\n $makerAssetBundle: BundleSlug\n $takerAssetBundle: BundleSlug\n) {\n ...Orders_data_2g7x2d\n}\n\nfragment AccountLink_data on AccountType {\n address\n chain {\n identifier\n id\n }\n user {\n publicUsername\n id\n }\n ...ProfileImage_data\n ...wallet_accountKey\n}\n\nfragment AskPrice_data on OrderV2Type {\n dutchAuctionFinalPrice\n openedAt\n priceFnEndedAt\n makerAssetBundle {\n assetQuantities(first: 30) {\n edges {\n node {\n ...quantity_data\n id\n }\n }\n }\n id\n }\n takerAssetBundle {\n assetQuantities(first: 1) {\n edges {\n node {\n ...AssetQuantity_data\n id\n }\n }\n }\n id\n }\n}\n\nfragment AssetCell_assetBundle on AssetBundleType {\n assetQuantities(first: 2) {\n edges {\n node {\n asset {\n collection {\n name\n id\n }\n name\n ...AssetMedia_asset\n ...asset_url\n id\n }\n relayId\n id\n }\n }\n }\n name\n slug\n}\n\nfragment AssetMedia_asset on AssetType {\n animationUrl\n backgroundColor\n collection {\n description\n displayData {\n cardDisplayStyle\n }\n imageUrl\n hidden\n name\n slug\n id\n }\n description\n name\n tokenId\n imageUrl\n}\n\nfragment AssetQuantity_data on AssetQuantityType {\n asset {\n ...Price_data\n id\n }\n quantity\n}\n\nfragment Orders_data_2g7x2d on Query {\n orders(after: $cursor, excludeMaker: $excludeMaker, first: $count, isExpired: $isExpired, isFilled: $isFilled, isValid: $isValid, maker: $maker, makerArchetype: $makerArchetype, makerAssetIsPayment: $makerAssetIsPayment, takerArchetype: $takerArchetype, takerAssetCategories: $takerAssetCategories, takerAssetCollections: $takerAssetCollections, takerAssetIsOwnedBy: $takerAssetIsOwnedBy, takerAssetIsPayment: $takerAssetIsPayment, sortAscending: $sortAscending, sortBy: $sortBy, makerAssetBundle: $makerAssetBundle, takerAssetBundle: $takerAssetBundle) {\n edges {\n node {\n closedAt\n isFulfillable\n isValid\n oldOrder\n openedAt\n orderType\n maker {\n address\n ...AccountLink_data\n ...wallet_accountKey\n id\n }\n makerAsset: makerAssetBundle {\n assetQuantities(first: 1) {\n edges {\n node {\n asset {\n assetContract {\n account {\n address\n chain {\n identifier\n id\n }\n id\n }\n id\n }\n id\n }\n id\n }\n }\n }\n id\n }\n makerAssetBundle {\n assetQuantities(first: 30) {\n edges {\n node {\n ...AssetQuantity_data\n ...quantity_data\n id\n }\n }\n }\n id\n }\n relayId\n side\n taker {\n ...AccountLink_data\n ...wallet_accountKey\n id\n address\n }\n takerAssetBundle {\n assetQuantities(first: 1) {\n edges {\n node {\n ...AssetQuantity_data\n ...quantity_data\n asset {\n ownedQuantity(identity: {})\n decimals\n symbol\n relayId\n assetContract {\n account {\n address\n id\n }\n id\n }\n id\n }\n quantity\n id\n }\n }\n }\n id\n }\n ...AskPrice_data\n ...orderLink_data\n makerAssetBundleDisplay: makerAssetBundle {\n ...AssetCell_assetBundle\n id\n }\n takerAssetBundleDisplay: takerAssetBundle {\n ...AssetCell_assetBundle\n id\n }\n id\n __typename\n }\n cursor\n }\n pageInfo {\n endCursor\n hasNextPage\n }\n }\n}\n\nfragment Price_data on AssetType {\n decimals\n imageUrl\n symbol\n usdSpotPrice\n assetContract {\n blockExplorerLink\n id\n }\n}\n\nfragment ProfileImage_data on AccountType {\n imageUrl\n address\n chain {\n identifier\n id\n }\n}\n\nfragment asset_url on AssetType {\n assetContract {\n account {\n address\n chain {\n identifier\n id\n }\n id\n }\n id\n }\n tokenId\n}\n\nfragment orderLink_data on OrderV2Type {\n makerAssetBundle {\n assetQuantities(first: 30) {\n edges {\n node {\n asset {\n externalLink\n collection {\n externalUrl\n id\n }\n id\n }\n id\n }\n }\n }\n id\n }\n}\n\nfragment quantity_data on AssetQuantityType {\n asset {\n decimals\n id\n }\n quantity\n}\n\nfragment wallet_accountKey on AccountType {\n address\n chain {\n identifier\n id\n }\n}\n"""
variables = {"cursor":None,"count":10,"excludeMaker":None,"isExpired":False,"isFilled":None,"isValid":True,"maker":None,"makerArchetype":None,"makerAssetIsPayment":True,"takerArchetype":{"assetContractAddress":"0x7c40c393dc0f283f318791d746d894ddd3693572","tokenId":"7722"},"takerAssetCategories":None,"takerAssetCollections":None,"takerAssetIsOwnedBy":None,"takerAssetIsPayment":None,"sortAscending":None,"sortBy":"MAKER_ASSETS_USD_PRICE","makerAssetBundle":None,"takerAssetBundle":None}
response = requests.post('https://api.opensea.io/graphql/', json={'query': query},data=variables)
print(response.text)
(In variables the "assetContractAddress" and "tokenId" are unique to the item.
However when I run this I get:
{"errors":[{"message":"Must provide query string."}]}
And if I don't use data=variables in requests.post I get:
{"errors":[{"message":"[400] One of taker_asset_categories, taker_asset_collections, maker, taker, maker, include_maker_assets, include_taker_assets, maker_assets, taker_assets, maker_asset_is_owned_by, taker_asset_is_owned_by, exclude_maker, maker_asset_bundle, taker_asset_bundle needs to be defined.","locations":[{"line":118,"column":3}],"path":["orders"]}],"data":{"orders":null}}
How can I use requests.post with the query and variables to get the proper response?
Thanks!
dataorjson, but not both, torequests.post(). 2. Read the documentation for the API you are trying to use to determine the correct data to pass to it. The error message gives you a hint about what is missing.