+ Reply to Thread
Results 1 to 17 of 17

Loop to do Whitepages API calls?

  1. #1
    Registered User
    Join Date
    08-13-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    10

    Loop to do Whitepages API calls?

    Hi - I've sen some past discussions helping people use the whitepages API in excel, is there anybody around still who knows how to do this? I'm actually a new account executive at Whitepages trying to help one of my customers who wants to write a macro which will go through a list of addresses, and for each one build the url then send it and format the response correctly.

    It looks pretty easy to send a static API request and Excel seems to automatically download the schema and format the data. I need help with two things:

    1) how do I program into the macro changes in how Excel executes the schema or formats the xml data? I want it to only paste in part of the XML. Specifically I want it to only paste in the lines with something in Column M ("Rank") and only once for each if there are duplicates. If there is a no match found response then it just pasts that field.

    2) how do I write a For loop which will allow it to run through a list or url's, send dynamic requests, then append the responses to the list which it's building in the sheet.

    Here's the static API call which I got to work with my developers key and I've attached a sample spreadsheet with the API url's already completed.

    Sub api()
    '
    ' api Macro

    ActiveWorkbook.XmlImport URL:= _
    "http://api.whitepages.com/reverse_address/1.0/?house= 98;street=Eagle Rest Road;city=Dahlonega;zip=30533-7017;api_key=<<<<PM me for the key if you want to try>>>>" _
    , ImportMap:=Nothing, Overwrite:=False, Destination:=Range("$A$1")
    Range("D17").Select

    End Sub

    I appreciate any advice anyone can give me as I'm trying to get this done without asking for help from our programmers so they can focus on improving the API. Our developers forum has nothing but crickets so I found this place with all the Excel experts. As I go along I expect to have lots of customers who are working with spreadsheets that would love to be able to use a macro to hit our API so I'm trying to learn this. Also, I imagine some of our customers would actually be willing to pay an excel developer to do this so it would be great to build some relationships with you guys!

    Thanks in advance!
    Eric Farnham, Account Executive Whitepages.com Pro
    Attached Files Attached Files
    Last edited by efarnham; 08-15-2011 at 12:31 PM.

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Loop to do Whitepages API calls?

    What columns define the found rows as duplicate, M:P or N:P? Which of the imported columns do you want saved? Input data A:E should be enough to build your link. Maybe you could post an example of what the output sheet should look like. Obviously, the easier method is to use a scratch sheet and do each run and then get the rows as needed for a summary sheet.

  3. #3
    Registered User
    Join Date
    08-13-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Loop to do Whitepages API calls?

    Thanks so much for helping! I've attached a spreadsheet with a second sheet that has the output from the static API call. In the standard format which Excel copies, Cell's A2 and C2 easily tell if the result was a success and what was found, so if not success I'm only interested in pasting that field and nothing else. For successes, I'm only interested in the lines that have names returned on them, and the rank collumn (M) seems to only have something in it on the lines I want. I really only want columns M through AD copied. I was thinking the macro could check for duplicates because we're only dealing with a few names per API hit usually, but that's not a huge requirement. Great idea about a scratch sheet, I was wondering if for each call it could copy into a scratch sheet and then copy into a final list.
    Attached Files Attached Files

  4. #4
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Loop to do Whitepages API calls?

    Time for sleep so I will post what I have so far. It should be about 80% of what you need and should let us know if we are close.

    I named the first sheet RawData, the 2nd GetDetails, and Scratch for the 3rd sheet. I commented out the full For loop and put in a loop for the first 5 rows. In this way, you can test without wasting too much time.

    I added a 2nd routine that lets you keep the imported XML to a new sheet named A2Sheet for the first RawData row starting with cell A2, A3Sheet for cell A3 and so on. This is just for testing purposes. The first button does the copy and paste from the Scratch sheet where each XML is imported for the main routine. It then removes duplicates. It is a bit off on some rows so I will have to see why later.

    Please Login or Register  to view this content.
    My standard Speed routine is in another Module:
    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    08-13-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Loop to do Whitepages API calls?

    Thanks so much, I'm going to try this out today.

  6. #6
    Registered User
    Join Date
    08-13-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Loop to do Whitepages API calls?

    Kenneth - I'm getting a runtime error, '9' subscript out of range. The debugger points to this line:

    Set rdSheet = ThisWorkbook.Worksheets("RawData")

    I'm sure it's just something I should have put in there in addition to your code, thanks so much for your help.

  7. #7
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Loop to do Whitepages API calls?

    You can rename your sheet with the raw data to RawData or change that code to contain the raw data's sheet name. You will need the GetDetails sheet name and the Scratch sheet names as well or change the sheet names in the code.

  8. #8
    Registered User
    Join Date
    08-13-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Loop to do Whitepages API calls?

    Kenneth - whenever you get a chance, would you be able to attach the spreadsheet as you're using it? I have the sheet open and renamed the first sheet "RawData", the second sheet "GetDetails", and the third sheet "Scratch" and it's still doing the same thing. Could it be that I'm missing some module of VB that's important for this? I just copied your code directly into a module in excel's VB editor.

  9. #9
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Loop to do Whitepages API calls?

    I zipped the file and attached it earlier in the code snippet post. Are zip files a problem for you?

  10. #10
    Registered User
    Join Date
    08-13-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Loop to do Whitepages API calls?

    No, I just missed seeing the attachment. Got it, and yours does work. I'll take a look and let you know if I have any other questions. Thanks!

  11. #11
    Registered User
    Join Date
    08-13-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Loop to do Whitepages API calls?

    Kenneth - This is great, really neat! I'm trying to figure out how to make it go all the way down the list but I'm sure I can figure it out. I showed to my boss and it may be enough of a proof of concept to get some programming resources to help out with this. Thanks very much!

  12. #12
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Loop to do Whitepages API calls?

    Good deal.

    I said earlier that you can process all of the entries. All you have to do is to comment out or delete the For line of code and uncomment the For below it.

    If I get time, I will look into using WinHTTP or this method which is similar:
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    08-13-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Loop to do Whitepages API calls?

    Sorry Kenneth, I missed that. It's awsome! I took programming in college and used to do Basic but I'm afraid my skills are sorely lacking since I've been doing sales forever. Mea culpa, and thanks again.

  14. #14
    Registered User
    Join Date
    08-13-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    10

    Thumbs up Re: Loop to do Whitepages API calls?

    How do I set this thread as Solved? Thanks Kenneth!

  15. #15
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Loop to do Whitepages API calls?

    From the FAQ:

    To mark your thread solved do the following:
    - Go to the first post
    - Click edit
    - Click Advance
    - Just below the word "Title:" you will see a dropdown with the word No prefix.
    - Change to Solve
    - Click Save

  16. #16
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Loop to do Whitepages API calls?

    Here is the other method that I explained. Note the comments on setting the reference and getting your own api key. Once you have the xml string, you can use similar methods or 3rd party xml parsers like ChilKatXML, http://chilkatsoft.com/, to parse the xml data. This method works fast.

    Please Login or Register  to view this content.
    Your sXML value will be:
    Please Login or Register  to view this content.
    Last edited by Kenneth Hobson; 08-17-2011 at 09:26 AM.

  17. #17
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Loop to do Whitepages API calls?

    Here is one final post for those that might want to parse the xml data. This is just a primer to get you started. If you open the xml file and review the Immediate Window's results after you run the two subs, you can start to see the structure and how to get specific parts. Run Test_WhitePagesInfo, open the created WhitePages.xml, and then run Test_ParseXMLWhitePageData. Compare the xml file's data to the Immediate Window.

    You will need get your own api_key as stated earlier. Be sure to set the Microsoft XML, v6.0 reference.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1