+ Start a Discussion
seamas liseamas li 

Can't see parameters in Rest HTTP doGet Method

Hi Expert,

I can not get phoneNumber in testing. but it is working in WorkBeach 

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

        String phoneNumber = req.params.get('phoneNumber');
        String subscriptionId = req.params.get('subscriptionId');    
        system.debug('phoneNumber : '+ phoneNumber) ;  


        return response;
    }

    static testMethod void getSubscriptionByPhoneNumberTest() {
        
        test.startTest();        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
        req.requestURI = '/services/apexrest/subscriptions?phoneNumber=416360999 1234567891 0488888888';
        req.httpMethod = 'GET';
        
        RestContext.request = req;
        
        String result=NewsSubscriptionController.doGet();

  
        test.stopTest();
    
    }
KaranrajKaranraj
Try avoiding space in the requestURI
req.requestURI = '/services/apexrest/subscriptions?phoneNumber=416360999+1234567891+0488888888';