The XML you provided was not well-formed or did not validate against our published schema: while calling S3 bucket from Salesforce - amazon-s3

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!

Set the content type as 'application/xml' instead of 'application/json;charset=UTF-8'
req.setHeader('Content-Type', 'application/xml');

Related

POST array body in RESTSHARP

I have been using RESTSHARP automating REST API test cases. So far I am familiar in using JObject like:
public IRestResponse HELPERS_POST(JObject input)
{
...
request.RequestFormat = DataFormat.Json;
request.AddParameter("text/json", input, ParameterType.RequestBody);
...
My problem now is I have a new API with the following information:
Parameters: nodeIds Parameter
Type: body
Data Type: Array[long] or as example {[12345,23453,45332]}
I parsed the above as JArray.
Now I don't know what to do with this JArray so my HELPERS_POST() can use it to make a POST request.

API Connect 5 - Error attempting to read the urlopen response data

I'm trying to create a REST API from a SOAP Service using IBM API Connect 5. I have followed all the steps described in this guide (https://www.ibm.com/support/knowledgecenter/en/SSFS6T/com.ibm.apic.apionprem.doc/tutorial_apionprem_expose_SOAP.html).
So, after dragging the web service block from palette, ensuring the correctness of endpoint and publishing the API, I have tried to call the API from the browser. Unfortunately, the API return the following message:
<errorResponse>
<httpCode>500</httpCode>
<httpMessage>Internal Server Error</httpMessage>
<moreInformation>Error attempting to read the urlopen response
data</moreInformation>
</errorResponse>
To testing purpose, I have logged the request and I have tried the request on SOAPUI. The service return the response correctly.
What is the problem?
In my case, the problem was in the backend charset (Content-Type: text/xml;charset=iso-8859-1).
For example, backend returns text/xml in German (or French). Api Connect cannot process character ü. It needs Content-Type: text/xml;charset=UTF-8.
I had a similar issue, in my case was the accept. if you have an Invoke and the content-type or the accept, is not matching the one of the request, or the response that you got, APIC is getting mad.
Please, check if the formats to send (contentType) and receive (accept) are the same of that your API expected. In my case the error occurs because the API returns a String and my default code is configured to receive a JSON body.
//define a JSON-PLAIN TEXT protocol
private HttpEntity<String> httpEntityWithBody(Object objToParse){
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "Bearer " + "xxx token xxx");
headers.set("Accept", MediaType.TEXT_PLAIN_VALUE);
headers.setContentType(MediaType.APPLICATION_JSON);
Gson gson = new GsonBuilder().create();
String json = gson.toJson(objToParse);
HttpEntity<String> httpEntity = new HttpEntity<String>(json, headers);
return httpEntity;
}
//calling the API to APIC...
ParameterizedTypeReference<String> responseType = new
ParameterizedTypeReference<String>(){};
ResponseEntity<String> result =
rest.exchange(builder.buildAndExpand(urlParams).toUri(), HttpMethod.PUT, httpEntityWithBody(myDTO), responseType);
String statusCode = result.getStatusCodeValue();
String message = result.getBody();

Microsoft Translator Text API doesn't work

