I am trying to deploy Omniscript which is stored in a zip file inside a static resource. I am following this documentation here.
Here is the code - `
public class MetadataDeploymentCurl {
public static HttpRequest makeDeploymentRequest(Blob zipFileBody) {
HttpRequest request = new HttpRequest();
request.setEndpoint('host'+'/services/data/v56.0/metadata/deployRequest');
request.setMethod('POST');
request.setHeader('Authorization', 'Bearer 00D...');
request.setHeader('Accept', '*/*');
request.setHeader('Connection', 'Keep-Alive');
request.setHeader('Content-Type', 'multipart/form-data');
String jsonPayload = '{' +
'"deployOptions" : {' +
' "allowMissingFiles" : false,' +
' "autoUpdatePackage" : false,' +
' "checkOnly" : false,' +
' "ignoreWarnings" : false,' +
' "performRetrieve" : false,' +
' "purgeOnDelete" : false,' +
' "rollbackOnError" : false,' +
' "runTests" : null,' +
' "singlePackage" : false,' +
' "testLevel" : "NoTestRun"' +
'}' +
'}';
String boundary = '----Boundary-' + String.valueOf(Datetime.now().getTime());
request.setHeader('Content-Type', 'multipart/form-data; boundary=' + boundary);
String body = '';
// JSON Payload
body += '--' + boundary + '\r\n';
body += 'Content-Disposition: form-data; name="entity_content"\r\n';
body += 'Content-Type: application/json\r\n\r\n';
body += jsonPayload + '\r\n';
// ZIP File
body += '--' + boundary + '\r\n';
body += 'Content-Disposition: form-data; name="file"; filename="unpackaged.zip"\r\n';
body += 'Content-Type: application/zip\r\n\r\n';
body += EncodingUtil.base64Encode(zipFileBody) + '\r\n';
// Closing boundary
body += '--' + boundary + '--';
//request.setHeader('Content-Type', 'multipart/form-data; boundary=' + boundary);
request.setBodyasBLob(Blob.valueof(body));
return request;
}
}`
To invoke - Blob zipFileBody = [SELECT Body FROM StaticResource WHERE Name = '<SRName>' LIMIT 1].Body; HttpRequest deploymentRequest = MetadataDeploymentCurl.makeDeploymentRequest(zipFileBody); Http http = new Http(); HttpResponse response = http.send(deploymentRequest);
Here is the request body generated -
In the response I can see 201 status code and the deployment being triggered. But in deployment if I keep singlePackage = true then I get 'Payload error - No package.xml found'. And if I keep singlePackage = false, then deployment is succeeded but it shows 0/0 components in deployment window.
The zip file structure is this -
PS. - I tried with Postman using curl command mentioned in this thread and its working absolutely fine.
Question What am I missing here? I have tried all the folder structure but still same issue. Is there any other approach that I can take to deploy the components from static resource?