Skip to main content

Search

Support for calling entra-authenticated external APIs

Comments

1 comment

  • Jonathan Cardy

    Just to follow up on this - after speaking to the team, if a Promise object is returned from the script action, it will be awaited and the promise result is used as the action output which is perfect.

    Therefore, to use async calls, you can use this pattern:

    let func = async function () {

        const tokenProvider = await spfxContext.aadTokenProviderFactory.getTokenProvider();

        const token = await tokenProvider.getToken('7c816beb-102f-49cd-88f7-06085e5df3ac');

        const headers = new Headers();

        const bearer = `Bearer ${token}`;

        headers.append('Authorization', bearer);

        headers.append('Accept', 'application/json, text/plain');

        headers.append('Content-Type', 'application/json;charset=UTF-8');

        const options = {

            method: 'POST',

            headers: headers,

            body: JSON.stringify(...)

        };

        const result = await fetch('url', options); 

        return await result.json();

    };

    //Convert the async function call to a promise for Skybow to be able to interpret the result

    return new Promise((resolve, reject) => {

     func().then(result => {

         resolve(result);

     });

    });
     
    Alternatively, just don't await the last async call of your method.
    0

Please sign in to leave a comment.