简体   繁体   中英

How to make an httpRequest from jobs in parse cloud code?

Parse.Cloud.job("syncMetadataWithContentPortal", function(request, status) {
    var apikey ="49eiivmz"; 
    var uid = "t1g4Y2jC6S";
    Parse.Cloud.httpRequest({
        url: 'https://api.parse.com/1/functions/getContentMetaData',
        method: 'GET',    
        headers : { 
            'Content-Type': 'application/json',
            'X-Parse-Application-Id':'appkey',
            'X-Parse-REST-API-Key':'restapikey',  
        },
        body: {
            apiKey : apikey
        }
    }).then(function(httpResponse) {
        Parse.Cloud.useMasterKey();
        status.message(httpResponse.text);
        console.log(httpResponse.text);
        var contents = JSON.parse(httpResponse.text);

        var contentIdCollection = [];
        for (var i = 0; i < contents.length; i++) {
            contentIdCollection.push(contents[i].id);
        }
        status.success('Content Synced');
    }, function(httpResponse) {
        // console.error('Request failed with response code ' + httpResponse.status);
        status.error('Request failed with response code ' + httpResponse.status)
    });
});

So I have a job making httpRequest to call a function getContentMetaData which requires API key as a parameter.

  1. How do I send parameters using GET method?
  2. I got status as :Request failed with response code 405

Please help me how to solve this. Thanks in advance.

Don't use Parse.Cloud.httpRequest to call other cloud functions, instead you should be using Parse.Cloud.run

Your problem could also be related to your headers as you appear to be using string literals instead of variable references.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM