Cloud

Parse. Cloud

new Cloud()

Contains functions for calling and declaring cloud functions.

Some functions are only available from Cloud Code.

Methods

(static) afterDelete(arg1, func)

Registers an after delete function.

Available in Cloud Code only.

If you want to use afterDelete for a predefined class in the Parse JavaScript SDK (e.g. Parse.User), you should pass the class itself and not the String for arg1.

Parse.Cloud.afterDelete('MyCustomClass', (request) => {
  // code here
})

Parse.Cloud.afterDelete(Parse.User, (request) => {
  // code here
})
Parameters:
Name Type Description
arg1 String | Parse.Object

The Parse.Object subclass to register the after delete function for. This can instead be a String that is the className of the subclass.

func function

The function to run after a delete. This function should take just one parameter, Parse.Cloud.TriggerRequest.

(static) afterSave(arg1, func)

Registers an after save function.

Available in Cloud Code only.

If you want to use afterSave for a predefined class in the Parse JavaScript SDK (e.g. Parse.User), you should pass the class itself and not the String for arg1.

Parse.Cloud.afterSave('MyCustomClass', function(request) {
  // code here
})

Parse.Cloud.afterSave(Parse.User, function(request) {
  // code here
})
Parameters:
Name Type Description
arg1 String | Parse.Object

The Parse.Object subclass to register the after save function for. This can instead be a String that is the className of the subclass.

func function

The function to run after a save. This function should take just one parameter, Parse.Cloud.TriggerRequest.

(static) beforeDelete(arg1, func)

Registers an before delete function.

Available in Cloud Code only.

If you want to use beforeDelete for a predefined class in the Parse JavaScript SDK (e.g. Parse.User), you should pass the class itself and not the String for arg1.

Parse.Cloud.beforeDelete('MyCustomClass', (request, response) => {
  // code here
})

Parse.Cloud.beforeDelete(Parse.User, (request, response) => {
  // code here
})
Parameters:
Name Type Description
arg1 String | Parse.Object

The Parse.Object subclass to register the before delete function for. This can instead be a String that is the className of the subclass.

func function

The function to run before a delete. This function should take two parameters a Parse.Cloud.TriggerRequest and a Parse.Cloud.BeforeDeleteResponse.

(static) beforeSave(arg1, func)

Registers an before save function.

Available in Cloud Code only.

If you want to use beforeSave for a predefined class in the Parse JavaScript SDK (e.g. Parse.User), you should pass the class itself and not the String for arg1.

Parse.Cloud.beforeSave('MyCustomClass', (request, response) => {
  // code here
})

Parse.Cloud.beforeSave(Parse.User, (request, response) => {
  // code here
})
Parameters:
Name Type Description
arg1 String | Parse.Object

The Parse.Object subclass to register the after save function for. This can instead be a String that is the className of the subclass.

func function

The function to run before a save. This function should take two parameters a Parse.Cloud.TriggerRequest and a Parse.Cloud.BeforeSaveResponse.

(static) define(name, data)

Defines a Cloud Function.

Available in Cloud Code only.

Parameters:
Name Type Description
name String

The name of the Cloud Function

data function

The Cloud Function to register. This function should take two parameters a Parse.Cloud.FunctionRequest and a Parse.Cloud.FunctionResponse

(static) httpRequest(options) → {Parse.Promise.<Parse.Cloud.HTTPResponse>}

Makes an HTTP Request.

Available in Cloud Code only.

By default, Parse.Cloud.httpRequest does not follow redirects caused by HTTP 3xx response codes. You can use the followRedirects option in the Parse.Cloud.HTTPOptions object to change this behavior.

Sample request:

Parse.Cloud.httpRequest({
  url: 'http://www.parse.com/'
}).then(function(httpResponse) {
  // success
  console.log(httpResponse.text);
},function(httpResponse) {
  // error
  console.error('Request failed with response code ' + httpResponse.status);
});
Parameters:
Name Type Description
options Parse.Cloud.HTTPOptions

The Parse.Cloud.HTTPOptions object that makes the request.

Returns:
Type:
Parse.Promise.<Parse.Cloud.HTTPResponse>

