diff --git a/TES/tes/apiendpoints.py b/TES/tes/apiendpoints.py
index e41d86d33411d439b2b773a3489eb1ca91728bd2..3b9f7732bb23176fa80c845563c95c1ac4c15d50 100644
--- a/TES/tes/apiendpoints.py
+++ b/TES/tes/apiendpoints.py
@@ -389,10 +389,10 @@ class AppUrl(Resource):
         return url
 
 class AppInstance(Resource):
-    def get(self, username, loginhost, batchhost):
+    def get(self, username, loginhost, batchhost, jobid):
         """Run a command to get things like password and port number
         command is passed as a query string"""
-        sshsess = SSHSession.get_sshsession()
+        sshsess = SSHSession.get_sshsession().format(jobid=jobid)
         paramscmd = request.args.get('cmd')
         import logging
         logger = logging.getLogger()
@@ -484,7 +484,7 @@ api.add_resource(JobStat, '/stat')
 api.add_resource(JobCancel, '/cancel/<int:jobid>')
 api.add_resource(JobSubmit, '/submit')
 api.add_resource(CreateTunnel, '/createtunnel/<string:username>/<string:loginhost>/<string:batchhost>')
-api.add_resource(AppInstance, '/appinstance/<string:username>/<string:loginhost>/<string:batchhost>')
+api.add_resource(AppInstance, '/appinstance/<string:username>/<string:loginhost>/<string:batchhost>/<int:jobid>')
 api.add_resource(AppUrl, '/appurl')
 api.add_resource(SSHAgent,'/sshagent')
 api.add_resource(DirList,'/ls')