Solved

How to get token by using httpcaller?

  • 1 February 2023
  • 1 reply
  • 22 views

Badge +7

There are some postings on this but it does not work for me yet:

I am trying to contact an external API via HTTP POST to get a token back.

It already works with python. But we wanna integrate the workflow in fme server and Iam sure it will work with fme.

 

Python script:

# Parameter_____
base_url = 'https://apieco.eco-counter-tools.com'
api_key = 'XXX'  # Base64 encoded secrets
 
 
# Tokenabruf
def get_token(url, api_key):
    header = {
        'Content-Type':'application/x-www-form-urlencoded',
        'Authorization': 'Basic ' + api_key 
             }
    r = requests.post(url + "/token", headers= header, data={'grant_type': 'client_credentials'})
 
    answer = json.loads(r.text)
    token  = answer['access_token']
    return token

HTTPCaller:

image 

Erorr Message: 

HTTP/1.1 415 Unsupported Media Type

 

 

Which mime type should I use for the grant_type: client_credentials?

icon

Best answer by limo 1 February 2023, 08:17

View original

1 reply

Badge +7

Ah I got it:

I have to define "grant_type= client_credentials" inside the parameter for query string

 

image

Reply