apex code - POST Request unable to receive the JSON respose in Salesforce -


i calling api of fluidsurvey. when make post request ... post request on fluidsurvey didnt json response. rather returns nothing. 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(2000);         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 apex page code is

<apex:page controller="fluidsurvey">  <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> 

and api documentation link http://docs.fluidsurveys.com/api/surveys.html#getting-a-list-of-surveys..

fluidsurveys dev here.

looks you're doing post request, according docs creating new response. function named getdata, i'm assuming want list of responses?

change request type post , should start work.

also, response type application/json, shouldn't setting request type encoding.

if i'm mistaken , you're looking submit new response, code wouldnt work because you're not passing content. can see http://docs.fluidsurveys.com/api/surveys.html#submitting-a-new-response need pass dictionary of question ids , answers. best way figure out ids or format is, first @ response returned request.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -