Skip to main content
Solved

How to get token by using httpcaller?

  • February 1, 2023
  • 1 reply
  • 216 views

limo
Supporter
Forum|alt.badge.img+8
  • Supporter
  • 52 replies

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?

Best answer by limo

Ah I got it:

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

 

image

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

1 reply

limo
Supporter
Forum|alt.badge.img+8
  • Author
  • Supporter
  • 52 replies
  • Best Answer
  • February 1, 2023

Ah I got it:

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

 

image