Skip to main content

We are scripting our installation of FME server 2020 and need to run API calls after installation. To do this we need a token but how do we create the token using python code, without creating it manually in the web interface? The FME server playground documentation references the "fmetokens" service but this has been deprecated. The API v3 documentation does not cover this topic that I can find.

Unable to get any assistance on this from safe support, looking for suggestions. Thanks

Hi @tris_w​ ,

 

In 2019 the FME Token Service has been deprecated. However this service has remained in the product for backwards compatibility and will continue to work for creating new tokens, however, will not be able to update or retrieve existing Tokens, but you should still be able to use this for your needs. Alternatively, you can also make use of the REST API tokens endpoint.

 

The key thing to note is that this token service requires you to input your username and password, however in FME 2020 onwards by default you are forced to update your password or first login, and so cannot make use of your user until this is done. Therefore as part of your silent install script, you should set the installation property FIRSTLOGINCHANGEPASSWORD=false so that you are not prompted to update the password and can then retrieve a token.

 

After this is complete you may wish to use the REST API PUT /security/accounts/< account >/password

to update this password to something other than 'admin'.


Thanks Holly, I'd like to use the rest API since the tokens service has been deprecated. In the API documentation it say "A token is required to access the REST API. This must be provided with every request...". So with a fresh install that has no tokens, how do you use the API to create a token? Is there a way to bypass the token and log in using default user/password: admin/admin?


Make a call to this rest end point with Basic Authentication of the required user account

https://docs.safe.com/fme/html/FME_REST/apidoc/v3/index.html#!/tokens/createForm_post_1


This was easier than I was making it, thanks! This code worked in python:

 

import requests

requestUrl = r'http://xxx:8080/fmerest/v3/tokens'

 

requestData = {"user": "admin",

    "expirationTimeout":3600,

    "name":"apiTestToken",

    "restricted":"false",

    "enabled":"true",

    "update":"true"}

 

req = requests.post(requestUrl,data=requestData,auth=('admin','admin'))

print(req.text)


Thanks @hkingsbury​ , that's right. While we recommend using a token for security reasons, you can use Basic Authentication with the Rest API.

 

If you were to use Postman or the HTTPCaller in FME there is a section for Basic Auth, so thanks @tris_w​  for sharing how it needs to look in Python.

 

Basic Auth can also be set up using a Header:

  1. combine the username and password with a colon e.g. admin:admin
  2. encode this string as Base64
  3. Set a Header with Authorization: Basic <Base64 encoded username:password>

 


Reply