2
public class SendWaveUsingRESTAPI {
 private final String clientId = 'xxxx';
 private final String clientSecret = 'xxx';
 private final String username = 'xxxxx';
 private final String password = 'xxxxxx';
 public class deserializeResponse
 {
 public String id;
 public String access_token;
 }
 public class deserializewaveresp
 {
 public String action;
 public String responseId;
 public String results;
 public String query;
 public String responseTime;
 }
 public void ReturnAccessToken()
 {
 String reqbody = 'grant_type=password&client_id='+clientId+'&client_secret='+clientSecret+'&username='+username+'&password='+password;
 Http h = new Http();
 HttpRequest req = new HttpRequest();
 req.setBody(reqbody);
 req.setMethod('POST');
 req.setEndpoint('https://XXXXXX.salesforce.com/services/oauth2/token');
 HttpResponse res = h.send(req);
 system.debug('######access_token####'+res.getbody());
 deserializeResponse resp1 = (deserializeResponse)JSON.deserialize(res.getbody(),deserializeResponse.class);
 system.debug('@@@@access_token@@'+resp1);
 if(resp1.access_token!=null)
 {
 String endPoint ='https://XXXXXX.salesforce.com/services/data/v36.0/wave/query';
 String jsonstr ="{"query":"q = load \"datasetId/versionid\";\n+q = group q by ('Name','Wac.cc');\n+q = foreach q generate 'Name' as 'Name','Wac.cc' as 'Wac.cc', count() as 'count';\n+q = order q by ('Name' asc,'wac.cc' asc);\n+q = limit q 2;\\"}";
 Http h2 = new Http();
 HttpRequest req1 = new HttpRequest();
 req1.setHeader('Authorization','Bearer ' +resp1.access_token);
 req1.setHeader('Content-Type','application/json');
 req1.setHeader('accept','application/json');
 req1.setBody(jsonstr);
 req1.setMethod('POST');
 req1.setEndpoint(endPoint);
 HttpResponse res1 = h2.send(req1);
 deserializewaveresp resp2 = (deserializewaveresp)JSON.deserialize(res.getbody(),deserializewaveresp.class);
 system.debug('@@@RESPONSE@@'+resp2);
 }
 }
}

I am trying to pass wave SAQL query to Wave REST API. But this is returning an error code:

bad request error 400.

Can anyone know how the request body has to be given for the wave rest query resource ?

1

we need to sereilize the request body SAQL to json string.Now i am getting response

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.