Python Examples & Better Error Messages
complete
A&B All Goods
I have gotten fairly far with my attempts, but am now faced with a response of:
{'errors': [{'message': 'Something went wrong. The error has been logged and will be fixed as soon as possible.'}]}
I can provide code if you need, or if it will help someone else. I just cannot move forward with my project until I know what is happening. If it helps, I am using the "Requests" module from python 3.7+
my query works just fine in the playground, but even though it gets to the endpoint, and counts against my total uses for the month, I only get the error result from above
R
Ryan Anderson
complete
Ryan Anderson
Can you share a link to the playground with the query or the raw graphql query? Will look into this asap.
A&B All Goods
Ryan Anderson Sure thing:
query amazonProduct {amazonProduct(input: {asinLookup: {asin: "B08P2DXP1P"}}) {title brand price {display currency} imageUrls technicalSpecifications {name value} featureBullets packageWeight}}
Let me know if you need any of the python code.
Ryan Anderson
A&B All Goods The query looks good to me. If you could share your python code I can help troubleshoot the issue. If you don't want the code public, feel free to share via the chat widget on https://www.canopyapi.co/ or via email to support@canopyapi.co
A&B All Goods
Ryan Anderson no worries, I dont mind sharing here, maybe the example will help others figure it out too.
this.canopy_request_data = 'query amazonProduct {amazonProduct(input: {asinLookup: {asin: "##"}}) {title brand price {display currency} imageUrls technicalSpecifications {name value} featureBullets packageWeight}}'
code = this.ent_scanner.get()
if len(code) == 10 and not code.isnumeric(): #test if barcode is asin
url_string = this.barcode_locations['asin']
headers = {"API-KEY": this.canopy_api_key, "User-Agent": "Mozilla/5.0"}
payload = this.canopy_request_data.replace('##', code)
response = requests.post(url_string, json=payload, headers=headers)
print(response.json())
Its very simple code thanks to the 3.7+ package I use. the request makes it to the server (it counts against my monthly allowance) so I am guessing whatever happens once it is received somehow disagrees with how I build the request.
I did also try to construct a urllib request that has more options, but I could never get the query string to pass through the api. It always just returned an empty string
Ryan Anderson
A&B All Goods We added a python example to the docs here: https://docs.canopyapi.co/examples/python
It wasn't clear to me what would be wrong in the above code. It looks okay, but it looks somewhat incomplete so I can't be sure.
Hopefully the example helps!
A&B All Goods
Ryan Anderson The issue was how the query was sent. Specifically structuring it inside a python dictionary with the "query" key. I was just sending the query alone as I couldn't figure out how the server expected it.
The example clears that up and shows the ability to use variables within your system, rather than clutter my code with string manipulations.
Thanks for clearing this up so quickly. and for making the system in the first place.