How can get data from multiple tables using REST api ?

TRISHUL TANDEL asked on September 9, 2020 07:20

How can I get data from multiple tables using REST api ? I am using kentico 12.

~/rest/cms.resourcetranslation/all

I need CMS_ResourceString and CMS_ResourceTranslation both data in one api. I need to get list of resource strings with its translation for current culture of site. Please suggest best applicable solution

Correct Answer

TRISHUL TANDEL answered on September 11, 2020 09:44

Getting below response from Kentico support:

I am afraid but it is not possible in this case. the REST API in Kentico allows only one API call for one object type only at a time. So, you will need to do multiple REST API calls.

The bindings parameter suggested by Dmitry just adds some more information to the response but you still need to make multiple calls. E.g. when requesting user object with the binding parameter, the response should contain e.g. the SiteID to which the user is assigned. But that's it.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Dmitry Bastron answered on September 9, 2020 14:59

Hi Trishul,

I'm not 100% sure it can be retrieved with a single query. Localizations are stored as 2 objects: cms.resourcestring (key) and cms.resourcetranslation (value). You can request all keys first with this request: /rest/cms.resourcestring/all so you will get something like this:

<cms_resourcestrings>
    <CMS_ResourceString>
        <StringID>3</StringID>
        <StringKey>custom.Colour</StringKey>
        <StringIsCustom>true</StringIsCustom>
        <StringGUID>699cd546-de8a-4827-a832-1fcc7e92935f</StringGUID>
    </CMS_ResourceString>
    <TotalRecords>
        <TotalRecords>1</TotalRecords>
    </TotalRecords>
</cms_resourcestrings>

And then iterating through keys you can request translations using StringID values: /rest/cms.resourcestring/3/bindings/cms.resourcetranslation, which will return all translations for this particular key:

<cms_resourcetranslations>
    <CMS_ResourceTranslation>
        <TranslationID>5</TranslationID>
        <TranslationStringID>3</TranslationStringID>
        <TranslationText>Colour</TranslationText>
        <TranslationCultureID>50</TranslationCultureID>
    </CMS_ResourceTranslation>
    <CMS_ResourceTranslation>
        <TranslationID>6</TranslationID>
        <TranslationStringID>3</TranslationStringID>
        <TranslationText>Colore</TranslationText>
        <TranslationCultureID>120</TranslationCultureID>
    </CMS_ResourceTranslation>
    <TotalRecords>
        <TotalRecords>2</TotalRecords>
    </TotalRecords>
</cms_resourcetranslations>

In theory according to the documentation (scroll to very bottom), you should be able to include bindings and hierarchy in your first request and CMS should return these all together in one response, but when I tested it on my local environment, it didn't return bindings for some reason:

/rest/cms.resourcestring/all?translations=true&bindings=true&hierarchy=true

You can ask Kentico support why this request doesn't work as expected, there could be a bug they can fix.

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.