rewiringamerica / api.rewiringamerica.org

A RESTful web API for federal, state, utility and local rebates, tax credits and other electrification incentives.
https://api.rewiringamerica.org
Apache License 2.0
4 stars 0 forks source link

`Find eligible incentives` API not ingesting `items` array of string values #525

Open glitchwizard opened 3 weeks ago

glitchwizard commented 3 weeks ago

Description Your Find eligible incentives API indicates that the request parameter items is optional, array of strings, items must be unique, minimum of 1 items

The API playground would set it up like so: /api/v1/calculator?zip=97206&items=["battery_storage_installation", "ducted_heat_pump"]&owner_status=homeowner&household_income=37585&tax_filing=hoh&household_size=2&language=en

While this is indicated as a correctly formatted array for items, it actually returns this reponse:

{
  "statusCode": 400,
  "error": "Bad Request",
  "message": "querystring/items/0 must be equal to one of the allowed values"
}

When I switch items to single quotes or backticks, it marks it as an invalid array and doesn't include it in the query:

image

The image above has the auto generated get request of /api/v1/calculator?zip=97206&owner_status=homeowner&household_income=37585&tax_filing=hoh&household_size=2&language=en

items is missing in the request.

Now when I make this call using Python's fetch with the params set as so:

{
    "household_income": 37585,
    "household_size": 2,
    "zip": "97206",
    "owner_status": "homeowner",
    "tax_filing": "hoh",
    "items": [
        "ducted_heat_pump"
    ]
}

I get the following response:

{
    "is_under_80_ami": True,
    "is_under_150_ami": True,
    "is_over_150_ami": False,
    "authorities": {},
    "coverage": {
        "state": None,
        "utility": None
    },
    "location": {
        "state": "OR",
        "city": "Portland"
    },
    "data_partners": {},
    "incentives": []
}

this.... is clearly incorrect.

Steps to reproduce To reproduce, initially go to https://api.rewiringamerica.org/docs/routes#find-eligible-incentives and use the playground for Find eligible incentives and try to put an array of strings in like ["battery_storage_installation", "ducted_heat_pump"]

/api/v1/calculator?zip=97206&items=["battery_storage_installation", "ducted_heat_pump"]&owner_status=homeowner&household_income=37585&tax_filing=hoh&household_size=2&language=en

Expected behavior It should have returned the information for only ducted_heat_pump as indicated by the API docs.

glitchwizard commented 3 weeks ago

Also, to follow up on this, when I don't include items there are in actually incentives with ducted_heat_pump indicated for that area, so we should be good to go in terms of returning an incentive that actually exists for that zip code.

oyamauchi commented 1 week ago

First of all, thanks for your report, and sorry for the delayed response.

Re: items, array parameters have to be passed by repeating the parameter name, like items=battery_storage_installation&items=ducted_heat_pump. If you're using Python, we recommend using Requests, which does this automatically when you pass an array to params.

Finally, the reason you got no results for the query on 97206 is that Oregon is still in beta; you have to pass the parameter include_beta_states=true to get state and local incentives there.

So this code:

import pprint
import requests

response = requests.get(
    "https://api.rewiringamerica.org/api/v1/calculator",
    params={
        "household_income": 37585,
        "household_size": 2,
        "zip": "97206",
        "owner_status": "homeowner",
        "tax_filing": "hoh",
        "items": ["ducted_heat_pump"],
        "include_beta_states": "true",
    },
    headers={"Authorization": "Bearer <KEY>"},
)

pprint.pprint(response.json())

produces results:

{'authorities': {'or-energy-trust-of-oregon': {'name': 'Energy Trust of '
                                                       'Oregon'}},
 'coverage': {'state': 'OR', 'utility': None},
 'data_partners': {},
 'incentives': [{'amount': {'number': 3000, 'type': 'dollar_amount'},
                 'authority': 'or-energy-trust-of-oregon',
                 'authority_type': 'state',
                 'items': ['ducted_heat_pump'],
                 'owner_status': ['homeowner'],
                 'payment_methods': ['rebate'],
                 'program': 'Energy Trust of Oregon',
                 'program_url': 'https://www.energytrust.org/residential/incentives',
                 'short_description': 'PGE and Pacific Power customers are '
                                      'eligible for a $3,000 rebate for an '
                                      'extended capacity heat pump replacing '
                                      'an electric furnace.',
                 'start_date': '2023-10-01'},
                {'amount': {'number': 3000, 'type': 'dollar_amount'},
                 'authority': 'or-energy-trust-of-oregon',
                 'authority_type': 'state',
                 'items': ['ducted_heat_pump', 'ductless_heat_pump'],
                 'owner_status': ['homeowner'],
                 'payment_methods': ['rebate'],
                 'program': 'Savings Within Reach',
                 'program_url': 'https://www.energytrust.org/residential/incentives',
                 'short_description': '$3,000 rebate for a heat pump for '
                                      'income-qualified customers. Must '
                                      'replace an electric forced-air furnace '
                                      'as the primary heating source.',
                 'start_date': '2023-10-01'},
                {'amount': {'number': 1000, 'type': 'dollar_amount'},
                 'authority': 'or-energy-trust-of-oregon',
                 'authority_type': 'state',
                 'items': ['ducted_heat_pump'],
                 'owner_status': ['homeowner'],
                 'payment_methods': ['rebate'],
                 'program': 'Extended Capacity Heat Pump',
                 'program_url': 'https://www.energytrust.org/residential/incentives',
                 'short_description': '$1,000 rebate for an extended capacity '
                                      'central ducted heat pump. Must be '
                                      'listed on Energy Trust’s list and be '
                                      'the primary heat source.',
                 'start_date': '2023-10-01'}],
 'is_over_150_ami': False,
 'is_under_150_ami': True,
 'is_under_80_ami': True,
 'location': {'city': 'Portland', 'state': 'OR'}}

I do see a bug here, though: you should get federal incentive results for this query, even without include_beta_states. It's a bug with the item filtering logic. Thanks for reporting!