Overview

I had an opportunity to add content to Drupal using Python, so this is a memo of the process. I referenced the following article.

https://weimingchenzero.medium.com/use-python-to-call-drupal-9-core-restful-api-to-create-new-content-9f3fa8628ab4

Preparing Drupal

I set it up on Amazon Lightsail. The following article is a useful reference.

https://annai.co.jp/article/use-aws-lightsail

Modules

Install the following modules.

  • HTTP Basic Auth
  • JSON:API
  • RESTful Web Services
  • Serialization

Changing JSON:API Settings

Access the following page to change the settings.

</admin/config/services/jsonapi>

Python

Set {IP address or domain name} and {password} as appropriate.

For Amazon Lightsail, the default username is user. You can check the password with the following command.

cat~/bitnami_application_password
ifeuph}p}rrmrnea.pod==ay=tompdlero''e''o"}rxtriu{rACadetenspscodaqrqteacntueurs=et=a""}eqe='spe"tasusw{tn{:yttet'o'tptssshr:-{er""}.t.tdT"itbpsat}'y:biooup'aputdst:pe"tly""th/p'nee"vf(/l:os":aoei{id":lrnmIc'e:{umdpPaa-"eapotp-{W"toraipah:"itdolra:ndnitt"tHr/ci'B",TevacsepTsntllhPsdieuwaeB.o"paiaaoan,tndsrp/fe_eiivrrtrcd+no.esAojdmx=ums.MthtaoaPy"ehinpyan'itfd,+hrenjoirasnesmo"n,en,d}'sa/.uj"ts,ho=n(aup,i/pn)o,dej/saornt=ipcalyel'oad)

Additional Notes

I also attempted to register a node_type as follows.

p}urrar.yl=jlso"}=roadendafq(t"u)=a""}{e"tahs{:ytotptss{er""t."itd}p:bie/outsjs"tlcstneero(os"inud":pare:tpl_"ii,t{o/ynnhp"oee":da-,ed-"_enntrooysddp=eeeh__/ettnayyodppdeeeer"_s,t,ypaeu"th"=(username,password),json=payload)

As a result, I received a Method Not Allowed error as shown below.

{''j'esmr''oersdntoteaaratp'stai:'ui':sl:{'''[::{l{'i'''vnt4Neki0orst5s'l'ri:e,oo'un{:t''e:s'eMf'leo1ftu.'hn0:od'd,{f'Nohorrte"fAP'lO:lSoT'whe/tdjt'sp,o:n/a/pjis/onnoadpei_.toyrpge//fnoordmea_tt/y1p.e0"/:'}M}e}t}h,odNotAllowed(Allow:GET,HEAD)',

I plan to continue investigating this issue.

Summary

I will continue investigating in order to use Drupal as a headless CMS.