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

REST Invalid URI


I had this code working but realized that it really wasn't bulkifyed because I was passing in a single username!  I changed the caller to pass a list as shown below.  The bold areas are what i changed from a String to a LIST string.  Once I did that I started getting an invalid URI error.  Your help is apprecaited - thanks.

public class SandboxManagerCallout {
    public static void DeactivateUser(String NamedCredential, List<String> UserNames) {
        // The line below is only here to save time during testing by reactivating users.  
        // This should always be set to FALSE in PRODUCTION.
        Boolean isActive = true; 
        String EndPoint = 'callout:' + NamedCredential + '/services/apexrest/SandboxManagerAPI/' + UserNames + '/' + isActive;        
        HttpRequest req = new HttpRequest();        
        Http http = new Http();
        req.setHeader('Content-Type', 'application/json;charset=UTF-8');
        req.setBody('{"UserNames":UserNames, "isActive":isActive}');
        HTTPResponse res = http.send(req);

this is the code on the REST API side but the error I get doesn't even make it to this code but thought to show in case...

global with sharing class SandboxManagerAPI {  
    static Boolean isSandboxValidated = false;
    static Boolean isOrgSandbox = false;

    global static void doDeactivate() { 
        Integer USER_NAME = 2;
        Integer IS_ACTIVE = 3; 
        if(!issandbox()) return;
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        System.debug('req: ' + req.requestURI);
        List<String> Parms = req.requestURI.split('/');
        String UserName = parms[USER_NAME];
        String isActive = parms[IS_ACTIVE];
        //String userName = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);      
        System.debug('Username Passed In: ' + UserName);
        System.debug('isACtive passwed In: ' + isActive);
        User user = [SELECT Id, Username, isActive 
                     FROM User 
                     WHERE userName .............................
can you plese paste the error you received, may be from debug logs


The  EndPoint you are building may have spaces or characters which may not be supported. 
Please see debug and check if the URI has any white spaces or invalid symbols
Note: if there is space even at the end of the endpoint then Invalid URI error is thrown!
Example: ' '

Hope this helps,