question

avimon avatar image
avimon asked

Syntax at start of cloudscript ?

what is 

POST https://{
                {TitleID}}.playfabapi.com/Server/AddFriend
    Content-Type: application/json
    X-SecretKey:<developer_secret_key>

at start of cloudscript? Why is it necessary and how we can avoid it incase it is avoidable?
CloudScript
10 |1200

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

brendan avatar image
brendan answered

The AddFriend call might look like this, but it doesn't have to be at the "start" of a Cloud Script:

var request = {
PlayFabId: currentPlayerId, FriendPlayFabId: args.FriendPlayFabId

};

var result = server.AddFriend(request);

And, of course, there are other parameters you can use to look up the friend to be added.

But I'm not sure what you mean concerning "Why is it necessary and how we can avoid it incase it is avoidable?"

It's not "necessary" to add friends - you only need to do that if you want to use the PlayFab friends system. Can you clarify what you're asking?

4 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.

avimon avatar image avimon commented ·

@Brendan

    POST https://{ {TitleID}}.playfabapi.com/Server/AddFriend

    Content-Type: application/json

    X-SecretKey:<developer_secret_key>

    I was asking about above syntax. I have seen it in every cloudscript. Can you explain it to me?

    0 Likes 0 ·
    brendan avatar image brendan ♦♦ avimon commented ·

    Can you please specify where you're seeing a Cloud Script that uses this format? It is not necessary to use the Secret Key in any Cloud Script call. The Server API calls can be made exactly as shown above - the fact that they're running in Cloud Script means that the Secret Key is already part of the call.

    0 Likes 0 ·
    avimon avatar image avimon brendan ♦♦ commented ·

    @Brendan I am getting this error

    after uploading this cloudscript

    Can you tell me what I am doing wrong and also tell me what I have to add to it?

    0 Likes 0 ·
    screenshot-481.png (177.6 KiB)
    screenshot-480.png (88.0 KiB)
    Show more comments
    Hubert avatar image
    Hubert answered

    I think you need to encapsulate your code in a method

    handlers.AddFriend = function (args, context) {

    var request = {PlayFabId: currentPlayerId, FriendPlayFabId: args.FriendPlayFabId};

    var result = server.AddFriend(request);

    }

    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.