Issues Getting Custom Portfolio History From HTTP API - Python

Hello,

I am trying to add the function below to my command-line trading program. The problem is, no matter what I put in the query parameters, I always get the default response using ‘1M’ as the period.

def history(period):
    response = requests.get(PORTFOLIO_HISTORY_URL, json={'period': period}, headers=HEADERS)
    json_response = json.loads(response.content)

    df = pd.DataFrame.from_dict(json_response)
    df['timestamp'] = pd.to_datetime(df['timestamp'], unit='s').dt.strftime('%m/%d')

    plt.figure(figsize=(15,8))
    plt.xticks(rotation=45)
    plt.title('Changes in Portfolio Over Previous 30 Days')
    plt.ylabel('Portfolio Value ($)')
    plt.plot(df['timestamp'], df['equity'])
    plt.show()

I have tried calling this function with history(‘1M’), history(‘1Y’), history(‘90d’) etc etc and nothing changes. Similarly, I have tried using the ‘end_date’ and ‘timeframe’ parameters with the same issue. Regardless of the values given for those parameters, the output does not change.

The documentation I am using can be found at https://alpaca.markets/docs/api-documentation/api-v2/portfolio-history/#portfoliohistory-entity

All the rest of the documentation has worked exactly as expected except for portfolio history.

Thanks in advance to anybody able to help.