Get email using Hunter IO API with Google Apps Script [closed] - google-apps-script

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
Hello fellow developers,
I am trying to get the email count for any website using Hunter IO free API with Google Apps Script.
Hunter IO API reference : https://hunter.io/api/v2/docs#email-count
Here is my code.
function checkDomain() {
var domain = 'stripe.com';
var url = 'https://api.hunter.io/v2/email-count?domain='+domain;
var response = UrlFetchApp.fetch(domain);
var result = response.getContentText();
Logger.log(JSON.parse(result)); // <-- Line 56
}
I get this Error : SyntaxError: Unexpected token: < (line 56, file "Code")
Can anyone please help me understand this error and tell me how to retrieve a JSON response from this Hunter IO.

You need to pass url and not domain variables.
var response = UrlFetchApp.fetch(url);
I would also recommend the use of string constructors. Its increase readability and understanding of the code.
var domain = 'stripe.com';
var template = 'https://api.hunter.io/v2/email-count?domain=%s';
var url = Utilities.formatString(template, domain);

Related

How should I go about parsing and using website data? I am using node js [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I am using node js to create a bot that gets stats from r6.tracker.network, but when I load it in the data won't show up unlike when I have 'www.google.com' as the host. I don't really know where to go from here. I'm trying to use several different debugging methods, but I haven't found anything yet. There is no output.
function getWebpage(parameter){
const pathuser = '/profile/pc/' + parameter;
var http = require('http');
var options = {
host: 'r6.tracker.network',
path: '/'
}
var request = http.request(options, function (res) {
var data = '';
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function () {
console.log(data);
});
});
request.on('error', function (e) {
console.log(e.message);
});
request.end();
}
They are redirecting you to the https version of their site.
The key here is to add this logging:
console.log(res.statusCode);
console.log(res.headers.location);
When you do that, you will see this:
301
https://r6.tracker.network/
In other words, they want you to use the https version of their site and they are redirecting you to do that. You won't get the content of the web page from the http URL. You have to use https.
Coding takeaways here:
Always look at the http status and only proceed normally if you get a 2xx response.
Be prepared for 3xx redirect responses.
FYI, if you use a more modern library such as got() or any of the other libraries listed here, they will all follow redirects for you automatically and they will gather the full response for you automatically too. And, they use the more modern promise-based method of asynchronous programming. I'd really suggest you pick one of those libraries for your outbound http requests.

