3

Is there a JSON Schema (or similar) available for the Anaylytics REST API?

I'm looking to generate strongly typed code for parsing the JSON responses. Usually I'd go with SOAP and WSDL based code generation for strongly typed code, but this isn't currently an option with this API.

I did find JSON2Apex and json2csharp but found generating parsing code from sample JSON responses problematic. E.g. the describe call to get the report meta data returns a detailColumnInfo which looks like the following for a particular report:

"detailColumnInfo": {
        "OPPORTUNITY_NAME": {
            "label": "Opportunity Name",
            "dataType": "string"
        },
        "PROBABILITY": {
            "label": "Probability (%)",
            "dataType": "percent"
        },
        "EXP_AMOUNT": {
            "label": "Expected Revenue",
            "dataType": "currency"
        },
        "NEXT_STEP": {
            "label": "Next Step",
            "dataType": "string"
        },
        "BucketField_34840671": {
            "label": "Industry",
            "dataType": "string"
        }
    }

Running this through a code generator creates numerous members specific to the report it was created for. That is, the generated code takes on the specific structure of the sample data rather than the generic meta data structure. E.g.

public class OPPORTUNITY_NAME {
    public String label;
    public String dataType;
}

public class DetailColumnInfo {
    public OPPORTUNITY_NAME OPPORTUNITY_NAME;
    public OPPORTUNITY_NAME PROBABILITY;
    public OPPORTUNITY_NAME EXP_AMOUNT;
    public OPPORTUNITY_NAME NEXT_STEP;
    public OPPORTUNITY_NAME BucketField_34840671;
}

In the above case I needed to manually alter the parsing code to create a Map/Dictionary with keys like "OPPORTUNITY_NAME" and "PROBABILITY" to OPPORTUNITY_NAME objects. This updated parser could adapt to any given report.

It seems a schema describing the web service would be more appropriate to generate the parsing code from as it would communicate dynamic versus fixed structures.

2

Response from Arun V - Product Manager, Analytics @ Salesforce.

There is no schema object but
"detailColumnInfo" can be modelled as Map
DetailColumn: {label, dataType}

Via Twitter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.