Using the OSF web Services outside Drupal

21 views
Skip to first unread message

A.T.

unread,
Nov 13, 2017, 3:33:56 AM11/13/17
to Open Semantic Framework
Dear Fred,

first of all I would like to thank you again for your hard work and the live framework provided.

While working with OSF for a while, we want to automate things by using the Web Services for importing entries, datasets, etc. using the web services provided.

Upon using both the POST Method and the PHP API, in a simple PHP script that I want to call, let's say once per day using cron jobs or through code in another application I couldn't do so with either methods.

For the POST HTTP Method, I am using the cURL library with PHP to create a script that's located in the main Drupal folder ( so I can call it with <my_ip>/script.php or localhost.php).

For simply adding an entry to an already existing dataset I used the information provided from here http://wiki.opensemanticframework.org/index.php/CRUD:_Create with the following code:

        $ch2 = curl_init();
        curl_setopt($ch2, CURLOPT_URL,"http://localhost/ws/crud/create/");
        $vars= array();
        $vars['document'] = $server_output;
        $vars['mime'] = 'application/rdf+xml';
        $vars['mode'] = 'full';
        $vars['dataset'] = 'http://localhost/wsf/datasets/dynamic_dataset_test2/';
        $headers = array();
        $headers[] = 'Accept: */*';
        curl_setopt($ch2, CURLOPT_POST,1);
        curl_setopt($ch2, CURLOPT_POSTFIELDS,$vars);
        curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch2, CURLOPT_HTTPHEADER, $headers);

where the $server_output is a RDF/XML entry.

I suppose that I have to use the admin user (1) http://localhost/user/1 but I can't find in the documentation the way to do so.
Also, as you can see in the following prntscn the Dataset info and the Dataset permissions (even to anonymous users).

What am I missing?

Kind Regards,
Apostolos
 





Auto Generated Inline Image 1
Auto Generated Inline Image 2

Frederick Giasson

unread,
Nov 14, 2017, 8:55:36 PM11/14/17
to open-semant...@googlegroups.com
Hi!


> first of all I would like to thank you again for your hard work and
> the live framework provided.


My pleasure.


> While working with OSF for a while, we want to automate things by
> using the Web Services for importing entries, datasets, etc. using the
> web services provided.


Happy to see that the framework works well for you
Have you tried the OSF PHP API?


https://github.com/structureddynamics/OSF-Web-Services-PHP-API


I think this can be of a big help :)

From your snippet above, you are missing the authentication step to the
endpoints I think.


Thanks,


Fred

A.T.

unread,
Nov 15, 2017, 11:03:01 AM11/15/17
to Open Semantic Framework
Hi,

a) Can you point me to the right direction for the authentication step with the POST method ? Is it through this : http://wiki.opensemanticframework.org/index.php/Auth_Registrar:_Access ?

b) I've tried the PHP API but although the code I use within drupal works, when I am using it as a php script on the drupal main directory (/usr/share/drupal/testscript.php) the "use" statement cannot see the classes required from there (even with the full path). "Include" statements didn't work either. I am not an expert with PHP so I can't really point out the origin of the error here.

Best Regards,
Apostolos
Reply all
Reply to author
Forward
0 new messages