I have two lists with look up column. How do i join two lists using REST API call.
Thanks in advance
You use the $expand query option.
For example, you have two lists: ListA
and ListB
. ListA
has two fields: Field1
and Field2
. ListB
has three fields: FieldA
, FieldB
and LookupField
. LookupField
looks up to ListA
. REST query should be as such:
/_api/web/lists/GetByTitle('ListB')/items?$select=FieldA,FieldB,LookupField/Field1,LookupField/Field2&$expand=LookupField
You select the fields from the list by adding their internal name to the $select
query option, and you select fields from the lookup list by using the format LookupField/FieldFromLookupList
, and then you add the lookup field to the $expand
query option.
$select
portion. For fields from the parent (the lookup list), add them to the $select
portion in the format LookupField/FieldFromLookupList
, where LookupField
is the internal name of the lookup field in the child list (all field names must be the internal names).
lookupfield/fieldname
.