This issue is killing us for more than a week now as there is no helpful information from the WC1 server on this issue. We are keep on getting this error System.HttpResponse[Status=Bad Request, StatusCode=400
We are using Salesforce Apex to create the JSON string and the request headers. Here is the code below. No matter whatever we do, your server just responded with 400 bad request with no additional info to debug the issue. We have changed the JSON to many format but all the efforts are in vain.
If your server returning bad request, atleast please give us a clue what you are getting as a request from us.
PLEASE GIVE US SOME INSIGHTS ON WHAT YOUR SERVER IS EXPECTING.
public with sharing class testingscenario
{
public static String generateAuthHeader(String dataToSign)
{
String algorithmName = 'HmacSHA256';
Blob hmacData = Crypto.generateMac(algorithmName, Blob.valueOf(dataToSign), Blob.valueOf('*************************'));
return EncodingUtil.base64Encode(hmacData);
}
@Future(callout = true)
public static void getvalues(String JsonString)
{
String gatewayurl = '/v1/';
String gatewayhost = 'rms-world-check-one-api-pilot.thomsonreuters.com';
String apikey = '***************************';
String apisecret = '*******************************';
String contentType = 'application/json';
String ND=Datetime.now().formatGMT('EEE, dd MMM yyyy HH:mm:ss z');
//String jsonBody = '{\"secondaryFields\":[],\"entityType\":\"INDIVIDUAL\",\"customFields\":[],\"groupId\":\"*********************\",\"providerTypes\":[\"WATCHLIST\"],\"name\":\"george w bush\"}';
JSONGenerator gen = JSON.createGenerator(true);
List<String> str1 = new List<String>();
List<String> str2 = new List<String>();
str2.add('WATCHLIST');
// Write data to the JSON string.
gen.writeStartObject();
gen.writeObjectField('secondaryFields', str1);
gen.writeStringField('entityType', 'INDIVIDUAL');
gen.writeObjectField('customFields',str1);
gen.writeStringField('groupId', '*********************************');
gen.writeObjectField('ProviderTypes', str2);
gen.writeStringField('name', 'george');
gen.writeEndObject();
// Get the JSON string.
String pretty = gen.getAsString();
System.debug('json string:>>>>>>>>>'+pretty );
String content = pretty ;//JSON.serialize(gen);
Integer Contentlength=pretty.length();
System.debug('Contentlengthhhhhh'+Contentlength);
/*
String dataToSign = '(request-target): post' + gatewayurl+ 'cases\n' +
'host: ' + gatewayhost + '\n' +
'date: ' + ND +'\n'+
'content-type: '+contentType +'\n' +
'content-length: '+ Contentlength + '\n' +
content;
*/
String dataToSign1 = '(request-target): post ' + gatewayurl + 'cases\n' +
'host: ' + gatewayhost + '\n' +
'date: ' + ND + '\n' +
'content-type: ' + contentType +'\n' +
'content-length: ' + contentLength + '\n' +
pretty;
String hmac = generateAuthHeader(dataToSign1);
String authorisation = 'Signature keyId=\"' + apikey + '\",algorithm=\"hmac-sha256\",headers=\"(request-target) host date content-type content-length\",signature=\"' + hmac + '\"';
System.debug('authorisation Result'+authorisation);
System.debug('dataToSign Result'+dataToSign1 );
System.debug('hmac Result'+hmac);
HttpRequest request = new HttpRequest();
request.setEndpoint('https://rms-world-check-one-api-pilot.thomsonreuters.com/v1/cases');
request.setMethod('POST');
request.setTimeout(120000);
request.setHeader('Authorization',authorisation);
request.setHeader('Date',ND);
request.setHeader('Cache-Control', 'no-cache');
request.setHeader('Content-Type', 'application/json');
request.setHeader('Content-Length', String.valueOf(contentlength));
Http http = new Http();
HTTPResponse res = http.send(request);
}
}