I'm trying to read the value of Custom Metadata from a Publication using ApiClient API.

Below is the code which I'm trying to get the Publication information:

ApiClientProvider pcaClientProvider;
ApiClient pcaClient = this.pcaClientProvider.getClient();

Publication publication = pcaClient().getPublication(ContentNamespace.Sites,id,"", null);

I couldn't able to get the value of Custom Metadata information from the above Publication.

  • Can you confirm which version of DXA and SDL Tridion Sites?
    – Velmurugan
    Nov 4 '20 at 14:10

Welcome to Tridion Stackexchange.

Here you can find the code example to get the publication metadata, I assume you are using DXA 2.2 Java + DXA Model Extension + GraphiQL provider.

private static final String PublicationCustomMetadata = "CustomMetadataFieldName";
String PublicationCustomMetadataValue;

Publication publication = apiClientProvider.getClient().getPublication(
                    "requiredMeta:" + PublicationCustomMetadata,
    String PublicationCustomMetadataValue = publication == null ||
            publication.getCustomMetas() == null ||
                    .anyMatch(meta -> PublicationCustomMetadata.equals(meta.getNode().getValue()));


In the backend, it will generate something like Graphql query request for customMetas

  publication(namespaceId: 1, publicationId:8)
    customMetas(filter: "requiredMeta:CustomMetadataFieldName")  

I hope it helps.

  • Thanks for your quick response @Velmurugan Could you please let me know what is the "requiredMeta:" here. Nov 4 '20 at 14:00
  • Updated my answer, The customMetas filter parameter required that requiredMeta: prefix to add metadata fields names with comma separated, customMetas(filter: "requiredMeta:CustomMetadataFieldName,CustomMetadataFieldName2")
    – Velmurugan
    Nov 4 '20 at 14:20
  • With Graphql query i'm getting null response. Even with filter or without filter i'm getting null as response. Did you tried this? Nov 4 '20 at 15:04
  • You mean GraphQL IDE you are getting the response null? then there is no metadata associated or published? you can validate to explore GraphQL using in-browser GraphQL IDE:velmuruganarjunan.wordpress.com/2019/03/03/…
    – Velmurugan
    Nov 4 '20 at 15:11
  • Yes, with GraphQL IDE i'm getting null as response. and Yes, the metadata is associated and it's published. Nov 7 '20 at 8:32

Querying publication custom metadata has not been supported. Please refer the knowledge-based article published. https://gateway.sdl.com/apex/communityknowledge?articleName=000014029

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.