locq
locq

Reputation: 301

Getting Request method 'GET' not supported - Python

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.

Here: https://docs.viator.com/partner-api/affiliate/technical/#tag/Product-services/paths/~1search~1products/post

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

Answers (1)

Ricky Kim
Ricky Kim

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

Related Questions