function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
asadim2asadim2 

Simple REST class won't work (Could not find a match for URL ....)

Here's the Apex REST class:

@RestResource(urlMapping='/abc/def/*')
global with sharing class TheRESTclass
{
  @HttpGet
  global static String doGet(RestRequest req, RestResponse res)
  { return 'hello'; }
}

 

From the Apigee Salesforce console, I call the following URL (using OAuth authentication):

https://na7.salesforce.com/services/apexrest/abc/def

 

I've also tried it with the namespace in there:

https://na7.salesforce.com/services/apexrest/namespace/abc/def

 

But I keep getting this error:

 "message": "Could not find a match for URL /namespace/abc/def", "errorCode": "NOT_FOUND"

 

I've looked at multiple tutorials and they all guided me in the same direction. So I don't know what I could be possibly missing. Do I need to comfigure Remote Site Settings or do any other type of configuration?

 

Thanks in advance.

Best Answer chosen by Admin (Salesforce Developers) 
TLFTLF

Actually I figured this out. If my package name is "MyPackage", then the URL for the resource must be:

 

https://{instance}.salesforce.com/services/apexrest/MyPackage/events

 

The namespace component of the URL is case sensitive, so, this URL doesn't work:

 

https://{instance}.salesforce.com/services/apexrest/mypackage/events

 

I'm giving myself create for a solution on this one ;)

All Answers

TLFTLF

asdim2, did you ever find a solution to this? I've run into a similar issue. I've got an APEX REST class with the following signature:

 

@RestResource(urlMapping='/event/*')
global with sharing class REST_Event {

	// Returns the specified Event Instance
	@HttpGet
	global static EventInstance__c getEvent(RestRequest req, RestResponse res) {

 

I developed the class in a non-namespaced Developer Edition org and it worked fine when I accessed it via the URL: https://naX.salesforce.com/services/apexrest/event/{someid}. When I migrated the code to a namespaced Developer Edition org in preparation for packaging I got the error you described. I tried accessing the resource using the following URL: https://naX.salesforce.com/services/apexrest/{mynamespace}/event/{someid} and got the same result. Any ideas?

asadim2asadim2

If I recall correctly, it took some time (like a day) for the service to get published. Don't know why, but when I tested it the next day it worked.

TLFTLF

Actually I figured this out. If my package name is "MyPackage", then the URL for the resource must be:

 

https://{instance}.salesforce.com/services/apexrest/MyPackage/events

 

The namespace component of the URL is case sensitive, so, this URL doesn't work:

 

https://{instance}.salesforce.com/services/apexrest/mypackage/events

 

I'm giving myself create for a solution on this one ;)

This was selected as the best answer
ShantinathShantinath
Thanks! Saved my day!!
SijuSiju
If you have a namespace enabled for your org, then it will need to be included in the url.
Example  it would be:
https://na15.salesforce.com/services/apexrest/your_namespace/apexrest/abc/def where "your_namespace" is the namespace of your org
thanh nguyen 35thanh nguyen 35
@Siju, thank you
Manu SrivastavaManu Srivastava
If my code is part of a managed package, then the namespace of the package contents need to be added as mentioned by Siju above.

This will ensure it will work in customer orgs where my package is deployed. 
WearlenseSNO API UserWearlenseSNO API User
Hi, I am still getting error n REST call :
GET :https://eu5.salesforce.com/services/apexrest/appsearch. The 404 error is: [
    {
        "errorCode": "NOT_FOUND",
        "message": "Could not find a match for URL"
    }
Pratap DemoPratap Demo
Did you find the way to resolve it @WearlenseSNO