1

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 at 14:10
0

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(
                    ContentNamespace.Sites,
                    publicationId,
                    "requiredMeta:" + PublicationCustomMetadata,
                    null);
    String PublicationCustomMetadataValue = publication == null ||
            publication.getCustomMetas() == null ||
            !publication.getCustomMetas()
                    .getEdges()
                    .stream()
                    .anyMatch(meta -> PublicationCustomMetadata.equals(meta.getNode().getValue()));

Updated:

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

{   
  publication(namespaceId: 1, publicationId:8)
  {
    customMetas(filter: "requiredMeta:CustomMetadataFieldName")  
    {
      edges 
      {
         node 
        {
           key
           value
        }
      }
    }
  }
}

I hope it helps.

| improve this answer | |
  • Thanks for your quick response @Velmurugan Could you please let me know what is the "requiredMeta:" here. – SandiriVenky Nov 4 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 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? – SandiriVenky Nov 4 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 at 15:11
  • Yes, with GraphQL IDE i'm getting null as response. and Yes, the metadata is associated and it's published. – SandiriVenky Nov 7 at 8:32
0

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

| improve this answer | |

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.