Latest Enterprise DNA Initiatives


Getting API for MP data in the UK

Good Morning people,

I am hoping someone can help me with API calls and to get the information I need. In the UK the parliament website has a developer hub page. I have created a power bi report which when you click the MP name it brings up the image of that MP using the image from theyworkforus.com. What I would like to do now is to bring more information about the MP over to the report using the Parliament API so when you click on the mp name it will give information such as when they were elected, positions they hold within government all the data really which seems to be housed within the developer hub. I am having really difficulty getting this information into the report due to not much knowledge about API.

The locations of the API are below

https://members-api.parliament.uk/index.html

I am particularity interested in bringing over the members details there is an api for members biography which I think would be useful but you need to input the member id in the page to get the biography. I have tried to get all member id’s but the api used for this restricts this to 20 rows of data so when I bring this in I only have 20 of the 650 members.

Any help would be greatly appreciated I have attached the Pbix file with the image and the MP’s name.

Kind regards

Dean
Mp data.pbix (75.6 KB)

1 Like

I had a similar thing with the API for our ticketting system the other day, it restricted to 30 rows per page. I’m guessing if you add &page=2 to the end of your call, you should find you get the next 20 MPs.

I used this article in the end to get multiple pages. You create a table of numbers 1 to x and create a function to loop through your URL, replacing the number with the number in the table each time.

Scrape Data from Multiple Web Pages with Power Query • My Online Training Hub

Thanks Jamie ,

I had actually used this exact link as well to learn a bit about API’s and still couldn’t get it to work. I was thinking the same thing to use the loop function and bring this all through. I will spend a bit of time this morning and see if I can get it to work using this.

Dean

The only issue I found is knowing how many pages you need. If a call fails because the page doesn’t exist the whole thing will fail. I don’t know if the amount of MPs ever changes, if so it’s something you may need to tweak as the number changes.

Hi Jamie,

Yes I think that might be the issues MP’s change but the total numbers don’t change that much. However they are identified by unique numbers so for instance you might be known as id 1005 and I could be 4520 there is no logic behind it so I would have to iterate through about 10,000 numbers to pick them all up.

Dean

1 Like

Oh no that should be fine, it’s the total amount that’s the sticking point if that changes or not. If it’s always 650 or thereabouts, if you made your table number 1 to 33 following from that article you shouldn’t run into any issues.

Interesting project @deanjohnson

1 Like