lumpy-lum avatar image
lumpy-lum asked

Having trouble using httpRequest to access PayPal API

Hi all,

so I'm working on an app that requires me to implement PayPal as a way to payout money to its users. I had originally looked into PlayFab + PayPal's Express Checkout, but that seems to only allow users to purchase things (but if I'm wrong, please correct me!). I actually want the users to have the ability to have money sent directly to their PayPal accounts.

As a test, I wrote up a simple http request in CloudScript, to see if I can connect to PayPal. I've tested this request in Postman, and I have it working successfully, where it will return a JSON with some data in it! However, when I make this call with CloudScript, then use ExecuteCloudScript in my app, the FunctionResult returns this: {"responseContent":""}. It's empty!

I guess my question is: am I doing something wrong in my request? I've never really made an http request before, so I feel like I'm probably missing something straightforward.

and just so everyone knows, the "Bearer {...}, Basic {...}" is populated with my bearer token, and basic auth info. I changed them to {...} for privacy reasons.

handlers.withdrawPayPal = function (amount) {
    var headers = {
    "authorization": "Bearer {...},Basic {...}=",
      "cach-control": "no-cache"
    var body = {
        "grant_type": "client_credentials"

    var url = "";
    var content = JSON.stringify(body);
    var httpMethod = "POST";
    var contentType = "application/x-www-form-urlencoded";
    // The pre-defined http object makes synchronous HTTP requests
    var response = http.request(url, httpMethod, content, contentType, headers);
    return { responseContent: response };
10 |1200

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

1 Answer

Seth Du avatar image
Seth Du answered

Cloud script will generate error report when anything unexpected occurs, and with correct configuration, the messages can show at the PlayStream. According to your description, it seems the cloud script works fine but the response is NULL, which means this can be your PayPal http request issue. The correct format of PayPal http request can be found on the PayPal official documentation website (we know that the documentation seems to only provide cURL examples to call the API, you can follow the guide flow to test ).

PayPal provides SDK for almost all popular platforms, we suggest you configuring the SDK for API calls, as PlayFab is based on RESTful API while we suggest users using SDK to call APIs.

Additionally, we notice the format of authorization part in your header is confusing. We are not sure whether what you have provided is hard coded for testing, because you have to transfer token for every single user and for now there is only an ‘amount’ parameter and we do not know where you generate Basic Authentication keys.

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.