Validation error recording usage for a subscription

98 views
Skip to first unread message

duby.s...@cottageindustries.build

unread,
Sep 11, 2018, 5:30:35 AM9/11/18
to Kill Bill users mailing-list

Hello there,

I ran across a possible validation error when recording usage billing that I'd appreciate assistance troubleshooting.

When I execute a curl to "Record usage for a subscription" with

POST/1.0/kb/usages

{
  "subscriptionId": "1fc44f4d-ce95-4890-81bf-910b354c74a2",
  "unitUsageRecords": [
    {
      "unitType": "killowatt-hours-solar",
      "usageRecords": [
        {
          "recordDate": 2019-10-19",
          "amount": 677.13
        }
      ]
    }
  ]
}

I get the following error in the response body:

{
  "className": "com.fasterxml.jackson.databind.JsonMappingException",
  "code": null,
  "message": "Unexpected character ('-' (code 45)): was expecting comma to separate OBJECT entries\n at [Source: org.apache.catalina.connector.CoyoteInputStream@70af675; line: 8, column: 30] (through reference chain: org.killbill.billing.jaxrs.json.SubscriptionUsageRecordJson[\"unitUsageRecords\"]->java.util.ArrayList[0]->org.killbill.billing.jaxrs.json.UnitUsageRecordJson[\"usageRecords\"]->java.util.ArrayList[0])",
  "causeClassName": "com.fasterxml.jackson.core.JsonParseException",
  "causeMessage": "Unexpected character ('-' (code 45)): was expecting comma to separate OBJECT entries\n at [Source: org.apache.catalina.connector.CoyoteInputStream@70af675; line: 8, column: 30]",
  "stackTrace": []
}

I was expecting the `unitType` to be what I named/defined in the catalog. Is that incorrect?

I have been having some difficulty finding the specific format / validation for fields like the `recordDate` and `amount`. Could you point me to where I can find `$date`, `$uuid`, `$int64`, and such defined?

Also, could you point me to where in the documentation the "TrackingId" of a usage record is defined or generated? It did not seem to be required, but is this a correct assumption?


Thanks for your help,
Savannah


Pierre-Alexandre Meyer

unread,
Sep 11, 2018, 10:06:49 AM9/11/18
to Savannah Duby, Kill Bill users mailing-list
On Tue, Sep 11, 2018 at 10:30 AM, <duby.s...@cottageindustries.build> wrote:
{
  "className": "com.fasterxml.jackson.databind.JsonMappingException",
  "code": null,
  "message": "Unexpected character ('-' (code 45)): was expecting comma to separate OBJECT entries\n at [Source: org.apache.catalina.connector.CoyoteInputStream@70af675; line: 8, column: 30] (through reference chain: org.killbill.billing.jaxrs.json.SubscriptionUsageRecordJson[\"unitUsageRecords\"]->java.util.ArrayList[0]->org.killbill.billing.jaxrs.json.UnitUsageRecordJson[\"usageRecords\"]->java.util.ArrayList[0])",
  "causeClassName": "com.fasterxml.jackson.core.JsonParseException",
  "causeMessage": "Unexpected character ('-' (code 45)): was expecting comma to separate OBJECT entries\n at [Source: org.apache.catalina.connector.CoyoteInputStream@70af675; line: 8, column: 30]",
  "stackTrace": []
}

This means the JSON you are sending is invalid. For reference, the corresponding Java model is: https://github.com/killbill/killbill/blob/master/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/SubscriptionUsageRecordJson.java.

I have been having some difficulty finding the specific format / validation for fields like the `recordDate` and `amount`. Could you point me to where I can find `$date`, `$uuid`, `$int64`, and such defined?

The source of truth is the Java models (see link above). But the easiest would be to use one of our official clients (Java/Ruby/Python/Go -- see https://killbill.github.io/slate/).

Also, could you point me to where in the documentation the "TrackingId" of a usage record is defined or generated? It did not seem to be required, but is this a correct assumption?

Yes, this is not required. It is an advanced feature for companies with strict reconciliation requirements.

Hope that helps,

--
Pierre
Message has been deleted

duby.s...@cottageindustries.build

unread,
Sep 11, 2018, 2:28:29 PM9/11/18
to Kill Bill users mailing-list
Hi Pierre,

Thanks for sharing that reference.
I found that I was missing an opening quote on the date.

I'm now getting a Null Pointer Exception.
Could you clarify if the subscriptionId is the uuid generated for a subscription bundle?

Below are the json response via the kb api. Attached are the kibana logs and an up to date kpm diagnostic.

Thanks for your help,
Savannah

    {
      "className": "java.lang.NullPointerException",
      "code": null,
      "message": null,
      "causeClassName": null,
      "causeMessage": null,
      "stackTrace": []
killbill-diagnostics-09-11-18.zip
nullPointerUsage.png

Pierre-Alexandre Meyer

unread,
Sep 12, 2018, 4:19:39 AM9/12/18
to Savannah Duby, Kill Bill users mailing-list
On Tue, Sep 11, 2018 at 7:28 PM, <duby.s...@cottageindustries.build> wrote:
I'm now getting a Null Pointer Exception.
Could you clarify if the subscriptionId is the uuid generated for a subscription bundle?

A bundle has one or many subscriptions. Both the bundle and the individual subscriptions have their own ids. Usage is always recorded against a subscription, see https://github.com/killbill/killbill/blob/50f749fd985d4a75f77d278be4ef36e85c558e90/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/SubscriptionUsageRecordJson.java#L41.

I'd suggest taking a look at our integration tests in more details, so you have a clear idea how the usage system works. This tutorial might be useful too: http://docs.killbill.io/0.20/consumable_in_arrear.html

    {
      "className": "java.lang.NullPointerException",
      "code": null,
      "message": null,
      "causeClassName": null,
      "causeMessage": null,
      "stackTrace": []
    }

ProTip™: passing withStackTrace=true as a query parameter will expand the full stacktrace. This could help for debugging.

Hope that helps,

--
Pierre

duby.s...@cottageindustries.build

unread,
Sep 12, 2018, 8:30:57 AM9/12/18
to Kill Bill users mailing-list
Thanks Pierre for clarifying and for the pro-tip.
Will work on integration tests next.

Best,
Savannah
Reply all
Reply to author
Forward
0 new messages