Jump to content

phpVMS REST API


Recommended Posts

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

Link to post
Share on other sites
  • 2 years later...
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.

Link to post
Share on other sites
On 09.02.2017 at 8:56 PM, Tom said:

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.

 

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

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://my.site.ru/api/pilots");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
$json=json_decode($response,true);
echo'<pre>',print_r($json),'</pre>'; 
?>

 

Edited by bass
Link to post
Share on other sites
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/..."

Link to post
Share on other sites
12 hours ago, Tom said:

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/..."

I want to get through the API
pireps/view
shedules
pilots
The statistics of the company.

I tried a request in this form: (does not work)


<?php
  $a = trim(strip_tags($_GET["a"]));
?>

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://my.site.ru/action.php/api/pilots/$a");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
$json=json_decode($response,true);
echo'<pre>',print_r($json),'</pre>'; 
?>

 

Edited by bass
Link to post
Share on other sites
14 hours ago, Tom said:

@bass Can you give any more information than "does not work"?

What response do you get?

 

Don't forget to set the 'Authorization' header.

The answer I have just the number "1"

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

Link to post
Share on other sites
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)

Link to post
Share on other sites
On 18.02.2017 at 0:45 PM, Tom said:

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

Hi.
I was never able to get anything via the API
TOM you can do one page with code (example) how to request a list of pilots and bring to the page?

Link to post
Share on other sites
  • 1 month later...
  • Moderators
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
Link to post
Share on other sites
  • 4 months later...
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.

Link to post
Share on other sites
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

 

Link to post
Share on other sites
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 = /

 

Link to post
Share on other sites
  • 2 years later...
  • 2 months later...

Ive used my trusty friend POSTMAN.

 

this is what it gave me. this is using a fake password btw so u cant do anything.

import requests

url = "https://mysite.ru/action.php/api/pilots"

payload = {}
headers = {
  'Authorization': 'Basic bXlVc2VyTmFtZTpNeVBhc3N3b3Jk'
}

response = requests.request("POST", url, headers=headers, data = payload)

print(response.text.encode('utf8'))

@brenohff

Link to post
Share on other sites
  • 4 months later...

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...