call drupal function from external php file

Events happening in the community are now at Drupal community events on www.drupal.org.
mirian@drupal.org's picture

Hi all,

I'v just heard about this module and understood it might help me...
I want to get values from external php script which will call drupal function that will take the data and call "node_save" with new node that contain the relevant data (which was arrived from the external php)

I don't understand how services can solve it.

Thanks,
Miriam.

Comments

CURL

andremolnar's picture

I'm not sure what you are trying to do, but you can use cURL to call your web services from another php file/ application.

This is in fact the way that I test all my web services. I run a testing script that uses cURL to send good/bad data to the services and tests the return values from the services.

andre

Can you show a code example

amitaibu's picture

Can you show a code example of how you use the cURL? [edit: here's a short Drupal code example on cURL].

@miriam, you can also use:

<?php
$node
= node_load(1);
xmlrpc('http://example.com/services/xmlrpc', 'node.save', $node);
?>

not exteral to drupal

tomhung's picture

this code does not work external to drupal.

can someone show a simple example xml-rpc client using php to connect to drupal services with node.load and/or node.save

I can't seem to get it to connect. i keep getting the following

<?xml version="1.0"?>
<methodResponse>
  <fault>
  <value>
    <struct>
    <member>
      <name>faultCode</name>
      <value><int>-32602</int></value>
    </member>
    <member>
      <name>faultString</name>
      <value><string>Server error. Wrong number of method parameters.</string></value>
    </member>
    </struct>
  </value>
  </fault>
</methodResponse>

The example should work from

amitaibu's picture

The example should work from one drupal site to another, you might need to set access permissions to allow it to work. Also remove the API key and Sess Id for the example to work.

Here an even better tutorial

amitaibu's picture

Here an even better tutorial - http://drupal.org/node/86727

Services

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: