When i try to solve the path using RouteTask it says
dojo.io.script error
Using the REST API the token is added to the request URL. However, in the JS API the RouteTask and RouteParameters do not have a property for assigning a token to the request.
Check out the Token based authentication section on the secure services help section. You may need to use the Identity Manager so check out the samples.