greg-e
greg-e

Reputation: 434

Microsoft Teams tab http/https does not send request

I want to create a Microsoft Teams Tab as a web application. I've got the initial setup up and running. (Using Yo Teams) Now I want to send a http(s) request to an Azure Function. So I added a post middleware function to my server.ts, which should call the Function.

    express.post("/createteamswiki", (req, res) => {
        https.request("my.function.url", { method : "POST" }, () => {
        });
        res.status(200);
        res.json("Oki");
    }); 

In my WikiConfig.ts I changed the save method to send the request. I tried to use vanilla-js and the modules: http and https. With vanilla-js the request gets sent but it is marked as ERR_FAILED in Chrome dev tools. The libraries do not send anything at all. So the success callback is never called and therefore saveEvent.notifySuccess(); is not called either. So the config window stays and reports an error.

    public async componentWillMount() {
            this.updateTheme(this.getQueryVariable("theme"));
    
            if (await this.inTeams()) {
                microsoftTeams.initialize();
    
                microsoftTeams.getContext((context: microsoftTeams.Context) => {
                    this.setState({
                        value: context.entityId
                    });
                    this.updateTheme(context.theme);
                    microsoftTeams.settings.setValidityState(true);
                    microsoftTeams.appInitialization.notifySuccess();
                });
    
                microsoftTeams.settings.registerOnSaveHandler((saveEvent: microsoftTeams.settings.SaveEvent) => {
                    // Calculate host dynamically to enable local debugging
                    const host = "https://" + window.location.host;
                    microsoftTeams.settings.setSettings({
                        contentUrl: host + "/sharepointWikiTab/?name={loginHint}&tenant={tid}&group={groupId}&theme={theme}",
                        websiteUrl: host + "/sharepointWikiTab/?name={loginHint}&tenant={tid}&group={groupId}&theme={theme}",
                        suggestedDisplayName: "Sharepoint Wiki",
                        removeUrl: host + "/sharepointWikiTab/remove.html?theme={theme}",
                        entityId: this.state.value
                    });
                    microsoftTeams.getContext((context: microsoftTeams.Context) => {
                        this.setState({
                            value: context.teamSiteUrl || ""
                        });
                        https.request("https://" + window.location.host + "/createteamswiki?code=gM6t7bov41tkw1ZTxGZUasY1WQH7UgrONp4OyoVzaYaFtFBTBwZcRQ==&team=" + context.teamSiteUrl, (res) => {
                            this.setState({
                                value: "Awesome it works..."
                            });
                            saveEvent.notifySuccess();
                        });
                    });
                    // saveEvent.notifySuccess();
                });
            } else {
            }
        }

I can't find any reason why it behaves that way, since the request calls the node.js server, which is serving the http files successfully.

Upvotes: 0

Views: 355

Answers (1)

Trinetra-MSFT
Trinetra-MSFT

Reputation: 1015

I believe this is something caused due to cross origin request. Can you check your request header and see if the CORS is enabled and also check the url is added in validDomain[] array in manifest

Upvotes: 1

Related Questions