I’m trying to create a bulleted list using the Google Doc API and want to tag a person’s profile in the bullet. For eg, I want to achieve the following in the GDoc:
- To-do item 1: John Doe
It’s possible to resolve John Doe’s profile manually on a Google Doc via @ and entering the email ID but when I use the insertText
request and use an email id like '@johndoe@randomcompany.org'
, the API enters raw text versus resolving the email to John Doe’s profile
>Solution :
Unfortunately, the Google Docs API does not provide a direct way to tag a person’s profile within a bulleted list item. The "@" mention feature you mentioned only works within the Google Docs user interface and cannot be replicated using the API.
However, you can achieve a similar result by using a hyperlink that points to the person’s email address. Here is an example of how to create a bulleted list item with a hyperlink to John Doe’s email address using the Google Docs API:
requests = [{
'insertText': {
'location': {
'index': 1
},
'text': 'To-do item 1:'
}
}, {
'createParagraphBullets': {
'range': {
'startIndex': 0,
'endIndex': 12
},
'bulletPreset': 'BULLET_ARROW_DIAMOND_DISC',
'textStyle': {}
}
}]
Add the hyperlink to John Doe’s email address:
requests.append({
'updateTextStyle': {
'range': {
'startIndex': 12,
'endIndex': 21
},
'textStyle': {
'link': {
'url': 'mailto:johndoe@randomcompany.org'
}
},
'fields': 'link'
}
})
This will create a bulleted list item with the text "To-do item 1:" followed by a hyperlink to John Doe’s email address. When a user clicks on the hyperlink, it will open their default email client and populate the "To" field with John Doe’s email address.
Note that the styling of the hyperlink can be customized using the updateTextStyle request to set properties like the font color, underline, etc.