I have been trying to make this work however no luck. I have a requirement where I need to modify the static resource on demand via apex. I downloaded MetadataService class from git (https://github.com/certinia/apex-mdapi/blob/master/apex-mdapi/src/classes/MetadataService.cls).
I have setup JWT connected APP, named creds, external creds correctly. Ran the below snippet and got 200.
request.setEndPoint('callout:MetadataJWT/services/data'); request.setMethod('GET'); HttpResponse response = new HTTP().send(request); System.assertEquals(200, response.getStatusCode()); I have below code where I am utilising this metadata api:
public static void updateStaticResource(){ MetadataService.MetadataPort service = new MetadataService.MetadataPort(); service.endpoint_x = 'callout:MetadataJWT/services/Soap/m/60.0'; MetadataService.StaticResource staticResource = new MetadataService.StaticResource(); staticResource.fullName = 'TESTHOG'; staticResource.contentType = 'application/json'; staticResource.cacheControl = 'public'; staticResource.content = EncodingUtil.base64Encode(Blob.valueOf('Static 1 stuff Changed')); List<MetadataService.SaveResult> results = service.updateMetadata( new MetadataService.Metadata[] { staticResource }); } I am no where setting session id instead using named creds for authenticating. But still gets this error: System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session faultcode=sf:INVALID_SESSION_ID faultactor=
Any help is much appreciated.