calling methods that get values from a spreadsheet from other scripts [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have two scripts, each one bounded to different spreadsheets. Just script one is bounded to a cloud project while script two is not. I saved the first script version with identifier: "scriptOne"
This is the function in script 1 (which does return the value I want when using the log):
var ss = SpreadsheetApp.getActive().getSheetByName("someSheet");
var one = ss.getRange(2, 1).getValue();
function scriptOneFunction() {
return one;
}
I have a second script and i made sure to select scriptOne.v1 within libraries (development mode "on") and now I am trying to call this function from the second script as follows:
function callScriptOne() {
var two = scriptOne.scriptOneFunction();
Logger.log(two);
}
The error I get:
TypeError: Cannot read property 'getRange' of null
at [scriptOneFunction](callScriptOne:2:17)
What am i doing wrong?
There are two possible issues with your approach:
Your second script is not bound to a google spreadsheet.
If 1) is not the issue, then check if the spreadsheet has indeed a sheet with the name someSheet.
Related:
TypeError: Cannot call method "getRange" of null. (line 9, file "Code")
TypeError: Cannot call method "getRange" of null. (line 4, file "Code"

Using events.patch in Google Apps script [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I'm writing a Google apps script to update an event. I tried using the path API like below:
event_ins.setVisibility('private');
Logger.log('Making event %s %s private %s',calendarId, event_ins.summary, event_ins);
Calendar.Events.patch(event_ins,calendarId, eventID_ins);
I get the following error message:
11:28:30 AM Error HttpResponseException: Response Code: 404. Message: Not Found.
I tried using the update method instead
Calendar.Events.update(event_ins,calendarId,eventID_ins);
I'm still getting the same error.
The examples in Google's API documentation does not use Google script. I tried searching example code and I found similar usage. For instance this is from here :
event = Calendar.Events.patch(event, calendarId, eventId, {
sendNotifications: true
});
I would appreciate any help to get this working.

Import JSON document array / object to a Meteor Collection with correct _ids [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
What is the best way to import a 15,000 document json file of a format (but with a +30 foo fields)
[{"foo1":"foo1data1", "foo2":"foo2data1"}, {"foo1":"foo1data2", "foo2":"foo2data2"}...
{"foo1":"foo1dataN", "foo2":"foo2dataN"}])
to a Meteor collection?
I tried with mongoimport but that created ObjectID's instead of _id's and I could not make it work without autopublish, although other collections, created with Meteor, work just fine on client side.
Supposing the file is located on the server under pathToFile you can do something like this:
var fs = Npm.require("fs");
var Fiber = Npm.require("fibers");
fs.readFile(pathToFile, 'utf8', function (err, data) {
// handle error if there is some
data = JSON.parse(data);
Fiber(function () {
_.each(data, function (document) {
SomeMeteorCollection.insert(document);
});
}).run();
});
Please note that Fiber wrapper is required if you want call any meteor specific routines, for example collections API, within some nodejs asynchronous code.

Tracking API for Fedex and UPS [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Is there any JavaScript API available for tracking Fedex and UPS packages?
I googled for something like this but couldn't find anything. Then I decided to do it server side in ROR.
Here it is how to get UPS and Fedex xml request and response from their test servers.
For Fedex:
track_no = '111111111111' # This is a test tracking number
# This XML Request body for fedex
xml_req =
"<TrackRequest xmlns='http://fedex.com/ws/track/v3'><WebAuthenticationDetail><UserCredential><Key>YOUR_ACC_KEY</Key>
<Password>YOUR_ACC_PASSWORD</Password></UserCredential></WebAuthenticationDetail><ClientDetail>
<AccountNumber>YOUR_ACC_NUMBER</AccountNumber><MeterNumber>YOUR_ACC_METER_NUMBER</MeterNumber></ClientDetail>
<TransactionDetail><CustomerTransactionId>ActiveShipping</CustomerTransactionId></TransactionDetail>
<Version><ServiceId>trck</ServiceId><Major>3</Major><Intermediate>0</Intermediate><Minor>0</Minor></Version>
<PackageIdentifier><Value>#{track_no}</Value><Type>TRACKING_NUMBER_OR_DOORTAG</Type></PackageIdentifier>
<IncludeDetailedScans>1</IncludeDetailedScans></TrackRequest>"
path = "https://gatewaybeta.fedex.com:443/xml"
#this url connects to the test server of fedex
# for live server url is:"https://gateway.fedex.com:443/xml"
url = URI.parse(path)
http = Net::HTTP.new(url.host,url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
response = http.post(url.path, xml_req)
response_body = response.body
res = response_body.gsub(/<(\/)?.*?\:(.*?)>/, '<\1\2>')
hash = Hash.from_xml(res.to_s)
And that's it! You will get response in hash variable, I converted xml response in to Hash because we can easily use Hash object at our view to display response data.
For UPS:
track_no = '1Z12345E1512345676' # This is a test tracking number
# This XML Request body for UPS
xml_req =
'<?xml version="1.0"?><AccessRequest xml:lang="en-US"><AccessLicenseNumber>YOUR_ACC_LICENCE_NUMBER</AccessLicenseNumber>
<UserId>YOUR_ACC_USER_ID</UserId><Password>YOUR_ACC_PASSWORD</Password></AccessRequest>
<?xml version="1.0"?><TrackRequest xml:lang="en-US"><Request><TransactionReference>
<CustomerContext>QAST Track</CustomerContext><XpciVersion>1.0</XpciVersion></TransactionReference>
<RequestAction>Track</RequestAction><RequestOption>activity</RequestOption></Request>
<TrackingNumber>#{track_no}</TrackingNumber></TrackRequest>'
path = "https://www.ups.com/ups.app/xml/Track"
url = URI.parse(path)
http = Net::HTTP.new(url.host,url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
response = http.post(url.path, xml_req)
response_body = response.body
hash = Hash.from_xml(response_body.to_s)
This hash variable contains the response of UPS Tracking Request in Hash format.
another easy way to do it: Just create a hyperlink with the following href
UPS:
http://wwwapps.ups.com/WebTracking/track?loc=en_US&track.x=Track&trackNums=put_tracking_number_here
FEDEX:
http://fedex.com/Tracking?action=track&language=english&cntry_code=us&tracknumbers=put_tracking_number_here
(not as elegant, but quick, easy and gets the job done!)
Or you can use the active_shipping gem for a nicer and cleaner way to track your packages for Fedex and UPS