Web Service Failing to Connect

I have been attempting to use the ESV bible API to create a drafts action that will pull in bible verses based on highlighted text. I have made this work using workflow but it would be nice to have it integrated and not have to leave the drafts app. That being said, I have tried and tried to get this code to work but nothing seems return a successful response. Every time I run the script I get a -1 response from the http.request.

Here is what I have for my code. I have striped everything down to the bear minimum at this point

var http = HTTP.create();

//I took my token out for obvious reasons. 
var credential ="1234";

var response = http.request({
  	"method":"GET", 
	"url":"https://api.esv.org/v3/passage/text/", 
	"headers": {
		"Authorization":"Token "+ credential	
	},
	"data": {
		"q":"john3:16"
	}
});

if (response.success) {
  var text = response.responseText;
  var data = response.responseData;
}
else {
  console.log(response.statusCode);
  console.log(response.error);
}

I have tried other web services from drafts and had no issue. I also took all this data and ran it from an Ajax function from my browser which had no issue and I ran it through a couple API tools as well just to make sure the issue wasn’t server side.

Any help would be appreciated.

Thanks,
Nathan

The data option is for data which gets send in the body of a POST request. It looks like ESV wants parameters in the URL query. So, something like:

var response = http.request({
  	"method":"GET", 
	"url":"https://api.esv.org/v3/passage/text/?q=john%203:16", 
	"headers": {
		"Authorization":"Token "+ credential	
	}
});

This is untested, but try it.

1 Like

Well thanks! I had previously tried handling it this way but I was getting the same timeout error. Not sure why it works this time and didn’t when I tried previously but I will take it. Thanks again!