Cannot get DocumentReference using it's guid
# support
l
I am stumped! In my self-hosted medplum environment, I have a Bot which posts some data to a stand-alone service. Among the data it posts is it's own baseUrl and accessToken, so the service can retrieve some additional data. The bot receives an Observation, which has an associated DocumentReference, and posts the Observation, along with the previously mentioned baseUrl and accessToken, over to the standalone service. In the standalone service I plan to use @medplum/core to retrieve some additional information, utilizing the baseUrl and accessToken provided. However there is a problem. In code, using that accessToken and baseUrl, I am able to successfully retrieve the Patient (e.g. medplum.get('/fhir/R4/Patient/')), but I am not able to retrieve the DocumentReference (e.g. medplum.get('/fhir/R4/DocumentReference/'). It always fails with 'Not Found'. However, if I ssh into the container where that service is running and use the medplum cli (e.g. medplum --base-url --access-token get DocumentReference/) then I am able to retrieve the DocumentReference resource. The access token is retrieved in the Bot with "client.accessToken" and, as mentioned, can be used in code to retrieve the Patient associated with the Observation. The same accessToken can be used with the medplum cli to retrieve the DocumentReference in question - just not in code. What gives? This has been my whole day trying to figure this out. I appreciate any input.
i
@lane is it possible that the code in your service is somehow mangling the path to the
DocumentReference
?
You mentioned you can ssh into the container running Medplum and get the
DocumentReference
, are you able to do the same from the box that is running your external service?
l
Hi, @Ian Plunkett . Sorry so long to respond. Actually it is the standalone service (i.e. "external service") where I ssh to test. And since I am heavily debugging this, I scrape the URL directly off of the screen to do the test. So it is unlikely there is some mangling there. BTW: I have moved beyond this by using the Bot-side medplum client to retrieve the DocumentReference and it's attachment. Then just push them to my service. I'm still perplexed why the original idea does not work, but not blocked. Thanks for your response.
Hi @Ian Plunkett . Just a quick follow up. I found my root cause: timing. The resource I wanted had not yet been created at the moment that the Bot was triggered. I added a back-off retry and found success!
i
ah great! glad you got it figured out
597 Views