I'm trying to make a request to an API. I've got the API key and read the documentation.
Documentation: https://info.nobil.no/images/downloads/API-NOBIL-Documentation_v3_20180808.pdf
The examples in the documentation seems to me to be in javascript.
jQuery.ajax({
type: 'POST',
url: 'https://nobil.no/api/server/search.php',
data: { 'apikey': nobilApiKey, 'apiversion': '3',
'action': "search",
'type': 'rectangle',
'northeast': '(59.943921193288915, 10.826683044433594)',
'southwest': '(59.883683240905256, 10.650901794433594)',
'existingids': '189,195,199,89,48'},
dataType: 'json'
});
Questions: 1.) Can I make a request to the server with python? 2.) How do I incorperate the api key into the code?
Would really appreciate a code snippet showing how!
you would use the requests
library
it would look something like this:
import requests
url = 'https://nobil.no/api/server/search.php?mode=ajax'
post_data = { 'apikey': nobilApiKey, 'apiversion': '3',
'action': "search",
'type': 'rectangle',
'northeast': '(59.943921193288915, 10.826683044433594)',
'southwest': '(59.883683240905256, 10.650901794433594)',
'existingids': '189,195,199,89,48'}
r = requests.post(url, data=post_data)
# do something with r
Read the docs here: https://requests.readthedocs.io/en/master/