I'm making a HTTPS POST request to the following URL: http://www.arcgis.com/sharing/rest/oauth2/token/

In the Request body I've added the following JSON:


Despite the client_id being clearly specified I always get the same response to my request:

{"error":{"code":400,"error":"invalid_request","error_description":"client_id not specified","message":"client_id not specified","details":[]}}

Is there something about the REST call I'm missing? Should I still be using JSON in the request body?

2 Answers 2


I'm successfully using this method to obtain a token:

def get_token():
    # Retrieve a token from ArcGIS Online to enable access to private services
    token_params = {
        'client_id': "your_client_id",
        'client_secret': "your_client_secret",
        'grant_type': "client_credentials"
    request = requests.get('https://www.arcgis.com/sharing/oauth2/token', params=token_params)
    response = request.json()
    token = response["access_token"]
    return token

agol_token = get_token()

We use python requests library to make HTTPS post calls to arcgis online and to arcgis server. you can use urllib2, but we really like using requests. After you have that, these are the params we use to pass to the endpoint.

# some params to pass to the function below
username = 'your_arcgis_online_username'
password = 'your_arcgis_online_password'
url = 'https://www.arcgis.com'

def get_token(url, username, password):
    ''' use this to get a token from arcgis online '''
    gen_token_url = '{}/sharing/rest/generateToken'.format(url)
    # payload params for the post request
    params = {'username':username,

    response = requests.post(gen_token_url, data=params, verify=False)
    data = response.json() # convert to json
    return data['token']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.