Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

13 replies

Level 2
Oct 27, 2023 6:53 AM UTC

@jineet_vora and @kautuk_sahni Please check and provide if you have solution or any refernce

Translate
Mahedi_Sabuj
Community Advisor
Community Advisor
Oct 27, 2023 7:04 AM UTC

You can refer to this documentation for instructions on creating tags using Tag Manager API. 

https://experienceleague.adobe.com/docs/experience-manager-65/developing/platform/tagging/building.html?lang=en

Translate
Mahedi Sabuj
arunpatidar
Community Advisor
Community Advisor
Oct 27, 2023 11:53 AM UTC

HI @venkata_naga_saibu 

Please check

 

import com.day.cq.tagging.Tag; import com.day.cq.tagging.TagManager; import org.apache.sling.api.resource.ResourceResolver; public class CreateTagInAEM { public void createTag(ResourceResolver resourceResolver) { // Get the TagManager instance TagManager tagManager = resourceResolver.adaptTo(TagManager.class); // Define the path where you want to create the tag (e.g., "/etc/tags/mytags") String tagPath = "/etc/tags/mytags"; // Define the name of the tag String tagName = "NewTag"; // Create the tag Tag newTag = tagManager.createTag(tagPath, tagName, null, false); if (newTag != null) { // The tag has been created successfully System.out.println("Tag created: " + newTag.getTagID()); } else { // Handle the case where the tag creation fails System.out.println("Tag creation failed"); } } }

 TagManger API : https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/day/cq/tagging/TagManager.html#createTag-java.lang.String-java.lang.String-java.lang.String-boolean-  

Translate
Arun Patidar
Level 2
Oct 27, 2023 2:40 PM UTC

hi @arunpatidar ,

I tried your code, but it is not generating new tag

 

Thanks

Translate
arunpatidar
Community Advisor
Community Advisor
Oct 27, 2023 3:45 PM UTC

Hi @venkata_naga_saibu 
Make sure you have resourceResolver with proper permissions.

public void createTag(ResourceResolver resourceResolver)

  

Could you please share your code?

Translate
Arun Patidar
Level 2
Oct 30, 2023 5:20 AM UTC
Hi @arunpatidar ,

Pls check and let me know if i need to do any changes.
import com.day.cq.tagging.InvalidTagFormatException;
import com.day.cq.tagging.Tag;
import com.day.cq.tagging.TagManager;
import org.apache.sling.api.resource.ResourceResolver;

public class CreateTagInAEM {

public void createTag(ResourceResolver resourceResolver) throws InvalidTagFormatException {
// Get the TagManager instance
TagManager tagManager = resourceResolver.adaptTo(TagManager.class);

// Define the path where you want to create the tag (e.g., "/etc/tags/mytags")
String tagPath = "/content/cq:tags/wknd-shared";

// Define the name of the tag
String tagName = "NewTag"

// Create the tag
Tag newTag = tagManager.createTag(tagPath, tagName, null, false);

if (newTag != null) {
// The tag has been created successfully
System.out.println("Tag created: " + newTag.getTagID());
} else {
// Handle the case where the tag creation fails
System.out.println("Tag creation failed");
}
}
}
Translate
kautuk_sahni
Level 9
Oct 30, 2023 11:35 AM UTC

@venkata_naga_saibu Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Translate
Kautuk Sahni