fsxa-api: Get reference name via fetchElement
Author: andre-forte
Publication Date: 10/9/2023 15:43
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:
But I didn't find any documentation about this.
Thanks in advance
Best,
André
Tags: caas, headless, javascript-content-api
-
Author: Peter_Jodeleit - 11/21/2023 12:40
The attribute is available since release 10.19.0
0 -
Author: neumann - 10/18/2023 11:00
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 -
Author: neo-reply-lukas - 10/17/2023 16:11
Hello André,
i think you mean the names you can choose when you select "rename" on a section.
keys : {"page.children.children.displayname": 1, "page.children.children.name": 1 }
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(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,
Lukas0 -
Author: andre-forte - 10/20/2023 10:42
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 -
Author: andre-forte - 10/20/2023 14:01
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 -
Author: Peter_Jodeleit - 10/25/2023 14:14
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.
0 -
Author: andre-forte - 11/2/2023 15:32
Sure. I did: https://github.com/e-Spirit/javascript-content-api-library/issues/194
Can you tell me, when this can be implemented?
0 -
Author: andre-forte - 10/25/2023 15:41
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 -
Author: Peter_Jodeleit - 10/25/2023 16:55
Thank you for the insights. We will discuss this in the team. Do you mind to create a github issue for this?
0
Please sign in to leave a comment.
Comments
9 comments