2

Folks,

A total newbie here when it comes to making end-to-end integrations. I am trying to "put" my salesforce data to the s3 bucket but receiving:

The XML you provided was not well-formed or did not validate against our published schema

Here's what I am doing:

List<Task> tasks = new List<Task>([SELECT ID from TASK WHERE Id =:recordId LIMIT 1]);
    
    for(Task task:tasks)
    {
        try
        {
            //File Content
            String Body = JSON.serialize(task);
            
            HttpRequest req = new HttpRequest();
            req.setMethod('PUT');
            req.setEndpoint('callout:AWS_Credentials');
            req.setHeader('Content-Type', 'application/json;charset=UTF-8');
            req.setBody(Body);
            
            Http http = new Http();
            HTTPResponse res = http.send(req);

What might I be doing wrong here? Too lost to see..

Thanks in advance!

1 Answers1

0

Set the content type as 'application/xml' instead of 'application/json;charset=UTF-8'

req.setHeader('Content-Type', 'application/xml');
Kamal
  • 486
  • 1
  • 6
  • 14
  • Kamal, tried but of no use. Still getting the same feedback. – Nikhil Somvanshi Apr 08 '22 at 07:58
  • Also, you would need to construct a xml string instead of sending JSON body.. You can refer this link to check how to create XML. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_xml_dom.htm – Kamal Apr 08 '22 at 09:00
  • Just changing header will not help in this case, since the data is serialized in the body as JSON already. This looks like a bug in AWS to me, I saw similar behavior in AWS CLI also. The [documentation examples](https://docs.aws.amazon.com/cli/latest/reference/s3api/put-bucket-lifecycle-configuration.html#examples) imply that I can use JSON but the response still complains about XML format. – Petr Gladkikh Apr 21 '23 at 15:47