+ Start a Discussion
MattWelchMattWelch 

Accessing, from Apex, a RESTful Heroku webservice that redirects.

I've built a simple, unauthenticated web service in Sinatra, running on Heroku, that takes a list of attachment Ids, uses OmniAuth and the databasedotcom gems to authenticate into SFDC and access the attachements. Once I've downloaded them, I zip them up, and send them back to the requestor.

 

Doing this straight from the browser works great: type in the REST url, watch the webservice redirect me to SFDC, where I can enter my SFDC credentials. (Or, if I'm already logged in to SFDC in another window, I don't even have to enter them). Once I'm authenticated, I'm redirected back to Heroku, where the attachments are pulled down and zipped up.

 

Great. Things look good. But now I'm trying to build this functionality into the Apex app I'm writing, and I hit a wall from the git-go. HTTPRequest doesn't like redirects. Looking at the debug log, the whole process just stops with that first 302.

 

I can't believe I'm the first one try and consume external RESTful services that redirect, but I can't find any references to this problem elsewhere. Any help would be appreciated.

dkadordkador

You'll either need to handle the redirect yourself or use a different oauth flow that does not do the redirect.