5

I need to import on node save information from a third party REST server and map that data to an entity that references the node saved. There will be a field in the node that the user can input an id that is passed in the url of the REST call. The REST call will return an XML object that needs to be mapped to a new entity that is referenced to the node.

How is this done? Are there an examples of Drupal 7 modules that do this?

  • What kind of server is on other side ? I use Curl and special designed library to pull data from Microsoft CRM and then i sync it with my nodes, but all of this is custom – NenadP Sep 8 '12 at 16:38
  • I want to access a video database. The content includes the URL of the asset, length of video and thumbnail images. I need to bring that information into Drupal through a REST server API provided by the video hosting company. – Adam S Sep 8 '12 at 17:13
10

Normally, I just roll my own.

I use a combo of drupal_http_build_query and drupal_http_request to make the request. I then use drupal_json_decode to parse JSON results, or simplexml_load_string to parse XML results.

When possible, I try to abstract out all of this into a PHP class as a singleton, which also includes static caching and/or caching via cache_set/cache_get for the actual requests. I will then wrap up everything as a normal Drupal module.

Invariably, the service I am consuming will have something odd about it that precludes using a generic solution. Also, I don't find the generic solutions any simpler than a custom one.

  • You are correct. I also need to know the best way to populate nodes or entities with this imported information. There is an array of objects in the XML response that need to be their own entities referenced by the top level node. I asked the question at drupal.stackexchange.com/questions/42125/…. – Adam S Sep 8 '12 at 21:50
1

You can also use Web Service Clients module. It is a perfect match when consuming from drupal Services module but it also can be used with other REST API.

  • 1
    Hello and welcome. Few words of explanation how to set this up, or relevant excerpt from documentation, could greatly increase usefulness of your answer :) – Mołot Dec 13 '13 at 10:05
0

Have you looked at REST Client? It's not for production use (currently) but is a good place to start if you don't just want to use drupal_http_request against whatever API you're hitting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.