Rich-text Reply

Connect Optimizely Rest Api to a google sheet

Nicolas_Hemidy 06-21-16

Connect Optimizely Rest Api to a google sheet

Hi there,

 

I'm trying to connect the Optimizely Rest API to a google sheet in order to preview my experiment results directly into a google sheet. I found this page https://developers.google.com/apps-script/guides/services/external#connecting_to_public_apis explaining how to connect to an API and created the following code into a google script:

 

function ConnectApi() {
var url = '-H"Token:[mytoken]"\"https://www.optimizelyapis.com/experiment/v1/projects/"';
var response = UrlFetchApp.fetch(url);
Logger.log(response);
var json = response.getContentText();
var data = JSON.parse(json);
Browser.msgBox(data.title);
}

 

I get an error every time and It seems that I don't use it in the proper way. 

Does anyone have already done that and could help me?

Thanks a lot in advance,

Nicolas

AllisonR 06-22-16
 

Re: Connect Optimizely Rest Api to a google sheet

[ Edited ]

Hi Nicolas,

 

It looks like there is an issue with the format of the HTTPS request you are trying to send. You'll need to send the token in the header of the request. This is one way to do so: 

 

function ConnectApi() {
	var token = [yourToken];
	var url = "https://www.optimizelyapis.com/experiment/v1/projects/";
	var headers = {
		"Token": token
	};
	var options = {
		"headers": headers
	};
	var response = UrlFetchApp.fetch(url, options);
	Logger.log(response);
	var json = response.getContentText();
	return json;
}

You'll need to fill in your API token as a string in the above sample. You can grab your API token here: https://app.optimizely.com/tokens 

 

Does this work for you? 

Allison
Sr. Technical Support Engineer
Optimizely | EMEA
Optimizely