how to get the url to usefor a private path if I have a file saved in private:://somefile.txt  , what function can I use in drupal to give me the external URL to access that? 

I tried PrivateStream::getExternalUrl()
but I get this error 

PHP Fatal error:  Call to undefined method Drupal\mymodule\myservice::getTarget() in /opt/DrupalSites/drupal-wcms-migration/docroot/core/lib/Drupal/Core/StreamWrapper/PrivateStream.php on line 50
You can't call PrivateStream::getExternalUrl() directly because it's not a static function; it needs an instantiated stream before you can call getExternalUrl() on it. 

You can retrieve it via the stream wrapper manager's getViaUri() method: 

$stream = \Drupal::service('stream_wrapper_manager')-&gt;getViaUri('private:://somefile.txt');
$stream-&gt;getExternalUrl();