Reputation: 301
So I've been trying to request an API using the following endpoint:
http://viatorapi.viator.com/service/search/products?destId=684&apiKey=98765687*****
Using the following python code:
import requests
import json
resp_1 = requests.get("http://viatorapi.viator.com/service/search/products?destId=684&apiKey=98765687*****")
res = resp_1.json()
print(res)
But I keep getting a Request method 'GET' not supported
error even when I try the request directly from the browser.
I've been looking at the documentation for a while now and it's says that It's supposed to be a POST request.
Any ideas on why this is happening and how to fix this?
UPDATE
Here's the new code I'm about to try:
import requests
import json
j="""{"destId": 684,"seoId": null,"catId": 3,"subCatId": 5318,"startDate": "2018-10-21","endDate": "2019-10-21","dealsOnly": false,"currencyCode": "EUR","topX": "1-3","sortOrder": "TOP_SELLERS"}"""
resp_1 = requests.post("http://viatorapi.viator.com/service/search/products?apiKey=98765687*****", data=json.loads(j))
res = resp_1.json()
print(res)
Upvotes: 1
Views: 1963
Reputation: 2022
According to the documentation you linked,
it is clear that it only takes POST requests for /search/products
. Generate a json (like the sample json from the documentation) and do a post request.
import requests
import json
j="""{
"destId": 684,
"seoId": null,
"catId": 3,
"subCatId": 5318,
"startDate": "2018-10-21",
"endDate": "2019-10-21",
"dealsOnly": false,
"currencyCode": "EUR",
"topX": "1-3",
"sortOrder": "TOP_SELLERS"
}"""
headers={'Content-type':'application/json', 'Accept':'application/json'}
resp_1 = requests.post("http://viatorapi.viator.com/service/search/products?destId=684&apiKey=98765687*****", data=j, headers=headers)
print(resp_1.json())
Upvotes: 3