Jump to content

Recommended Posts

Posted

phpVMS REST API

A basic REST API module for access to phpVMS data and functionality, for example in third party clients & other sites.

Note: This is very much still in development. It isn't very thoroughly tested or remotely complete in functionality, however it is a start and I'm putting it up to allow others to contribute and speed up development. Use with caution.

Current Features:

  • Username/password user auth for all requests via Basic Auth
  • Only available to confirmed registered users
  • Removes sensitive information from responses (encrypted password, salt, emails, IP addresses)
  • All PUT/POST data is expected to be JSON
  • Get paginated news list (requires SimpleNews)
  • Get individual news item (requires SimpleNews)
  • Get pilot list
  • Get individual pilot details
  • Get details of current user (of the API)
  • Get schedule list
  • Get individual schedule
  • Bid on a schedule
  • Approve/Reject registrations (Admin)

Obviously there's a lot left to do so I welcome contributions. You can find the code & more detailed information on GitHub.

If you have any issues please open them on GitHub rather than a forum post here.

https://github.com/t...phpVMS-REST-API

  • 2 years later...
Posted
On 05/02/2017 at 3:45 AM, joooseb said:

any tutorial :(?

The endpoints are documented in the readme on GitHub - they're mostly GET requests so very simple. How you make those GET requests depends on what you're doing (i.e. from Javascript, or an app, etc.) but you can find tons of tutorials on making HTTP requests online.

Posted
5 hours ago, bass said:

 

Hi, trying to get the data from database through your module, but I can't.

Make a request like this:

my.site.ru/index.php/api/pilots      not working

my.site.ru/api/pilots                        not working

 

In its current state the API requires basic auth user credentials set in the Authorization header for every request. Also unless you've set up URL redirects you'll need to access it via "site.com/action.php/api/..."

Posted
22 hours ago, bass said:

The answer I have just the number "1"

You can show an example of an authorization code that must be on the pages?

You'll need to add the header "Authorization" with the value "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", where dXNlcm5hbWU6cGFzc3dvcmQ= is base64_encode($username.':'.$password)

  • 1 month later...
  • Moderators
Posted
21 hours ago, bass said:

Reviewed a lot of information, but was not able to get this module to work(((

Is there someone who have this module working?

the best way I find to display pilot page is an iframe without layout

  • Moderators
Posted (edited)
9 hours ago, bass said:

/action.php/pilots   ???  It does not suit me(

No, make a copy of the folder of your phpvms in your cpanel with other name.. For example "content"

and then go to layout.tpl and delete all skins css or script.

Late make a page with your content that you want to display, and then call it via iframe to your site =).

<html> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> 
</head> 
<style type="text/css"> 
#test iframe { 
width: 100%; 
height: 100%; 
border: none; } 

#test { 
width: 100%; 
height: 650px; 
padding: 0; 
overflow: hidden; } 

</style> 

<body style="margin:0;"> 
<div id="test"> 
<iframe src="http://www.yoursite.com/index.php" scrolling="no">
</iframe> 
</div> 
</body> 
</html>

That's I did in my wordpress site:

www.travelskyalliance.com

Edited by joooseb
  • 4 months later...
Posted
2 hours ago, brenohff said:

Can someone help me with REST API? 
I put the files inside /core folder and I don't know what I have to do now....

You make calls to the API endpoints.

I've fixed the readme, seems GitHub changed how they parse markdown and broke it <_<

Make sure you're including a Basic Auth token on all requests.

Posted
31 minutes ago, Tom said:

You make calls to the API endpoints.

I've fixed the readme, seems GitHub changed how they parse markdown and broke it <_<

Make sure you're including a Basic Auth token on all requests.

I did the installation as you said in github but when i make a GET request, the response came empty...

I'm putting Authorization: Basic YnJlbm9oZmZAZ21haWwuY29tOmIyMjA1OTZi at header

 

Posted
5 hours ago, Tom said:

You make calls to the API endpoints.

I've fixed the readme, seems GitHub changed how they parse markdown and broke it <_<

Make sure you're including a Basic Auth token on all requests.

Now I'm getting error 401 Unauthorized even adding the authorization header = /

 

  • 2 years later...
  • 6 months later...
  • 1 year later...
Posted

Tom is there?

This definitely doesn't work for me. Unless I delete line 81 as presented above by #JefferssonSantos, even using Authorization Basic

On 12/3/2020 at 11:53 PM, JefferssonSantos said:

There's a file called core/modules/api/api.php. Inside that file, there's a function called "private static function setup()". Comment the line 81(self::checkUser();) and you'll be able to use this API without Verification. Sorry for my english.

 

Posted (edited)

Hi Folks,

 

So, I scanned the PHP code and got the result. Let´s go!
You can do a quick test using Postman. If you don't have it yet, download it here: https://www.postman.com/downloads/

You need to create an account and password to use it, it's free!

 

See the attached print of my postman that will guide the explanation.

 

  1. Define the method, in this case GET, as I want to bring the list of pilots.
  2. Enter your URL remembering to put the folder where your phpVMS is installed.
  3. Click Authorization tab

  4. Choose the type of authorization, in this case Basic Auth

  5. Enter your username. This is where I was wrong and it's not clear from the API documentation. Your username is your ID and not your callsign used when you log into phpVMS. So, ID is the number (unless zeros) that after airline code. Example: My login callsign is XYZ0001, so my username is 1.

  6. Type your password

 

Finally, I got a positive response!

 

Captura de tela 2021-12-14 18.01.48.png

 

 

Here's an example of the PHP code you can make inside your phpVMS using cURL

 

<?php

ob_start();

$user = 'type your User ID number';

$pass = 'type your password';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://{your website}/{phpvms folder}/index.php/api/pilots');

curl_setopt($ch, CURLOPT_HEADER, 0);

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic '.base64_encode($user.':'.$pass)));

curl_exec($ch);

$result = ob_get_contents();

ob_end_clean();

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

header("Content-Type: text/html;

charset=utf8");

echo "$httpCode<br>$result";

 

I hope I've helped!👍

 

 

Edited by Nascoli

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...