Skip to main content
Solved

Error connecting to API


magnus
Participant
Forum|alt.badge.img+2

I am having trouble connecting to the API at https://developer.vasttrafik.se/portal/. I would like to get the public transport stops (https://developer.vasttrafik.se/portal/#/api/Geography/v1/admin), but I am stuck, I keep getting "HTTP/1.1 403 Forbidden" from the HTTPCaller. I have tried using "Authorization" as suggested at https://community.safe.com/s/question/0D54Q00008WImfCSAT/using-fme-to-call-power-bi-via-the-api-to-refresh-data-sets-dynamically-i-am-stuck-with-the-authentication-piece-for-the-bearer-token, but no success. Any suggestions on what I might be missing?

Best answer by takashi

magnus wrote:

The API has now been updated to https://api.vasttrafik.se/geo/v2/StopPoints and I no longer get an error message. However, the _response_body I get is about 10 MB and looks like: 7B2273746F70506F696E7473223A5B7B22676964223A2239303232303134303031303034303031222C2273746F704172656... . I was more hoping for the JSON respons that Postman produces. Any suggestions?

 

Tried with FME 2021.2.2.0.

 

HTTPCaller

Hi @magnus​ , try setting the Response Body Encoding parameter explicitly to appropriate character encoding, maybe UTF-8.

View original
Did this help you find an answer to your question?

nielsgerrits
VIP
Forum|alt.badge.img+54

Have you been able to connect to the API using Postman?

This is the way I work through these projects:

  • Make it work in Postman. (Better geared to get this working.)
  • Transfer the steps to FME.

magnus
Participant
Forum|alt.badge.img+2
  • Participant
  • November 29, 2021

Thank you for the suggestion. Yes, I am able to get the desired response using Postman. In Postman, I used the address http://api.vasttrafik.se/geo/v1/StopPoints and Authorization - Type: Bearer Token. I guess I´m not configuring this correctly in FME.


nielsgerrits
VIP
Forum|alt.badge.img+54
magnus wrote:

Thank you for the suggestion. Yes, I am able to get the desired response using Postman. In Postman, I used the address http://api.vasttrafik.se/geo/v1/StopPoints and Authorization - Type: Bearer Token. I guess I´m not configuring this correctly in FME.

If I try some of these samples (API-konsol) and monitor DevTools (F12) I see:

DevToolsI would try to do:

Authorization


magnus
Participant
Forum|alt.badge.img+2
  • Participant
  • November 29, 2021
nielsgerrits wrote:

If I try some of these samples (API-konsol) and monitor DevTools (F12) I see:

DevToolsI would try to do:

Authorization

HTTPCallerI have tried Authorization and using the token, but I still get "HTTP/1.1 403 Forbidden".


nielsgerrits
VIP
Forum|alt.badge.img+54
nielsgerrits wrote:

If I try some of these samples (API-konsol) and monitor DevTools (F12) I see:

DevToolsI would try to do:

Authorization

Is your Content Type set to JSON (application/json)?


magnus
Participant
Forum|alt.badge.img+2
  • Participant
  • November 29, 2021
nielsgerrits wrote:

If I try some of these samples (API-konsol) and monitor DevTools (F12) I see:

DevToolsI would try to do:

Authorization

HTTPCaller2I added Content-Type = application/json and still get "HTTP/1.1 403 Forbidden".


nielsgerrits
VIP
Forum|alt.badge.img+54
nielsgerrits wrote:

If I try some of these samples (API-konsol) and monitor DevTools (F12) I see:

DevToolsI would try to do:

Authorization

Hm, swedish is not my first language so it is difficult to reproduce, but I think I have a valid login now.

 

The curl command is:

curl -k -d "grant_type=client_credentials" -H "Authorization: Basic <token>" https://api.vasttrafik.se:443/token

So I think you need 2 httpcallers: 

  • get a temp token from https://api.vasttrafik.se:443/token using the key you got for the app you added.
  • get the data using the temp token you got in the first step.

nielsgerrits
VIP
Forum|alt.badge.img+54
nielsgerrits wrote:

If I try some of these samples (API-konsol) and monitor DevTools (F12) I see:

DevToolsI would try to do:

Authorization

@magnus​ I can reproduce you issue. I can get a token but then I get a forbidden on the datasets as well. Not sure why but or we are making the same mistake, or it does not work as documented.


magnus
Participant
Forum|alt.badge.img+2
  • Participant
  • January 28, 2022

The API has now been updated to https://api.vasttrafik.se/geo/v2/StopPoints and I no longer get an error message. However, the _response_body I get is about 10 MB and looks like: 7B2273746F70506F696E7473223A5B7B22676964223A2239303232303134303031303034303031222C2273746F704172656... . I was more hoping for the JSON respons that Postman produces. Any suggestions?

 

Tried with FME 2021.2.2.0.

 

HTTPCaller


takashi
Supporter
  • January 28, 2022
magnus wrote:

The API has now been updated to https://api.vasttrafik.se/geo/v2/StopPoints and I no longer get an error message. However, the _response_body I get is about 10 MB and looks like: 7B2273746F70506F696E7473223A5B7B22676964223A2239303232303134303031303034303031222C2273746F704172656... . I was more hoping for the JSON respons that Postman produces. Any suggestions?

 

Tried with FME 2021.2.2.0.

 

HTTPCaller

Hi @magnus​ , try setting the Response Body Encoding parameter explicitly to appropriate character encoding, maybe UTF-8.


magnus
Participant
Forum|alt.badge.img+2
  • Participant
  • January 31, 2022
takashi wrote:

Hi @magnus​ , try setting the Response Body Encoding parameter explicitly to appropriate character encoding, maybe UTF-8.

Yes, that helped. I now get a proper JSON response. Thanks!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings