question

Bernardo Varela avatar image
Bernardo Varela asked

Call PlayFab CloudScript using Azure Function

Is there any example code to just call PlayFab API from Azure functions?

Our idea is to call the Azure function from our game code without a login to PlayFab using an http request. Then the Azure function would call a server-side CloudScript. Is this easy to do with an API or do we need to use make an http POST request using the PlayFab Web API from the Azure function code?

apisCloudScript
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Citrus Yan avatar image
Citrus Yan answered

You can install the PlayFab SDK into your Azure Functions, depending on the language of your choice, in order to make PlayFab API calls from it. This code repository contains some Azure Function demo code you may find helpful:

https://github.com/PlayFab/PlayFab-Samples/tree/master/Samples/CSharp/AzureFunctions

Actually, I think what can be done via CloudScript can also be done in Azure Functions, hence, I don’t think it necessary to call CloudScript via Azure Functions when you can implement all your server-side logic in Azure Functions.

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Shaiv Kamat avatar image Shaiv Kamat commented ·

@Citrus Yan Would you be able to go into a bit more detail about using the PlayFab SDK (Node) in Azure Cloud Functions?

Specifically I'm running into an Internal server error when ever I try and make an API call with what I have below (This is my index.js for the specific function being called).

Solved: needed a GetEntityToken call, then the rest works just fine.

const util = require('util');
const PlayFab = require('playfab-sdk');
//Manually set titleId and DevSecret key for testing
const cloudScript = util.promisify(PlayFab.PlayFabGroups.ListMembership);

module.exports = async function (context, req) {
    context.log('FNVersion', 2);
      const args = req.body.FunctionArgument;
      let res;
        try {
            res = await cloudScript({Entity: args.coach});
            context.log('res', args.coach);
        } catch (err) {
            context.log.error('ERROR', err);
            throw err;
        }

        context.res = {
            status: 200,
            body: {args: req.body.FunctionArgument, res, req},
        };
    return context;
};

These are the Azure Cloud Function logs

1 Like 1 ·
image.png (17.1 KiB)
Citrus Yan avatar image Citrus Yan Shaiv Kamat commented ·

Hi, sorry for the late response, glad you solved this!

BTW, you can create a new thread next time in case sometimes we may miss answered questions.

0 Likes 0 ·
Dan Mlodecki avatar image
Dan Mlodecki answered

There's a C# api out there that might do the trick?
https://docs.microsoft.com/en-us/gaming/playfab/sdks/c-sharp/

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.