+ Start a Discussion
Mariappan PerumalMariappan Perumal 

Http Callout Issue

Hi Everyone,

 

I have created endpoint URL for google analytics,

 

https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A731335&dimensions=ga%3Adate&metrics=ga%3Avisitors%2Cga%3AnewVisits&start-date=2013-04-01&end-date=2013-05-01&max-results=50

then how to add remaining attributes in HttpRequest ?

For example,,

HttpRequest req = new HttpRequest();

req.setEndpoint('https://www.googleapis.com/analytics/v3/data');

My Question is how to add remaining attribute that mean like (ids=ga%3A731335) in the same class, and how to call this?

ForceMantis (Amit Jain)ForceMantis (Amit Jain)
Try this way, so you need to set request method to get so that parameter are passed in url and then add name value pair in request body. HTTP class will use these to do http callout.

HttpRequest req = new HttpRequest();
req.setEndpoint('http://www.yahoo.com');
req.setMethod('GET');

// Specify the required user name and password to access the endpoint
// As well as the header and header information

String username = 'myname';
String password = 'mypwd';

Blob headerValue = Blob.valueOf(username + ':' + password);
String authorizationHeader = 'BASIC ' +
EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);

// Create a new http object to send the request object
// A response object is generated as a result of the request

Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody());
Mariappan PerumalMariappan Perumal

Hi amit,

 

Nice to hear from you. I tried  this one but unfortantely that was not the answer for this. I mean that was not working.

 

I am trying to use setheader method to get n no of parameter concat to endpoint to url .I am not sure with that way.

 

If you know any other way kindly let me know.

 

Thanks in advance