It is unclear what are you exactly trying to do. If you only need to extract part of the link then this seems to be a simple parsing task that can be done by editing the api call if possible or write some parsing code for it (using bash or python f.e.).
However, if you are trying to do some matching between the datasets, which I suspect is your goal then you need to figure out the id computation logic or its relation to the product_res_number. Since this does not seem to be a simple task I suggest using the 510(K)Number, which seems to be the same in both Databases and you can search for a certain Device using its K_res_number on https://www.accessdata.fda.gov/scripts/cdrh/cfdocs/cfRES/res.cfm.
So what you can do is simulate a search using the K-number, by replicating the same request triggered on search click and curl the request ( this is the second command. Note that I pass the k-number in the command as the variable $knumb
). Curl would return the Html page with the link that includes the id which you can extract using grep and regex. In a bash terminal this can be done as follows:
# get k-number from first link/request
$ knumb=$(curl -s https://api.fda.gov/device/recall.json\?search\=product_res_number:%22Z-0997-2015%22 | python3 -c "import sys, json; print(json.load(sys.stdin)['results'][0]['k_numbers'][0])")
$ echo $knumb
K110474
# get id from second link using search return for k-number
$ id=$(curl 'https://www.accessdata.fda.gov/scripts/cdrh/cfdocs/cfRES/res.cfm' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Content-Type: application/x-www-form-urlencoded' -H 'Origin: https://www.accessdata.fda.gov' -H 'Connection: keep-alive' -H 'Referer: https://www.accessdata.fda.gov/scripts/cdrh/cfdocs/cfRES/res.cfm' -H 'Cookie: AWSALB=k/tN7E7E4WMctvjulYSGWAjgrR3jlJwt8EWdvVIVJhuNirELXXFdnfK6G/ND2K95WIXt7o1JiYoo/PdCHWJ6u5I+KmJjznvH9/vpULe0tooH5LTi6xHbNfeCqwlF; AWSALBCORS=k/tN7E7E4WMctvjulYSGWAjgrR3jlJwt8EWdvVIVJhuNirELXXFdnfK6G/ND2K95WIXt7o1JiYoo/PdCHWJ6u5I+KmJjznvH9/vpULe0tooH5LTi6xHbNfeCqwlF' -H 'Upgrade-Insecure-Requests: 1' -H 'TE: Trailers' --data-raw 'productdescriptiontxt=&productcode=¢erclassificationtypetext=&PMA_510K_Num='$knumb'&postdatefrom=&postdateto=&recallnumber=&productshortreasontxt=&firmlegalnam=&rootCauseText=&sortcolumn=cdd&Search=Search' | grep -o -P "(?<=./res.cfm\?id=).*(?=\")")
$ echo $id
131452
NB:
If curl, grep and regex seem to be a bit complex or you do not use a Unix-based system where these tools are relatively simple to use ... please know that replicating the previous logic is a simple task in Python and the code is probably much tidier.
Sources and references: