'Wikipedia API - for multiple titles generate links with ids

There are two things I can do:

  1. Using a generator, I can make a request to retrieve links with ids for a specific title:

https://en.wikipedia.org/w/api.php?action=query&generator=links&titles=Klaksvik&gpllimit=500&format=json

Of course, I can retrieve links for more than one title, but there is no information about which link refers to which title.

  1. I can use a query parameter and retrieve JSON with links for each requested title (with mapping):

https://en.wikipedia.org/w/api.php?action=query&titles=England%20Salisbury|Klaksvik&prop=links

The problem is, that there are no ids - only titles for each link.

I want to combine these two options: the response contains both information about which link refers to which title and the pageid for each link.

(The second option but with id for each link.)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source