3

I am trying to deploy Metadata on Salesforce using REST api. Here is my request:

POST https://myorg-dev-ed.my.salesforce.com/services/data/v55.0/metadata/deployRequest

headers :

{Authorization: "Bearer 00D...", "Content-Type": "multipart/form-data; boundary=--------------------------BOUNDARY"}

----------------------------BOUNDARY
Content-Disposition: form-data; name="json"; Content-Type: application/json
{
  "deployOptions":
    {
      "allowMissingFiles": false,
      "autoUpdatePackage": false,
      "checkOnly": false,
      "ignoreWarnings": false,
      "performRetrieve": false,
      "purgeOnDelete": false,
      "rollbackOnError": false,
      "runTests": null,
      "singlePackage": true,
      "testLevel": "RunAllTestsInOrg"
    }
}
----------------------------BOUNDARY
Content-Disposition: form-data; name="file"; filename="deploy.zip"
Content-Type: application/zip

UEsDBBQAAAAAAIxYMFUAAAAAAAAAAAAAAAAHACAAZGVwbG95L1VUDQAHGTwk
YyI8JGMZPCRjdXgLAAEE9QEAAAQUAAAAUEsDBBQACAAIAJtYMFUAAAAAAAAA
AO8AAAASACAAZGVwbG95L3BhY2thZ2UueG1sVVQNAAc2PCRjNjwkYzY8JGN1
eAsAAQT1AQAABBQAAABtjzEOwjAMRfeeIspOHBAghNKwMVcUDmBa01Y0SUUs
BLcnQMvEYOnbev7fNruH68WdbrELPpdzpaUgX4W6800uT8f9bCN3NjMFVlds
SCTax1y2zMMWIAYcVLyEW0WqCg4WWq9BL8ERY42M0mZCGH4OFN8qaUfunMJs
iT3FArk9kAtMZZeKmFOqgYn5bnh0ZP9Qn/nbHn7+ZvzDrlZKG5i6zMB4vn0B
UEsHCDbrTJymAAAA7wAAAFBLAwQUAAAAAACRWDBVAAAAAAAAAAAAAAAAGgAg

----------------------------BOUNDARY--

NB : I truncated the base64 encoded zip file to simplify the explanation here.

I can't contact Salesforce support service because I am using the Salesforce Developer Edition; it does not offer support.

The API response gives a 500 error :

[{"message":"An unexpected error occurred. Please include this ErrorId if you contact support: 926862273-8617 (-291109249)","errorCode":"UNKNOWN_EXCEPTION"}]

So I have no clue what the problem is. My only guess would be that perhaps the zip, base64-encoded, is in the wrong format. But other than that I really don't know what could be the problem.

Do you have any idea on what the problem is ?

Knowing that I don't have access to customer support, do you know how I could debug that ?

14
  • 1
    Please include the complete GACK ID in your question instead of 9268... Sep 20, 2022 at 13:32
  • 1
    Hi @Swetha, just edited my post to add the full GACK ID
    – Uj Corb
    Sep 20, 2022 at 14:25
  • 1
    Obviously a 500 is tough to debug without access to the server on which the error occurred. But are you perhaps deploying stuff that breaches a limit somewhere, either within the org or on the Metadata API?
    – dyson
    Sep 20, 2022 at 14:30
  • 3
    Depending on how much stuff you are deploying, you may need to selectively remove stuff until you have a working deployment, or start with a small deployment and add stuff until it stops working
    – dyson
    Sep 20, 2022 at 14:30
  • 1
    did you try to deploy the file via Workbench as an alternative?
    – cropredy
    Sep 23, 2022 at 4:48

1 Answer 1

1

So I finally made it work.

In my request body, each end of line is made of a "new line" character : \n.

Turns out I had to add a carriage return (\r) and a new line character together at each end of line in order to make it work : \r\n.

See this SO thread for more info on those characters.

I wrote my request in Ruby, here is a sample. You can adapt it to any programming language you want :

    zipfile_path = generate_tmp_metadata_deploy_package

    uri = URI.parse("#{my_domain}/services/data/v56.0/metadata/deployRequest")
    boundary = "--------------------------BOUNDARY"
    header = {
      Authorization: "Bearer #{my_access_token}",
      "Content-Type": "multipart/form-data; boundary=#{boundary}"
    }
    post_body = []
    post_body << "--#{boundary}\r\n"
    post_body << "Content-Disposition: form-data; name=\"json\"\r\n"
    post_body << "Content-Type: application/json\r\n"
    post_body << "\r\n"
    post_body << "{\r\n"
    post_body << "\"deployOptions\" :\r\n"
    post_body << "{\r\n"
    post_body << "\"allowMissingFiles\" : false,\r\n"
    post_body << "\"autoUpdatePackage\" : false,\r\n"
    post_body << "\"checkOnly\" : false,\r\n"
    post_body << "\"ignoreWarnings\" : false,\r\n"
    post_body << "\"performRetrieve\" : false,\r\n"
    post_body << "\"purgeOnDelete\" : false,\r\n"
    post_body << "\"rollbackOnError\" : false,\r\n"
    post_body << "\"runTests\" : null,\r\n"
    post_body << "\"singlePackage\" : true,\r\n"
    post_body << "\"testLevel\" : \"RunAllTestsInOrg\"\r\n"
    post_body << "}\r\n"
    post_body << "}\r\n"
    post_body << "----------------------------BOUNDARY\r\n"
    post_body << "Content-Disposition: form-data; name=\"file\"; filename=\"#{File.basename(zipfile_path)}\"\r\n"
    post_body << "Content-Type: application/zip\r\n"
    post_body << "\r\n"
    post_body << File.read(zipfile_path)
    post_body << "\r\n----------------------------BOUNDARY--\r\n"

    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    request = Net::HTTP::Post.new(uri.request_uri, header)
    request.body = post_body.join

    http.request(request)

You must log in to answer this question.

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