Authentification problem using arcpy

1236
3
Jump to solution
08-30-2021 06:44 AM
MaximeDemers
Occasional Contributor III

Hi,

I am trying to use the Urban API with Python but I got an authentification error:

GraphQL query failed with 1 errors
[{'message': 'The access token provided is invalid or expired.', 'extensions': {'code': 'UNAUTHENTICATED'}}]


Im not sure why the token I provided to the urban api url is not working because it was generated using arcpy like below:

import arcpy
from sgqlc.operation import Operation
from sgqlc.endpoint.http import HTTPEndpoint
from urban_api_schema import urban_api_schema as schema

arcpy.SignInToPortal("https://www.arcgis.com", "myUserName", "MyPasswOrd")
#token is generated correctly
token = arcpy.GetSigninToken()
urban_api_url = "https://urban-api.arcgis.com/graphql" + '?token=' + token['token']

endpoint = HTTPEndpoint(urban_api_url)

#here it's the function that call the api to update the parcels
for parcel_chunk in parcels_chunks:
  op = Operation(schema.Mutation)
  create_parcels = op.create_parcels(urban_database_id="1c80e3e815594fd288d347e132138f0a", parcels=parcel_chunk)
  create_parcels.attributes.__fields__('global_id')

  json_data = endpoint(op)
  errors = json_data.get('errors')
  if errors:
    print(errors)

 

Any helps would be greatly appreciated!

Thanks,

Maxime Demers

1 Solution

Accepted Solutions
MaximeDemers
Occasional Contributor III

Yes ok, it can be deleted. Thank you for the feedback. Have a good day.

View solution in original post

3 Replies
MaximeDemers
Occasional Contributor III

Further readings make me realize that I must use a OAuth2.0 authentification method.

AgnieszkaRozniak
Esri Contributor

Hi @MaximeDemers and thank you for reaching out to us. You are right, the Urban API does use OAuth2.0 authentication method. Does it mean that your question above is no longer valid?

 

MaximeDemers
Occasional Contributor III

Yes ok, it can be deleted. Thank you for the feedback. Have a good day.