-
-
Save kperry2215/3bb97309eb4b1730c00e9d4b18918876 to your computer and use it in GitHub Desktop.
import requests | |
r= requests.post(url = "https://auth.accela.com/oauth2/token", | |
headers={"Content-Type": "application/x-www-form-urlencoded", | |
"x-accela-appid": str(client_id)}, | |
data = {"grant_type" :"password", | |
"client_id": str(client_id), | |
"client_secret": str(client_secret), | |
"redirect_uri": "http://localhost/myapp/", | |
"username": username, | |
"password": password, | |
"environment": "PROD", | |
"scope": "records"}, verify=False).json() | |
agencies = requests.get("https://apis.accela.com/v4/agencies", | |
headers={"Authorization": r['access_token']}, verify=False).json() | |
# Loop through the agencies and get the records??? | |
for agency in agencies['result']: | |
req = requests.get("https://apis.accela.com/v4/records", | |
headers={'x-accela-appid': str(client_id), | |
'x-accela-agency': agency['name'], | |
"Authorization": r['access_token']}, | |
verify=False) | |
print(req.status_code) | |
Hey @clay-jacob thank you for helping me out with this! I've tried it both ways (declaring an agency_name in the oauth call, and the above method where I don't declare an agency, and still have not been successful. The specific error I'm getting is as follows:
b'{"status":500,"code":"internal_server_error","message":"Internal Server Error. Please contact the administrator.","more":null,"traceId":"250627174944594-b9433319"}'
Here is the code I'm running with an arbitrary agency name declared (I picked one randomly from the /v4/agencies/ output), where I can get a token successfully, but the error above is thrown if I attempt to access any records:
agency_name = 'BAKER_CITY'
ls= requests.post(url = "https://auth.accela.com/oauth2/token",
headers={"Content-Type": "application/x-www-form-urlencoded",
"x-accela-appid": str(client_id)},
data = {"grant_type" :"password",
"client_id": str(client_id),
"client_secret": str(client_secret),
"redirect_uri": "http://localhost/myapp/",
"agency_name": agency_name,
"username": username,
"password": password,
"environment": "PROD",
"scope": "records"}).json()
req = requests.get("https://apis.accela.com/v4/records",
headers={'x-accela-appid': str(client_id),
'x-accela-agency': agency_name,
"Authorization": ls['access_token']})
print(req.content)
Output to above snippet:
b'{"status":500,"code":"internal_server_error","message":"Internal Server Error. Please contact the administrator.","more":null,"traceId":"250627175353709-3b7ebe55"}'
can you add print(ls.content)
and let me know the output? Is Baker City the agency you made your public user account with?
@clay-jacob I get the following output for ls.content:
{'access_token': 'ACCESS_TOKEN',
'token_type': 'bearer',
'expires_in': 900,
'refresh_token': 'REFRESH_TOKEN',
'scope': 'records'}
I didn't sign up specifically for Baker City when I made a public account. I signed up for Denver here: https://aca-prod.accela.com/DENVER/Default.aspx. However, even if I use "DENVER" instead of "BAKER_CITY" above as agency_name, I get the 500 internal server error. Am I not using the right site for signing up for a public user account? Is there somewhere in the documentation on all of the accounts I need to sign up for? Perhaps that's my issue.
I would like to pull data for multiple agencies as well. Is that not possible with the current setup, or can I make multiple accounts with the same email, etc?
@clay-jacob I have solved the issue! I did not link to my Denver account in the Accela Civic Portal. Once I did, I was able to successfully pull data. Thank you for pointing me in the right direction!
Hi @kperry2215 , I have a similar issue. Would you mind a brief explanation on how to link my account to an agency? Do you have the link? Thank you.
Hey @kperry2215 - what specifically is the error message you're getting? My first thought is that you will need to have a public user with each agency to then be able to get the records. Your
access_token
is only authenticated with the first agency you're authenticating to.In your first request to authenticate I don't see you specifying the
agency_name
in the body so I would actually expect this to throw an error.