Score:0

Post Data to D7 from D9

cn flag

How do I post data from Drupal 9 when a content is created, post data to Drupal 7 hosted in a different server to create node content.

In Drupal7, I have enabled services module and created a resource to create login session, accept json data and creates node content. This is working fine when I test from POSTMAN.

I am new to Drupal 8/9 and not sure how to post json data to D7. Please could anyone suggest? so far, i have created a custom module in D9 and have added additional custom_form_submit where I can add code to post data once the node is submitted. I need to login to D7, grab token, post data to D7 to create node in D7, then logout from D7.

Or can the login process be handled separately via sysadmin configurations like proxy/firewall settings? Both D7 and D9 are hosted in separate servers but in same organisation cloud.

[updated] Our current D7 app has a lot of custom features used internally within our organisation and externally. We are in the process of migrating the app to D9 prioritising externally accessible features and to keep D7 as legacy system for internal use. We only need 5 fields in ONE cck in D9 to be stored in real time in D7 to continue using D7.

The 5 fields include integer, date&time and list fields. I have tried to maintain the cck and field machine names SAME in both D7 and D9 sites. The rest of the fields in this cck are very different in both sites.

cn flag
Specifically, what kind of data are you trying to post? What is the relationship between the D7 site and the D9 site? Are they supposed to be "mirrors" of each other and have the same users, content, etc.? Or are they mostly separate sites with different content and users? In many cases, you can use the Feeds module to sync content between Drupal sites.
shablm avatar
cn flag
please see question updated with answers for your questions. Syncing using Feeds module sounds much less work than web services. Would it work with different drupal version sites like between D7 and D9?
cn flag
Yes, Feeds will work with different Drupal versions, and even non-Drupal sites. It depends on what kind of access control you need, but in the simplest setup, you could create a view on the D9 site that outputs the data you need and point the D7 site to it and import it in Feeds on D7.
shablm avatar
cn flag
Great! I will definitely try out Feeds module. Just another quick question regarding access control, all our forms and views are login protected and should not be accessible publicly. Would the view in D9 that outputs data could be configured to be accessed only by D7 / login etc?
cn flag
Yes, see the fetchers here: https://www.drupal.org/node/856644
shablm avatar
cn flag
Hi, unfortunately, since feeds module is not covered under Drupal's security advisory we cannot use this module as per our organisation policy. Please could you suggest an alternative? many thanks
cn flag
Feeds is the way to go from the contrib ecosystem, so if you can't use that, you will be coding everything yourself, good luck. In that case, I would consider SSO (Single Sign-On) between the D7 and D9 sites, and then just let users in the D7 site access the content directly from the D9 site. This also eliminates the content duplication between D9 and D7. But, this only works if you have the same users in both sites.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.