jason2192839
Posts: 0
Joined: Wed Sep 23, 2015 10:34 am

How do I log in to a Rest API service instead of using a key?

Hi,

Let me start off with saying that I'm not a coder. I know HTML & CSS and that's it.
Watching the Appery video's however gave me the idea that I could actually build real apps. And with that realize an idea I had

Here's what I want to do:
Use the dutch railroad RestAPI to connect travellers.
The API docs can be found here: http://www.ns.nl/api/api

Sample request: http://webservices.ns.nl/ns-api-avt?s...
(only in dutch, sorry)

So here's my problem:
This 5 minute video explains nicely how to use an external API but it uses a key for authentication. the NS API uses a username/password login.

I tried to implement what I found on the bottom of this post:
https://devcenter.appery.io/documenta...

  1. add external resource

  2. add the javascript

  3. add the service on load of the page

  4. add the javascript to the Authorization paramater. (which I renamed to Access-Control-Allow-Origin later because of the error message bellow)

    Unfortunately this was to no avail. When I look in console I get the following error:

    XMLHttpRequest cannot load http://webservices.ns.nl/ns-api-avt. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://appery.io' is therefore not allowed access. The response had HTTP status code 501.

    Any thoughts on making this work would be greatly appreciated!

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

How do I log in to a Rest API service instead of using a key?

Hello,

Please enable proxy for this service.

jason2192839
Posts: 0
Joined: Wed Sep 23, 2015 10:34 am

How do I log in to a Rest API service instead of using a key?

He Sergiy,

Thanks for your reply.
I enabled the proxy this way:

  1. created a new "secure proxy" from my account page and named it "NSProxy" (using default settings)

  2. Went to my app service in question checked "use appery.io proxy "NSProxy"

    When I now check console I get the error:
    Failed to load resource: the server responded with a status of 401 (Unauthorized)

jason2192839
Posts: 0
Joined: Wed Sep 23, 2015 10:34 am

How do I log in to a Rest API service instead of using a key?

He Sergiy, my question hasn't been resolved yet it says answered on the top.
Can I change that?

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

How do I log in to a Rest API service instead of using a key?

Hi Jason - Could you please check this error in browser developer tools using network tab to see what is the response payload is from this error? And show us this result.

jason2192839
Posts: 0
Joined: Wed Sep 23, 2015 10:34 am

How do I log in to a Rest API service instead of using a key?

He Illya,

Thanks for getting back to me. Here's a screenshot from my network tab:
http://i59.tinypic.com/2lnjp5i.png

Hope you can help me out, to me it seems like my login details are not being used. I also tried entering the URL as http://username:password@apiservice but then I get the message "invalid URL" on testing

jason2192839
Posts: 0
Joined: Wed Sep 23, 2015 10:34 am

How do I log in to a Rest API service instead of using a key?

Hi Guys,

I figured out my problem: I did not put "basic" in the header request, just the authorisation key. Everything seems to work now :)

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

How do I log in to a Rest API service instead of using a key?

Thank you for the update Jason! Glad it works now!

Return to “Issues”