Consumes a given amount of the specified virtual good.

View interactive version here

Request Parameters

Parameter Required Type Description
quantity Yes number The amount of virtual goods to be consumed
shortCode Yes string The short code of the virtual good to be consumed

Response Parameters

A response to a consume virtual goods response

Parameter Type Description
scriptData ScriptData A JSON Map of any data added either to the Request or the Response by your Cloud Code

Nested types


A collection of arbitrary data that can be added to a message via a Cloud Code script.

Parameter Type Description
myKey string An arbitrary data key
myValue JSON An arbitrary data value.

Error Codes

Key Value Description
qty INSUFFICIENT The player does not have sufficient virtual goods for shortcode specified
authentication NOTAUTHORIZED The player is not authorized to perform the request

Code Samples


    using GameSparks.Api;
    using GameSparks.Api.Requests;
    using GameSparks.Api.Responses;
    new ConsumeVirtualGoodRequest()
        .Send((response) => {
        GSData scriptData = response.ScriptData;

ActionScript 3

    import com.gamesparks.*;
    import com.gamesparks.api.requests.*;
    import com.gamesparks.api.responses.*;
    import com.gamesparks.api.types.*;

        .send(function(response:com.gamesparks.api.responses.ConsumeVirtualGoodResponse):void {
        var scriptData:ScriptData = response.getScriptData(); 


    #import "GS.h"
    #import "GSAPI.h"
    GSConsumeVirtualGoodRequest* request = [[GSConsumeVirtualGoodRequest alloc] init];
    [request setQuantity:quantity;
    [request setShortCode:shortCode;
    [request setCallback:^ (GSConsumeVirtualGoodResponse* response) {
    NSDictionary* scriptData = [response getScriptData]; 
    [gs send:request];


    #include <GameSparks/generated/GSRequests.h>
    using namespace GameSparks::Core;
    using namespace GameSparks::Api::Responses;
    using namespace GameSparks::Api::Requests;

    void ConsumeVirtualGoodRequest_Response(GS& gsInstance, const ConsumeVirtualGoodResponse& response) {
    GSData scriptData = response.getScriptData(); 

    ConsumeVirtualGoodRequest request(gsInstance);


import com.gamesparks.sdk.api.autogen.GSRequestBuilder.ConsumeVirtualGoodRequest;
import com.gamesparks.sdk.api.autogen.GSResponseBuilder.ConsumeVirtualGoodResponse;
import com.gamesparks.sdk.api.autogen.GSTypes.*;
import com.gamesparks.sdk.api.GSEventListener;

    .send(new GSEventListener<ConsumeVirtualGoodResponse>() {
        public void onEvent(ConsumeVirtualGoodResponse response) {

Cloud Code

    var request = new SparkRequests.ConsumeVirtualGoodRequest();
    request.quantity = ...;
    request.shortCode = ...;
    var response = request.Send();

var scriptData = response.scriptData;