Why am I getting “Service not found error” when trying to access a @RestResource when it is exists

apexapexrestrest-apirestresource

I have a rest class with a @RestResource annotation and a method with @HttpPost annotation. Something like –

(urlMapping='/abc/contractors')
class ContractorInfoWebService {

    @HttpPost 
    global static void callContractorsInfoService() {
      // some code here........
    }   
}

While creating the class in my development org (in an unmanaged package) I was able to hit the uri /services/apexrest/abc/contractors and get a response out of it. But after the class is deployed to production environment in a managed package, I am getting an error when trying to hit the same uri saying –

Service not found at: /services/apexrest/abc/contractors

The request type and body and everything is correct while trying to access the URI.
Could somebody please explain why it was working in my dev org but is failing after being installed through a managed package ? Is there some setting or any addition required in the URI now that it is in a managed pacakge ?

Best Answer

For a managed package you will need to ensure you provide the namespace of the package when hitting the custom rest endpoint.

Your url to try hitting would be as below

services/apexrest/namespace/abc/contractors

Here note namespace is the actual namespace of your package

Related Topic