You need to sign in to do that
Don't have an account?

HTTP POST bad request error.
Hi Guys,
Below is the format in which i had to send data.
POST https://<target_domain>/db/main HTTP/1.0
Content-Type: application/xml
Content-Length:
QUICKBASE-ACTION: API_Authenticate
<qdbapi>
<username>PTBarnum</username>
<password>TopSecret</password>
<hours>24</hours>
<udata>optional data</udata>
</qdbapi>
Below is the APEX class i am using to build the above request.
I get bad request as the responce.
i need some help in finding out where i am going wrong.
Thanks,
Vishnu
Below is the format in which i had to send data.
POST https://<target_domain>/db/main HTTP/1.0
Content-Type: application/xml
Content-Length:
QUICKBASE-ACTION: API_Authenticate
<qdbapi>
<username>PTBarnum</username>
<password>TopSecret</password>
<hours>24</hours>
<udata>optional data</udata>
</qdbapi>
Below is the APEX class i am using to build the above request.
HttpRequest req = new HttpRequest(); HttpResponse res = new HttpResponse(); Http http = new Http(); string test = ' <qdbapi><username>xx</username><password>xx</password><hours>24</hours><udata>optional data</udata></qdbapi>'; req.setEndpoint('https://oneroofenergy.quickbase.com/db/main HTTP/1.0'); req.setheader('content-Length',''); req.setheader('QUICKBASE-ACTION','API_Authenticate'); req.setHeader('Content-Type', 'application/xml'); req.setMethod('POST'); req.setBody(test); res = http.send(req); system.debug(res);
I get bad request as the responce.
i need some help in finding out where i am going wrong.
Thanks,
Vishnu
I think the actual problem is with your endpoint.
Please remove the HTTP/1.0 from the endpoint. You will get the response. If you mention the HTTP/1.0 - it is becoming a part of the end url and there is no such url. Thus your getting a 400 code.
Other than that your code is okay. I have tried out the endpoint and I have received a success message.
Your code should be something like this:
Thanks,
Kaustav
All Answers
global with sharing class LmsRestApiIntegration {
//LmsRestApiIntegration.invokeRestAPI();
@future(callout = true)
global static void invokeRestAPI(){
String URL = 'http://fdfdfsdfsfsd/QuickQuoteWebSvc/QQWebSvc.asmx?op=GetCityListFromZip' ;
String xmlContent = '';
xmlContent = '<?xml version="1.0" encoding="utf-8"?>';
xmlContent = xmlContent + '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
xmlContent = xmlContent + '<soap:Body>';
xmlContent = xmlContent + '<GetCityListFromZip xmlns="http://www.fdfdfsdfsfsd.com/irv/quickquote/auto/2006/10/01">';
xmlContent = xmlContent + '<zipcode>89008</zipcode></GetCityListFromZip>';
xmlContent = xmlContent + '</GetCityListFromZip>';
xmlContent = xmlContent + ' </soap:Body>';
xmlContent = xmlContent + '</soap:Envelope>';
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setBody(xmlContent);
req.setHeader('content-type','text/xml');
req.setHeader('content-length', '0');
req.setEndpoint(URL);
req.setHeader('SoapAction', 'http://www.fdfdfsdfsfsd.com/irv/quickquote/auto/2006/10/01/GetCityListFromZip');
req.setMethod('POST');
String response = '' ;
HttpResponse res = h.send(req);
response = res.getBody();
System.debug('Response :'+response);
}
}
I think the actual problem is with your endpoint.
Please remove the HTTP/1.0 from the endpoint. You will get the response. If you mention the HTTP/1.0 - it is becoming a part of the end url and there is no such url. Thus your getting a 400 code.
Other than that your code is okay. I have tried out the endpoint and I have received a success message.
Your code should be something like this:
Thanks,
Kaustav