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
Shaolin MasterShaolin Master 

In an Apex REST Endpoint how do I parse parameters sent in a Get request?

I want to know how to parse the URL params from a get request
/services/apexrest/Endpoint/?subject=test&status=active&priority=1&origin=?subject=test&status=active&priority=1
I want to parse the url params in the class below
@HttpGet
    global static void getStatus() {
        RestRequest request = RestContext.request;
        System.debug(request.requestURI); 
        
    }

Please help!
Best Answer chosen by Shaolin Master
Maharajan CMaharajan C
Hi,

You have to write like below to parse the request:
@HttpGet
global static void getStatus() {
    RestRequest req = RestContext.request;
    String subject = req.params.get('subject');
    String status = req.params.get('status');
    String priority = req.params.get('priority');
    String origin = req.params.get('origin');
    
    system.debug('subject --> ' + subject  + ' status --> ' + status + 'priority --> ' + priority + 'origin --> ' + origin);

}

Thanks,
Maharajan.C

All Answers

Maharajan CMaharajan C
Hi,

You have to write like below to parse the request:
@HttpGet
global static void getStatus() {
    RestRequest req = RestContext.request;
    String subject = req.params.get('subject');
    String status = req.params.get('status');
    String priority = req.params.get('priority');
    String origin = req.params.get('origin');
    
    system.debug('subject --> ' + subject  + ' status --> ' + status + 'priority --> ' + priority + 'origin --> ' + origin);

}

Thanks,
Maharajan.C
This was selected as the best answer
Shaolin MasterShaolin Master
Thank you this worked! Not sure why I could not find this in the docs.
Shaolin MasterShaolin Master
How can you receive the body in a GET request?
Jonathon HayesJonathon Hayes
The package version associated with this installation URL is deprecated because the developer of the package has downloaded a newer version. Contact the package publisher to get the new installation URL.

https://writemyresearchpaper.onl/
sf asasf asa
Can you share the complete scirpt of this program? I want to test it for my blog (https://besttenniscompanion.com/best-tennis-racquet/).