401 error when connecting API in Python code

Hello,

I successfully ran the school API on the ‘Try it’ area and got the JSON result from an advanced list on the web page. But when I ran the sample Python code by filling the ‘subscription key’ , ‘access taken’, and ‘list_id’, I got a 401 status code, says “Access denied due to invalid subscription key. Make sure to provide a valid key for an active subscription.”

Did I missing something here?

Comments

  • Chris Rodgers
    Chris Rodgers Blackbaud Employee
    Ninth Anniversary Kudos 3 Name Dropper Participant

    Hi Jacob,

    There can be a few reasons why you'd see this error, but the most common:

    • The subscription key header (bb-api-subscription-key) is provided on the request, but the header value is not set or the header value is not a valid subscription key (possibly a typo).
    • The subscription key is valid but it is not correct for the API you are calling (e.g. a “Standard APIs” subscription key being used for the Payments API).

    In your case, I only see one subscription on your account, so I believe your issue might be the former. Please check that the request has correctly set that subscription key header.

  • TLDR: Update your config_file test_api_endpoint parameter to something you can open.

    Hey there @Jacob d*** (and anyone else stumbling here for assistance)--this was happening to me too. @Chris Rodgers is on the money--the API node/endpoint/reference you are calling may not be within you suite to call.

    The API Python Code provided (see Git justein230\\BbApiConnector) is helpful for setting up your environment but dates out a test node that may not work for everyone. The default in the in the config_file (apps_secrets.json) is "test_api_endpoint": "https://api.sky.blackbaud.com/school/v1/roles"; which is 'invalid' for me and perhaps others. To see this in effect, try going directly to it--you'll see it holler back the same 401 code explicitly.

    In your respective config_file, change it to something you do have access to (as seen within the Try Me sections of the API manual). For me, I notated the the original parameter as old_test_api_endpoint (just in case--you never know and it never hurts to have a backup/restore plan) and a replacement test_api_endpoint as

    Was able to get a clear 200 and start making the calls I wanted with the BbApiConnector. Hopes this helps someone else!

    -TCL

Categories