A promise that will be resolved with a Parse.Cloud.HTTPResponse object when the request completes.

(static) job(name, func)

Defines a Background Job.

Available in Cloud Code only.

Parameters:
Name Type Description
name String

The name of the Background Job

func function

The Background Job to register. This function should take two parameters a Parse.Cloud.JobRequest and a Parse.Cloud.JobStatus

(static) run(name, data, options) → {Parse.Promise}

Makes a call to a cloud function.

Parameters:
Name Type Description
name String

The function name.

data Object

The parameters to send to the cloud function.

options Object

A Backbone-style options object options.success, if set, should be a function to handle a successful call to a cloud function. options.error should be a function that handles an error running the cloud function. Both functions are optional. Both functions take a single argument.

Returns:
Type:
Parse.Promise

A promise that will be resolved with the result of the function.

Type Definitions

BeforeDeleteResponse

Properties:
Name Type Description
success function

If called, will allow the delete to happen.

error function

If called, will reject the save. An optional error message may be passed in.

BeforeSaveResponse

Properties:
Name Type Description
success function

If called, will allow the save to happen. If a Parse.Object is passed in, then the passed in object will be saved instead.

error function

If called, will reject the save. An optional error message may be passed in.

FunctionRequest

Properties:
Name Type Description
installationId String

If set, the installationId triggering the request.

master Boolean

If true, means the master key was used.

user Parse.User

If set, the user that made the request.

params Object

The params passed to the cloud function.

FunctionResponse

Properties:
Name Type Description
success function

If success is called, will return a successful response with the optional argument to the caller.

error function

If error is called, will return an error response with an optionally passed message.

HTTPOptions

Properties:
Name Type Description
body String | Object

The body of the request. If it is a JSON object, then the Content-Type set in the headers must be application/x-www-form-urlencoded or application/json. You can also set this to a Buffer object to send raw bytes. If you use a Buffer, you should also set the Content-Type header explicitly to describe what these bytes represent.

error function

The function that is called when the request fails. It will be passed a Parse.Cloud.HTTPResponse object.

followRedirects Boolean

Whether to follow redirects caused by HTTP 3xx responses. Defaults to false.

headers Object

The headers for the request.

method String

The method of the request. GET, POST, PUT, DELETE, HEAD, and OPTIONS are supported. Will default to GET if not specified.

params String | Object

The query portion of the url. You can pass a JSON object of key value pairs like params: {q : 'Sean Plott'} or a raw string like params:q=Sean Plott.

success function

The function that is called when the request successfully completes. It will be passed a Parse.Cloud.HTTPResponse object.

url string

The url to send the request to.

HTTPResponse

Properties:
Name Type Description
buffer Buffer

The raw byte representation of the response body. Use this to receive binary data. See Buffer for more details.

cookies Object

The cookies sent by the server. The keys in this object are the names of the cookies. The values are Parse.Cloud.Cookie objects.

data Object

The parsed response body as a JavaScript object. This is only available when the response Content-Type is application/x-www-form-urlencoded or application/json.

headers Object

The headers sent by the server. The keys in this object are the names of the headers. We do not support multiple response headers with the same name. In the common case of Set-Cookie headers, please use the cookies field instead.

status Number

The status code.

text String

The raw text representation of the response body.

JobRequest

Properties:
Name Type Description
params Object

The params passed to the background job.

JobStatus

Properties:
Name Type Description
error function

If error is called, will end the job unsuccessfully with an optional completion message to be stored in the job status.

message function

If message is called with a string argument, will update the current message to be stored in the job status.

success function

If success is called, will end the job successfullly with the optional completion message to be stored in the job status.

TriggerRequest

Properties:
Name Type Description
installationId String

If set, the installationId triggering the request.

master Boolean

If true, means the master key was used.

user Parse.User

If set, the user that made the request.

object Parse.Object

The object triggering the hook.

ip String

The IP address of the client making the request.

headers Object

The original HTTP headers for the request.

triggerName String

The name of the trigger (beforeSave, afterSave, ...)

log Object

The current logger inside Parse Server.

original Parse.Object

If set, the object, as currently stored.