andre-forte
Occasional Observer

fsxa-api: Get reference name via fetchElement

Jump to solution

Hello,

we are using the api fsxa-api and trying to get some more fields. In every section it is possible to add a reference name, but in the api this field is not printed out. Is it possible to get this field?

https://www.npmjs.com/package/fsxa-api#fetchelement

In the documentation there is parameter called:

* @param additionalParams optional additional URL parameters
 
 

But I didn't find any documentation about this.

Thanks in advance

Best,

André

 

0 Kudos
1 Solution

Accepted Solutions
andre-forte
Occasional Observer
0 Kudos
9 Replies
neo-reply-lukas
New Creator

Hello André,

i think you mean the names you can choose when you select "rename" on a section.
Those are pushed into CaaS but currenty not mapped by the fsxa-api. You could retrieve them with a seperate api call, by setting "keys" in additional parameters

keys : {"page.children.children.displayname": 1, "page.children.children.name": 1 }

(untested)
This works, since the keys parameter disables the mapping of the fsxa-api.

If you need the fsxa-api to pass those values, you would need to create a feature request with Crownpeak

Best,
Lukas

neumann
Crownpeak employee

Hello André,

you can also create an issue on github if you'd like. Or even a pull request if you feel up to it 😉

If you're happy with Lukas' Solution, please click on "Accept as Solution" so others know that this a valid workaround for this issue.

Regards,

Emre

0 Kudos
andre-forte
Occasional Observer

Hi neo,

Thanks for your answer. You are right, I meant these names.

 

 

 const page: Page = await fsxaApi.fetchElement({
        id: routeData.caasDocumentId,
        locale: FS_LOCALE,
        fetchOptions: {
            cache: 'force-cache',
            next: {
                tags: ['allRouteData'],
            },
        },
    });

    const referenceNames: Page = await fsxaApi.fetchElement({
        id: routeData.caasDocumentId,
        locale: FS_LOCALE,
        fetchOptions: {
            cache: 'force-cache',
            next: {
                tags: ['allRouteData'],
            },
        },
        additionalParams: {
            keys: { 'page.children.children.displayname': 1, 'page.children.children.name': 1 },
        },
    });

 

 

 

I have created 2 api calls. the first ist getting alle the page data, the next one only the reference names. This works so far, but the objects are looking totally different.

How can I merge them together? Just with a loop? or is there an easier way?

How do you know these keys? Is there a documentation about it?

 

Thanks in advance

0 Kudos

Update:

I have created this here. But the loop doesn't feel good

 referenceNames?.page.children[0].children.forEach((referenceName, index) => {
        const child = page.children[0].children[index];

        if (child && 'id' in child && child.id === referenceName?.identifier) {
            page.children[0].children[index] = {
                ...page.children[0].children[index],
                ...referenceName,
            };
        }
    });

 

0 Kudos

I understand that this "doesn't feel good" thing. We have only fractional insights in your code and challenges, so I'm unsure if we can help you further with your specific problem. This leads me to the question: Why do want to include the reference name in the first place? If there is a sane reason for this we may include it in the API. At the moment we don't see any use case for this, but we may miss something here.

Peter
0 Kudos

@Peter_Jodeleit We need the reference name as ids for anchor tags to scroll down to specific sections. We could also take the ids that are provided, but there are not readable by the user and on the editor in FirstSpirit you also choose this reference name when linking to a section. So if you could provide it via the default api call it would be nice. 

or the additionalParams will include the keys to the whole request.

So for now, when I add this here:

additionalParams: {
            keys: { 'page.children.children.displayname': 1, 'page.children.children.name': 1 },
        },

the rest of the data is gone, only these keys where shown by the request. 

0 Kudos

Thank you for the insights. We will discuss this in the team. Do you mind to create a github issue for this? 

Peter
0 Kudos
andre-forte
Occasional Observer

Sure. I did: https://github.com/e-Spirit/javascript-content-api-library/issues/194

Can you tell me, when this can be implemented?

0 Kudos
Peter_Jodeleit
Crownpeak employee

The attribute is available since release 10.19.0

Peter
0 Kudos