Search code examples
pythonapisocratasoda

Acces all data from RDW API by adding App Token


For a school project i need to work with the information that a api is giving me. I choose for the RDW API(Dutch License plate info). What i now have is only acces to 1000 licenseplates but i want to be able to get all off them.

import urllib.request
import json

url = "https://opendata.rdw.nl/resource/m9d7-ebf2.json?"

json_data_request = urllib.request.urlopen(url)
json_data = json.loads(json_data_request.readall().decode("utf-8"))

print(len(json_data))

With this code i'm only able to acces 1000 licenceplates What i want to get to work is(kenteken=licenceplate):

def locu_search(kenteken):
    api_key = "CYcaHHuuvFfG2apjnvns8Ob41"
    url = "https://opendata.rdw.nl/resource/m9d7-ebf2.json?$$app_token=" + api_key
    after_url = "kenteken=" + kenteken
    final_url = url + after_url
    json_data_request = urllib.request.urlopen(final_url)
    json_data = json.loads(json_data_request.readall().decode("utf-8"))
    #print all info with that licenceplate
kenteken = input("Licenceplate:")
locu_search(kenteken)

What this code should do is:

  1. ask for licenceplate.
  2. go to the function with the value you put in.
  3. print all information of that licenceplate.(not here yet because i can't get the previous lines not to work)

I searched but was not able to get this working any info i can work with?


Solution

  • There are a couple of things you'll need to change in your code:

    • You'll need to add an ampersand (&) between url and after_url to separate those two parameters: final_url = url + "&" + after_url
    • If you want to retrieve more than 1000 records per request, you'll need to use the $limit and $offset paging parameters: https://dev.socrata.com/docs/paging.html