Skip to content

API Usage Power Query Example

Wil Collins edited this page Sep 1, 2022 · 2 revisions

search/spending_by_geography

This code snippet demonstrates how to make a POST request to the spending_by_geography endpoint at https://api.usaspending.gov/api/v2/search/spending_by_geography/ using Excel Power Query. This snippet was designed as an interactive exercise for a training on the USAspending API.

let
    url = "https://api.usaspending.gov/api/v2/search/spending_by_geography/",
    body = "{
        ""scope"": ""recipient_location"",
        ""geo_layer"": ""district"",
        ""filters"": {
            ""time_period"": [
                {
                    ""start_date"": ""2020-10-01"",
                    ""end_date"": ""2021-09-30""
                }
            ],
            ""recipient_locations"": [
                {
                    ""state"": ""FL"",
                    ""country"": ""USA"",
                    ""district"": ""08""
                }
            ]
        }
    }",
    Source = Json.Document(Web.Contents(url,[Content=Text.ToBinary(body),Headers=[#"Content-Type"="application/json"]]))
in
    Source

disaster/spending_by_geography

This code wnippet demonstrates how to make a POST request to the spending_by_geography endpoint at https://api.usaspending.gov/api/vs/disaster/spending_by_geography using Excel Power Query. This snippet was designed as an interactive exercise for a training on the USAspending API. ​

let 
    url = "https://api.usaspending.gov/api/v2/disaster/spending_by_geography/",
    body = "{
        ""spending_type"": ""obligation"",
        ""geo_layer"": ""district"",
        ""geo_layer_filters"": [""1208""],
        ""filter"": {""def_codes"": [""L"", ""M"", ""N"", ""O"", ""P"", ""U"", ""V""]}
    }",
    Source = Json.Document(Web.Contents(url,[Content=Text.ToBinary(body),Headers=[#"Content-Type"="application/json"]])),
    results = Source[results],
    results1 = results{0},
    #"Converted to Table" = Record.ToTable(results1)
in 
    #"Converted to Table"