I want to use Microsoft Translator API but I am unable to use it.
I created a Microsoft Azure account as specified in the documentation (http://docs.microsofttranslator.com/text-translate.html) and I created a resource.
When I call the web service to get an access toke, every time I get an exception because a time out..
This is my code (it's Apex, similar to Java) :
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setHeader('Content-Length', '3495');
req.setEndpoint('https://api.cognitive.microsoft.com/sts/v1.0/issueToken?Subscription-Key=[myAPIKey]');
req.setTimeout(20000);
HttpResponse res = h.send(req);
If I remove my API key or I the content length from the header, I get an error from Microsoft.
Do you know why I get this?
Thanks
You should replace [myAPIKey] with the right key. You can get it through https://www.microsoft.com/cognitive-services
EDIT
The answer above is related to GET operations. For POST, you should include the 'Ocp-Apim-Subscription-Key' header:
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setHeader('Content-Length', '3495');
req.setHeader('Ocp-Apim-Subscription-Key', '[INSERT_HERE_YOUR_TOKEN]');
req.setEndpoint('https://api.cognitive.microsoft.com/sts/v1.0/issueToken');
req.setTimeout(20000);
HttpResponse res = h.send(req);
It works fin now.
I edit my code and it is ok :
HttpRequest req = new HttpRequest();
req.setMethod('GET');
req.setEndpoint(theURL);
req.setHeader('Content-Type','application/xml');
Http binding = new Http();
HttpResponse res = binding.send(req);
Thanks

Sending a file with XMLHttpRequest() to Tika server

I'm trying to send a PDF for content extraction to a Tika Server but always get the error: "Cannot convert text from stream using the source encoding"
This is how Tika is expecting the files:
"All services that take files use HTTP "PUT" requests. When "PUT" is used, the original file must be sent in request body without any additional encoding (do not use multipart/form-data or other containers)." Source https://wiki.apache.org/tika/TikaJAXRS#Services
What is the correct way of sendig the file with XMLHttpRequest()?
Code:
var response, error, file, blob, xhr;
file = new File("/PROJECT/web/dateien/ai/pdf.pdf");
blob = file.toBuffer().toBlob("application/pdf");
url = "http://localhost:9998/tika";
// send data
try {
xhr = new XMLHttpRequest();
xhr.open("PUT", url);
xhr.setRequestHeader("Accept", "text/plain");
xhr.send(blob);
} catch (e) {
error = e;
}
({
response: xhr.responseText,
status: xhr.statusText,
error: error,
type: xhr.responseType,
blob: blob
});
Error:
I suspect PUT request to be converted into a POST request by wakanda when there is blob in XHR body. Can you wireshark your XHR request and add details ? If so, you can probably fill an issue in wakanda (https://github.com/Wakanda/wakanda-issues/issues)
Hope it helps,
Yann

BadRequest when try Create folder via REST

I've downloaded a exampled that show the files in the "Shared with everyone" folder in my OneDrive for Bussiness. It's work fine!
But, when I try to create a Folder or File (without content) like this documentation the response became with a BadRequest .
The request goes like:
string requestUrl = String.Format(CultureInfo.InvariantCulture, "{0}/files", serviceInfo.ApiEndpoint);
// Prepare the HTTP request:
using (HttpClient client = new HttpClient())
{
Func<HttpRequestMessage> requestCreator = () =>
{
HttpRequestMessage request = new HttpRequestMessage( HttpMethod.Post, requestUrl);
request.Headers.Add("Accept", "application/json;odata.metadata=full");
request.Content = new StringContent(#"{'__metadata':{'type':'MS.FileServices.Folder'},Name:'TestFolder'}");
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
return request;
};
}
And the response is a BadRequest.
I think that my problem is in the "__metadata"'s json value. It´s is correct? Where can I find a working example implementing this operations?
Thanks in advance!
EDIT: Changing the API Endpoint from "/_api/web/getfolderbyserverrelativeurl('Documents')/files" to "_api/files" the error became to: "The property '__metadata' does not exist on type 'MS.FileServices.FileSystemItem'. Make sure to only use property names that are defined by the type."
I´m think I foward in this. But, I still continue with problems.
I am not sure if this can be of any help to you, as this pertains to oneDrive and not oneDrive for business.
Also the documentations are confusing :)
according to the documentation the request should be as follow:
POST https://apis.live.net/v5.0/me/skydrive
Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json
{
"name": "My example folder"
}
if you can see that in the header there is authorization access token
I don't see that you sent to the server any access token. and that is why you had a bad request.
I am trying to below way to create a folder in SP and it's working for me. Hope it will work for you as well.
Create a folder using SharePoint Web API -
POST https://<Domain>.sharepoint.com/_api/web/folders
Accept: "application/json;odata=verbose"
Content-Type: "application/json"
{
"ServerRelativeUrl": "/Shared Documents/<Folder-Name>"
}