Overview

This is a personal note on how to use Drupal’s JSON:API. This time, I will cover the use of include for taxonomies and multilingual processing.

Data

As shown below, the taxonomy “Assistant Professor” has been assigned to the position field.

/node/5

Additionally, content multilingualization is enabled, so the English versions of the title and position are also displayed as shown below.

/en/node/5

JSON:API

Since the above content was created with the content type “faculty”, the data list can be retrieved from the following URL.

/jsonapi/node/faculty/

Below shows the result excluding the links field. While the taxonomy ID is included in field_position, the label of that taxonomy is not included.

{}"}"]j,ds""}a{}ovmtnee"}a"""}"}artl"tia,rpsai"}:ydt""""""""""""""""}"e"}"}"}"}ii"nsp"tddlrrstccpsdrccp,bln,r,u,f"o:ke"[e:rrraeetirhrteeooa"""oao"}e"}i"}i"}:nslh"iuunvvateaoifvnntapldtddvddded"{"fr:"bppgiitlanmcaitthliayiea"""}ia"""}"a"""}la"""}{::"e5uaacssuetgokusee"idn"o_ttimsttim:ttimdttim:f"8tlloiis"eetylinn:a"g:ntayde"iayde"ayde"_ayde""{"n6e__doo":dde"totts:csy"p"tdo"p"td{"p"tdp"p"td1{:oesiienn:""":_n__{"onhp:e:arn:e:ar:e:aro:e:ar.df"nn"__":::l_tt:nduie""u_""u""us""u0"e1:tt:tltfatrruelp"{:":pu{:":p{:":pi{:":p"h-deeior""tanraanl"ls:8ai0a0at6a,t-9{rr"mgu22rlgannul:""4{ld"b{l"b{li"c{ltf-nnje"e"00uscnssl,:{n1_"u0_u0_ote_pabaaas:,,22eeoslll"o9i:s0is0ina4i:c6ll"t33,,dlaa,j{d6ne1ne1n"x5n/u8__,an--eattae2t{retret:o8t/l0__mu00"tii"_fe-4e-4eneejt-nvpl66:ioot7r-dr-dr{o8rsy4ii"l--onny-nu-nu-nm-no"1dd:,00tn__p9aseaseay6an,f""88r_soe1ledledl_dla9::"TTuaou-c_r2_r2_t7_p-200efut-8_"9_"9_e9_ib51001,frdn-t,-t,-tr-t.5,32::ecao4a4a4am4ao4,340cetd7rarar-errb-41t"eeag5g5g-dgg-0::e:d_1e3e3ep1e/7612d"t-t-t-to-tfe-56"":yb_9_9_s9_ob0++:up3i6i6ii6irc800nfe3d0d0dt5dmdT00nda"5"d"d"i3"ac0::u"l,-:-:-:o-:t9100l,se99n5/d:00lea"c1c1"e5110"",,4fdd,c.51,,9acc104:4ccc7/f4eu338""3fldd5,+et33604yaa806"ddb:77770c00a0""""",,,,,

Using include

Add ?include=field_position to the query. As a result, the included field is added, and the value of the taxonomy term’s name field can also be obtained.

{}"}"]"]j,d,is""}a{}n{}ovmtcnee"}a"""}"}l"""}"}artl"tia,rutia,rpsai"}:ydt""""""""""""""""}"e"}"}"}"}dydt""""""""""""""""}e"}"}"}"}ii"nsp"tddlrrstccpsdrccp,bln,r,u,fep"tddlrrsndwcdrcccplv,r,p,c"o:ke"[e:rrraeetirhrteeooa"""oao"}e"}i"}i"}de:rrraeetaeeheeoooa"""ai"}e"a"]o"}:nslh"iuunvvateaoifvnntapldtddvddded""iuunvvamsiafvnnntapltddvdrdnd"{"fr:"bppgiitlanmcaitthliayiea"""}ia"""}"a"""}la"""}::"bppgiitecgnaittthliai"a"""}iaea{}ta"""}{::"e5uaacssuetgokusee"idn"o_ttimsttim:ttimdttim6uaacssu"rhguseee"idno:ttimstntettim:f"8tlloiis"eetylinn:a"g:ntayde"iayde"ayde"_ayde"["ctlloiis:itelinnn:a"gnayde"iata""nayde""{"n6e__doo":dde"totts:csy"p"tdo"p"td{"p"tdp"p"tdtee__doo"p"dtottts:cs{"p"tdo"""tit"p"td1{:oesiienn:""":_n__{"onhp:e:arn:e:ar:e:aro:e:ara4siienn:"t:"_n___{"oh:e:arn:::yd_:e:ar.df"nn"__":::l_tt:nduie""u_""u""us""ux5"nn"__i:l_ttt:ndi""u_p"t""u0"e1:tt:tltfatrruelp"{:":pu{:":p{:":pi{:":po8:tt:clto0atrrruep{:":pun{[e:r{:":p"h-deeior""tanraanl"ls:8ai0a0at6aneeeror"n,"nraaanl"s4asu"a0a,t-9{rr"mgu22rlgannul:""4{ld"b{l"b{li"c{lo8{rr"egu,"2gannnul:""5{lel:"n"b{ltf-nnje"e"00uscnssl,:{n1_"u0_u0_ote_m-nnja_e:0cnsssl,:t0_rlvsu0_pabaaas:,,22eeoslll"o9i:s0is0ina4iy6aaatm,2osllll"aei""ils0i:c6ll"t33,,dlaa,j{d6ne1ne1n"x5n_dll"een3dlaaa,j{x8n:trae1n/u8__,an--eattae2t{retret:o8tt7__,dsu-eatttaoetattret/l0__mu00"tii"_fe-4e-4eneee9__"sl0"tiii"n8e{xui-4ejt-nvpl66:ioot7r-dr-dr{o8rr-tr:al6:ioooo5roao-drsy4ii"l--onny-nu-nu-nm-nm4ieg,-onnnm-nnlnu-no"1dd:,00tn__p9aseaseay6a-edv"e0tn___y4ao"_sean,f""88r_soe1ledledl_dl-d"i2"8r_soc_8lmuedla9::"TTuaou-c_r2_r2_t7_p1:s0:Tuaourv6_yir2_p-200efut-8_"9_"9_e9_o-i20efuteo6__d"9_ib51001,frdn-t,-t,-tr-ts95o3n1,frdac-tt",-t.5,32::ecao4a4a4am4ai6,n-u:ecata4ae:4ao4,340cetd7rarar-ert5_0l0ceteb3rrarrb-41t"eeag5g5g-dgi3i6l0t"edu7gm{5gg-0::e:d_1e3e3ep1eo-d-,:e:d"l3e-3e/7612d"t-t-t-to-tn5"03d":a-t--tfe-56"":yb_9_9_s9_"e:81"":r9_p9_ob0++:up3i6i6ii6i,cT+:u"y7io6irc800nfe3d0d0dt5d1500nf2-cds0dmdT00nda"5"d"d"i3"7,10tda0-2"id"ac0::u"l,-:-:-:o-:8::r"l2t-:t-:t9100l,se99n5500u,s3adi9/d:00lea"c1c1"e5600ee-xb"oc1110"",,4fdd,c8:",,0o2pnd.51,,9acc1b3,6n5o"c04:4ccc771-o9s,c/f4eu338a+0mai3""3fldd5"08yctd,+et336,0T_3i304yaa8:0v8oa06"ddb01o1nd:77770:cf"70c00a"0af00"""",0b""",,,,:u,,,3l1a+r0y0":,00",

Furthermore, by using the fields query, you can reduce the size of the retrieved results as shown below.

/jsonapi/node/faculty/?include=field_position&fields[node–faculty]=title,field_position&fields[taxonomy_term–position]=name

{}"}"]"]j,d,is""}a{}n{}ovmtcnee"}a"""}"}l"""}artl"tia,rutiapsai"}:ydt"e"}dydt"ii"nsp"ttlfep"tn"o:ke"[e:riai"}de:ra:nslh"itted""im"{"fr:"blila"""}::"be{::"e5ueodttim6u":f"8t"n_ayde"["ct:"{"n6e:sp"p"tdtee1{:oesho:e:ara4s".df""is""ux5"0"e1:pi{:":po8:"h-dst6ane",t-9{"i"c{lo8{tf-":ote_m-pabna4iy6:c6{"x5n_d/u8:o8tt7/l0neee9jt-{o8rr-sy4m-nm4o"1y6a-en,f_dl-da9t7_p1p-e9_o-ibr-ts9.5m4ai6o4-ert5rb-dgi3g-p1eo-/7o-tn5fes9_"eobi6i,crct5d1mdi3"7aco-:8t9n55/d"e5611,c8.51b0477/f8a""5",6,8b7a",

Multilingual Support

Simply by appending the language to the URL, data in that language can be retrieved.

/en/jsonapi/node/faculty/?include=field_position&fields[node–faculty]=title,field_position&fields[taxonomy_term–position]=name

{}"}"]"]j,d,is""}a{}n{}ovmtcnee"}a"""}"}l"""}artl"tia,rutiapsai"}:ydt"e"}dydt"ii"nsp"ttlfep"tn"o:ke"[e:riai"}de:ra:nslh"itted""im"{"fr:"blila"""}::"be{::"e5ueodttim6u":f"8t"n_ayde"["ct:"{"n6e:sp"p"tdtee1{:oesho:e:ara4s".df""is""ux5"a0"e1:Spi{:":po8:s"h-dast6anes,t-9{t"i"c{lo8{itf-o:ote_m-spabrna4iy6t:c6u{"x5n_da/u8:o8tt7n/l0Nneee9tjt-a{o8rr-sy4km-nm4po"1ay6a-ern,fm_dl-doa9ut7_p1fp-re9_o-eibar-ts9s.5"m4ai6so4-ert5orb-dgi3rg-p1eo-"/7o-tn5fes9_"eobi6i,crct5d1mdi3"7aco-:8t9n55/d"e5611,c8.51b0477/f8a""5",6,8b7a",

Summary

Many features are implemented, and I found it very convenient. I hope this serves as a useful reference for others.