0

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 - enter image description here

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 - enter image description here

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?

1 Answer 1

0

There's a few problems.

First, the ZIP file can't be base64 encoded. See this answer for a way to properly encode binary data in Apex Code. It's non-trivial because Apex doesn't have native binary support in the same sense that Java or C++ does.

Second, if you're setting singlePackage to false, you must have the following file structure:

+ package
| package.xml
| + omniScripts
  | scriptName.omniScript

I derived the script name from the OmniScript Metadata API object. It's not entirely clear, though, as few objects are formatted this way, so it may very well be a suffix of .omniScript-meta.xml. Either way, it's probably not .os-meta.xml.

Conversely, if you set singlePackage to true, the expected format is:

+ omniScripts
| scriptName.omniScript
package.xml

Notice how the package.xml must be at the base level, and metadata must be in their metadata folders (e.g. the omniScripts folder).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .