Search code examples
f#type-providersf#-data

Consuming Yellow Pages.com using FSharp Type Providers


I signed up for the yellow pages.com API program found here: https://publisher.yp.com/home.

I went to make a call like this and I am getting back JSON in the browser: http://pubapi.atti.com/search-api/search/devapi/search?term=Jumbo+China+5&searchloc=6108+Falls+Of+Neuse+Rd+27609&format=json&key=ZZZZZZZZ

When I take the json results and put it into Json2CSharp, it renders fine. When I try and load it into a type provider:

type RestaurantListingJson = JsonProvider< @"http://pubapi.atti.com/search-api/search/devapi/search?term=Jumbo+China+5&searchloc=6108+Falls+Of+Neuse+Rd+27609&format=json&key=ZZZZZZZ">

I get a 400

Looking at fiddler, I see "User agent is a required field"

Has anyone run into this before? How do I add a user agent to a type provider?

Thanks in advance


Solution

  • The latest version of F# Data now always sends user agent and accept headers, so this should now work directly:

    type RestaurantListingJson = JsonProvider<"http://pubapi.atti.com/search-api/search/devapi/search?term=Jumbo+China+5&searchloc=6108+Falls+Of+Neuse+Rd+27609&format=json&key=ZZZZZZZ">