admin管理员组文章数量:1122832
I'm building a Graph-Connector using msgraph-sdk-java to create connection/schema.
According to documentation an ExternalConnection has a SearchSettings property which then holds a collection of DisplayTemplate as search result templates.
I'm struggling to pass such an DisplayTemplate
to the ExternalConnection
.
The following approach throws an error (com.microsoft.graph.models.odataerrors.ODataError: The request is malformed or incorrect.
):
ExternalConnection externalConnection = new ExternalConnection();
externalConnection.setId(connectionId);
externalConnection.setName(connectionName);
DisplayTemplate template = new DisplayTemplate();
template.setId("testTemplate");
template.setLayout(new UntypedString("{\"type\": \"AdaptiveCard\",\"version\": \"1.0\",\"body\": [{\"type\": \"TextBlock\",\"text\": \"A contoso ticket.\"}]}"));
SearchSettings settings = new SearchSettings();
settings.setSearchResultTemplates(List.of(template));
externalConnection.setSearchSettings(settings);
graphClient.external().connections().post(externalConnection);
For the Schema
there is a separated API call, but I didn't find anything accordingly for the DisplayTemplate:
graphClient.external().connections().byExternalConnectionId(connectionId).schema().patch(schema);
There is a Manage search results layout in the documentation but it only shows how to read data.
I'm building a Graph-Connector using msgraph-sdk-java to create connection/schema.
According to documentation an ExternalConnection has a SearchSettings property which then holds a collection of DisplayTemplate as search result templates.
I'm struggling to pass such an DisplayTemplate
to the ExternalConnection
.
The following approach throws an error (com.microsoft.graph.models.odataerrors.ODataError: The request is malformed or incorrect.
):
ExternalConnection externalConnection = new ExternalConnection();
externalConnection.setId(connectionId);
externalConnection.setName(connectionName);
DisplayTemplate template = new DisplayTemplate();
template.setId("testTemplate");
template.setLayout(new UntypedString("{\"type\": \"AdaptiveCard\",\"version\": \"1.0\",\"body\": [{\"type\": \"TextBlock\",\"text\": \"A contoso ticket.\"}]}"));
SearchSettings settings = new SearchSettings();
settings.setSearchResultTemplates(List.of(template));
externalConnection.setSearchSettings(settings);
graphClient.external().connections().post(externalConnection);
For the Schema
there is a separated API call, but I didn't find anything accordingly for the DisplayTemplate:
graphClient.external().connections().byExternalConnectionId(connectionId).schema().patch(schema);
There is a Manage search results layout in the documentation but it only shows how to read data.
Share Improve this question edited Nov 21, 2024 at 14:06 flavio.donze asked Nov 21, 2024 at 13:45 flavio.donzeflavio.donze 8,06010 gold badges66 silver badges99 bronze badges2 Answers
Reset to default 0UntypedString
will produce string, but you need to produce a JSON. It could be achieved by UntypedObject
template.setLayout(new UntypedObject(
new HashMap<>() {
{
put("type", new UntypedString("AdaptiveCard"));
put("version", new UntypedString("1.0"));
put("body", new UntypedArray(Arrays.asList(new UntypedObject(
new HashMap<>() {
{
put("type", new UntypedString("TextBlock"));
put("text", new UntypedString("A contoso ticket."));
}
}))));
}
}));
After some more research I came accross Serialization helpers.
It seems like it is not possible to create an ExternalConnection
, set the SearchSetting
and pass the whole object in the post()
.
ODataError: One or more request precondition not met.
So first create and post()
the ExternalConnection
, then read the JSON to create the SearchSettings
and use patch()
:
ExternalConnection externalConnection = new ExternalConnection();
externalConnection.setId(connectionId);
externalConnection.setName(connectionName);
graphClient.external().connections().post(externalConnection);
// read search settings and patch the ExternalConnection
try (InputStream in = new FileInputStream("D:/temp/template.json")) {
SearchSettings searchSettings = KiotaJsonSerialization.deserialize(in, SearchSettings::createFromDiscriminatorValue);
externalConnection.setSearchSettings(searchSettings);
graphClient.external().connections().byExternalConnectionId(externalConnection.getId()).patch(externalConnection);
}
An example of a JSON can be found here: searchSettings resource type
本文标签: javahow to configure a DisplayTemplate for ExternalConnection in microsoft Graph APIStack Overflow
版权声明:本文标题:java - how to configure a DisplayTemplate for ExternalConnection in microsoft Graph API? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736310349a1934344.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论