You need to make some changes during the generation process, not during the replay ...
Firstly, examine the request message in your request-response pair. Look at the first line. If the first line reads
GET http://hostname/api/retrieveId/12 HTTP/1.1
Then that's contributing to your problem. The request message was generated incorrectly - we want base path there, not URL.
You fix this by opening the listen step in your VSM file, and changing the base path in there, so you don't get a 404 error. You could change that to "/api/" so any api requests are dealt-with, or "/api/retrieveId/" so only retrieveId messages are dealt-with, or "/" so all requests are dealt-with.
Your other problem with generating 404s is that your operation name needs to be made more generic. Add the Request Data Manager to your list of data protocol handlers. You want to copy the attribute "http-sequence-2" (or something - whatever points to "retrieveId" ) to your operation name. This will mean that any request to retrieveId will be matched, and your URLPARAM0 (perhaps you can change this during generation to a better name, such as {retrieveId} ) will determine whether you have an exact or a signature match.