+ Start a Discussion
rwc0001rwc0001 

How can I determine the metadata endpoint url for a given session id (and without the username/password)?

How can I correctly determine the metadata endpoint URL for a given sessionId?

 

I have a program that is launched by a custom link I need to generate a metadata connection using the sessionId.

 

Currently I'm able to accomplish this by

1) guessing which pod (e.g. na1) the users on using the 'referer' header from a visualforce page that launched my app

2) manually constructing the metadata endpoint url from the pod and orgId 

 

The problem I'm running into in this approach is there are a lot of edge cases for what the referer url looks like, e.g. c.na1.visual.force.com or managedPackage.na1.visual.force.com.  Long term this strategy is less than ideal as it breaks whenever the url for visualforce pages changes.

 

Does anyone have any tips on how I can improve on this?

Best Answer chosen by Admin (Salesforce Developers) 
cgosscgoss
One thing you can do is to include the SOAP endpoint URL merge field in your link in addition to the session merge field. In our experience, this method works in sandbox, visualforce, and standard SF pages.

All Answers

cgosscgoss
One thing you can do is to include the SOAP endpoint URL merge field in your link in addition to the session merge field. In our experience, this method works in sandbox, visualforce, and standard SF pages.
This was selected as the best answer
rwc0001rwc0001
Merge field when used in visualforce is  {!$Api.Partner_Server_URL_160}