+ Start a Discussion
PawelWozniakPawelWozniak 

Problems with Setting up RESTful service

The mian goal is to set up web service which accept few parameters and based on that returns the file.

As it is my first try with webservices I do not know too much about it.

 

Input http call is GET type: https://cs8.salesforce.com/services/apexrest/RemoteActivation?company=abc&street=xyz

so parameters are passed in URL, for simplicity lets use just those two parameters.

 

I have found this article http://wiki.developerforce.com/page/Creating_REST_APIs_using_Apex_REST and followed the sample code. 

 

As a result came up with that:

@RestResource(urlMapping='/RemoteActivation/*')
global class as_remoteActivationService {
	
@HttpGet 
	global static String remoteActivation(RestRequest req, RestResponse res) {
		String company = req.params.get('company');
		String street = req.params.get('street');
				
		System.debug('COMPANY: ' + company);
		System.debug('STREET: ' + street);
		return 'Done';
	}

and error when saving:

Save error: Invalid type: HTTP GET/DELETE methods do not support parameters 

 

Now I do not understant it. Example code exacly says:

@HttpGet
  global static List<Case> getOpenCases(RestRequest req, RestResponse res) {

 and I have done the same and getting error. Why?

Best Answer chosen by Admin (Salesforce Developers) 
MarcoTimbaMarcoTimba

Found the problem, I was reading a Salesforce PDF called "Apex REST Developer's Guide" that apparently is not up to date.

 

That PDF has this example:

 

@HttpGet
global static Account doGet(RestRequest req, RestResponse res) {
   ...
}

but when I tried to create an example class with this code I got the following error: "Save error" Invalid type: HTTP GET/DELETE methods do not support parameters".

 

but if you look at the current version of the "Force.com Apex Code Developer's Guide" it has this newer version of the example:

 

@HttpGet
global static Account doGet() {
    RestRequest req = RestContext.request;
    RestResponse res = RestContext.response;
    ...
}

 and this new version does actually works.

 

All Answers

MarcoTimbaMarcoTimba

Did you ever get this sorted out? I'm seeing the same issue here.

MarcoTimbaMarcoTimba

Found the problem, I was reading a Salesforce PDF called "Apex REST Developer's Guide" that apparently is not up to date.

 

That PDF has this example:

 

@HttpGet
global static Account doGet(RestRequest req, RestResponse res) {
   ...
}

but when I tried to create an example class with this code I got the following error: "Save error" Invalid type: HTTP GET/DELETE methods do not support parameters".

 

but if you look at the current version of the "Force.com Apex Code Developer's Guide" it has this newer version of the example:

 

@HttpGet
global static Account doGet() {
    RestRequest req = RestContext.request;
    RestResponse res = RestContext.response;
    ...
}

 and this new version does actually works.

 

This was selected as the best answer
TLFTLF

Bad move Salesforce! I've already packaged GET and DELETE methods that accept parameters (which was allowed in prior API versions and documented in their sample code). Now, I cannot upgrade my Apex REST classes to new API versions (25.0+) because once global methods that are annotated with HttpGet and HttpDelete are packaged, you cannot change their signature to remove the parameters, nor can you remove the annotations from these methods. 

TLFTLF

To explain more clearly, I have the following managed released version of an Apex REST class that was developed under API version 23.0:

 

@HttpGet
global static List<EventInstance__c> getEvents(RestRequest req, RestResponse resp) {
 .
 .
 .
}

 

I tried to update it to API version 26.0, and got the "HTTP GET/DELETE methods do not support parameters" error when the code was compiled. So, I tried to change my method signature to the following:

 

@HttpGet
global static List<EventInstance__c> getEvents() {
  RestRequest req = System.RestContext.request;
  RestResponse resp = System.RestContext.response;
  .
  .
  .
}

 

This fails to compile with "Global/WebService identifiers cannot be removed from managed application". So, I then tried leaving the original global method in place and adding a new one with the signature required by API version 26.0:

 

@HttpGet
global static List<EventInstance__c> getEvents() {
   RestRequest req = System.RestContext.request;
   RestResponse resp = System.RestContext.response;
   return getEvents(req, resp);
}

global static List<EventInstance__c> getEvents(RestRequest req, RestResponse resp) {
  .
  .
  .
}

 

This failed to compile, giving the error "Previously annotated identifier with @HttpMethod must still be annotated". So, I'm kind of screwed here, because this class will never be able to take advantage of API functionality beyond version 23.0. Ah, the joys of developing managed packages!