18

I found a different question asking, "Can I have a public APEX REST API?" which led to a blog post explaining how to setup a public site to expose a REST API:

  1. Create your REST API in Apex as normal
  2. Create a public site
  3. Configure the public user to have access to the Apex class and any other sObjects

I followed the directions and have a publicly available site, but when I do a GET to the URL the site returns a HTTP 503 error page. My understanding is that shouldn't even be routed through the VF handler.

Webservice code:

@RestResource(urlMapping='/helloWorld/*')
global class RestWebservice {

  @HttpGet
  global static String helloWorld(){
    return 'HelloWorld';
  }

}

URL being queried: https://chale1-developer-edition.na14.force.com/services/apexrest/helloWorld

I have tried:

  • Turning on debug logs for the public site user, but that didn't help as no logs recorded the error.
  • Verified no redirects are configured
  • With and without a header for Accept: application/json
  • Tried on two different dev orgs, on different instances

Answers to questions:

  • I have not built any apps in this org, nor are there any installed packages, so there are no namespaces
  • Trying /services/apexrest/helloWord/blah returned the same response
  • Most of the raw response is just HTML. The headers have content-type of text/html, X-Powered-By: Salesforce.com ApexPages, P3P: CP="CUR OTR STA", cache-control, and nothing else of note

Eventually I would like to have a webhook use this API which is why it needs to be public. What else could cause the service to return a 503?

3
  • Can you inspect the raw response for an error? Also append /something to the service endpoint? Commented Apr 24, 2014 at 19:03
  • do you happen to have a namespace on that org? (managed package) Commented Apr 24, 2014 at 19:07
  • Questions answered and I filled in the URL just in case somebody wants to see the actual response. Commented Apr 24, 2014 at 19:14

2 Answers 2

26

You are using the wrong URL I think

Try this: https://chale1-developer-edition.na14.force.com/test/services/apexrest/helloWorld

EDIT - When I looked at the HTML that came back original URL in Postman, I saw this message:

https://chale1-developer-edition.na14.force.com/test</i> is down for maintenance

So I realized he must have used added a suffix to the Default Web Address in the Site called test. The REST URL includes the default suffix as part of the full URL, so I added that the URL he provided, and it worked...

9
  • 1
    Wow, that worked! Where did you get that from? Commented Apr 24, 2014 at 19:16
  • could you please explain why "test" should be needed? In the related article the service url shown has not the test you are refering Commented Apr 24, 2014 at 19:18
  • 2
    'test' is only needed because he added a suffix to the Default Web Address - if you just create a site and leave that blank, the URL would be as described in the article Commented Apr 24, 2014 at 19:25
  • That's the name of my site and the default page I configured; I'll try removing those. Commented Apr 24, 2014 at 19:26
  • 2
    Ah - it was almost namespaces :-) Commented Apr 24, 2014 at 19:57
3

If you have a managed package & your namespace name is 'devns' then try to add

/services/apexrest/devns/helloWorld

1
  • 1
    Thanks for this - got stuck on this while creating a managed package. Commented May 18, 2024 at 21:01

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.