5

What is the proper/safe way to get/generate links for Salesforce objects retrieved through the REST API?

For instance, we have a tool living in another application that allows users to query for Salesforce content objects from the context of this other application and directly embed a link (just eases the process of linking to Salesforce content). At the moment, I am relying on the ID and the Salesforce URL (e.g., https://mysalesforceinstance.salesforce.com/|sobjectId|) as the URL that is embedded. Ideally, for content, we would link to the version page instead (e.g., https://mysalesforinstance.salesforce.com/sfc/#version/|sobjectID|). Is there a way to safely generate/retrieve this URL with the rest API? Or can I simply assume this URL will exist for all content objects?

I have seen in the past APIs that return a list of "resources" (e.g, URLs for all CRUD operations on the object) alongside an object, but I haven't seen anything like this in the documentation.

3

I know your question is about the REST API, but with the SOAP Partner API you can use DescribeSObjectResult to get the urlDetail, urlEdit, and urlNew. With these you can build up the correct URL by substituting the {ID} value.

It looks like there are equivalent fields available via the REST API. I say "looks like" as there is something off about that documentation. It looks more like the SOAP API docs than the REST API.

If you do an SObject Describe via the REST API you can get the "urls" in the response. Like the SOAP API, you can substitute the {ID} with your value.

curl https://na1.salesforce.com/services/data/v20.0/sobjects/Account/describe/ -H   
     "Authorization: Bearer access_token" -H "X-PrettyPrint:1"

Output

{
    "name" : "Account",
    "fields" :
    [
        ...
    ],
    "updateable" : true,
    "label" : "Account",
    ...
    "urls" :
    {
        "uiEditTemplate" : "https://na1.salesforce.com/{ID}/e",
        "sobject" : "/services/data/v20.0/sobjects/Account",
        "uiDetailTemplate" : "https://na1.soma.salesforce.com/{ID}",
        "describe" : "/services/data/v20.0/sobjects/Account/describe",
        "rowTemplate" : "/services/data/v20.0/sobjects/Account/{ID}",
        "uiNewRecord" : "https://na1.salesforce.com/001/e"
    },
    ...
}
  • Interestingly in this case, for both ContentDocument and ContentVersion, the '/sfc/#version/{ID}' is not returned as a URL, which is the URL I am ultimately after. Wondering why this is the case. – user7266 Mar 10 '14 at 20:53
  • My past experience with Content is that it was a law unto itself in some respects. Do the API returned URLs redirect as required. If not, you might have to do some hardcoded URL cases in your code. Less than ideal for sure. – Daniel Ballinger Mar 10 '14 at 21:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.