You need to sign in to do that
Don't have an account?
wixxey
No response after making a POST request
Hi!
I am calling an API of FluidSurvey. when i make a POST request ... it post the request on the fluidSurvey but i didnt get the JSON response. rather it returns nothing. any suggestion??
my controller code
public class fluidSurvey{ public String tst{set;get;} public String result{get;set;} public PageReference chk() { getData(); return null; } public void getData(){ String apiKey = 'xxxxxx'; String pwd = 'xxxxxx'; String u = 'https://app.fluidsurveys.com/api/v2/surveys/survey_id/responses/'; HttpRequest req = new HttpRequest(); Http http = new Http(); HTTPResponse res; try{ req.setEndPoint(u); req.setTimeout(20000); req.setMethod('POST'); Blob headerValue = Blob.valueOf(apikey + ':' + pwd); String authorizationHeader = 'Basic '+ EncodingUtil.base64Encode(headerValue); req.setHeader('Authorization', authorizationHeader); req.setHeader('Content-Type', 'application/json'); req.setHeader('Content-Length','31999'); res = http.send(req); tst= res.toString(); catch(Exception e){ System.debug('Callout error: '+ e); System.debug(tst+'--------'+res); } } }
and the Apex page code is
<apex:page controller="newFS"> <center> <apex:form > <apex:pageBlock title="New Fluid Surveys API"> <apex:outputText value="{!tst}"></apex:outputText><br/> <apex:pageBlockButtons location="bottom"> <apex:commandButton value="Submit" action="{!chk}"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </center> </apex:page>
and api documentation link is http://docs.fluidsurveys.com/api/surveys.html#getting-a-list-of-surveys..
You're setting a content-length header, but not setting any body,the server is dilligently waiting for the 3199 byte body you said you were going to send to turn up, and so you get the timeout exception you're seeing.
Also res.toString() will just return the server stautus like (200 OK, etc), not the actual response body, you need to use getBody() for that.
All Answers
Hi Wixxey,
In debug log check are able to hit the URL and try to debug for response
System.debug(res.getBody());
Regards,
Varun
This is the Log
Hi,
put reg.setTimeOut(2000); in your code. I think headervalues are not seted properly so you are getting read time out error.
i have set the timeout to 20000 but it still has the same problem
Hi wixxey,
You are not passing api key,survey id etc. required variable to pass in URL. I just find api documentation on Goolg. You should pass required variables in URL.
Here is link for api:
http://fluidsurveys.com/api/
This version of the API is no longer supported. they are using a new version now. if you click on the link you have given contain the path of their new api documentation
Hey,
Is your request from salesforce trying to access something which is running behind firewall?
You're setting a content-length header, but not setting any body,the server is dilligently waiting for the 3199 byte body you said you were going to send to turn up, and so you get the timeout exception you're seeing.
Also res.toString() will just return the server stautus like (200 OK, etc), not the actual response body, you need to use getBody() for that.
Hi,
Remove ezqcp. from URL and try the following url
https://fluidsurveys.com/api/v2/surveys/26814/responses/
After setting the URL the new Log is
Have u incorportaed changes suggested by Simon?
Thanx SimonF ... your suggestion works for me after setting the getBody method my code works.. and thanx to all others who give there precious time