user2240193
user2240193

Reputation: 21

ParseCloud httpRequest post exception

I am trying to execute a http request in using the cloud code module from Parse.com. I then invoke from my android app but keep getting this exception :

com.parse.ParseException:java.lang.IllegalArgumentException Trying to execute a POST command without body parameters.

Code below and it keeps giving me

 Parse.Cloud.define('httpRequest', function(request, response) {
        var requestParams = {
        'apiKey': '{API_KEY}',
        'currency':'GBP',
        'locale':'en-GB',
        'adults':'1',
        'children':'0',
        'infants':'0',
        'originplace':'11235',
        'destinationplace':'13554',
        'outbounddate':'2015-08-19',
        'inbounddate':'2015-08-26',
        'locationschema':'Default',
        'cabinclass':'Economy',
        'groupPricing':'true',
        'country':'GB'
        };
      Parse.Cloud.httpRequest({
        method: 'POST',
        url: 'http://partners.api.skyscanner.net/apiservices/pricing/v1.0/',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
        },
         body: {'private': 'Your_mOTP_Private_Key'},
       params: requestParams,
        success: function(httpResponse) {
            response.success(httpResponse.text);
             console.log(httpResponse.text);
        },
        error: function(httpResponse) {
            response.error("error: " + httpResponse.status);
             console.log(httpResponse.status);
        }
    });
    });

 Parse.initialize(this,"{APP_ID}","{CLIENT_KEY}");
        ParseCloud.callFunctionInBackground("httpRequest", null, new FunctionCallback<Map<String, Object>>() {
            public void done(Map<String, Object> mapObject, ParseException e) {
                if (e == null) {
                    Toast.makeText(MainActivity.this, mapObject.toString(), Toast.LENGTH_LONG).show();
                }else{
                    Toast.makeText(MainActivity.this,e.getMessage(),Toast.LENGTH_LONG).show();
                    Log.i(e.getMessage());
                }
            }
        });

Upvotes: 0

Views: 587

Answers (1)

Lee Leo
Lee Leo

Reputation: 21

I also had got this problem. Then I solved.

callFunctionInBackground 's 2nd parameter cannot be null.

Here's example

Map<String, String> parameters = new HashMap<String, String>();
                                    ParseCloud.callFunctionInBackground("onPhotoUpload", parameters, new FunctionCallback<HashMap<String, String>>()
                                    {
                                        public void done(HashMap<String, String> mapObject, ParseException e)
                                        {
                                            if (e == null)
                                            {
                                                Toast.makeText(context, mapObject.get("answer").toString(), Toast.LENGTH_SHORT).show();
                                            }
                                            else
                                            {
                                                Log.e("onPhotoUpload", e.getMessage());
                                                Toast.makeText(context, "Error saving: " + e.getMessage(), Toast.LENGTH_SHORT).show();
                                            }
                                        }
                                    });

Upvotes: 2

Related Questions