Creating subcriptions from invoices

Hi, I am trying to create subscriptions using the invoice/create endpoint. This is what the body looks like
{
“merchantId”: merchantId,
“orderId”: orderId,
“orderCurrency”: “USD”,
“userName”: “name”,
“userEmail”: “email@email.com”,
“subscription”: [
{
“amount”: 10.00,
“unit”: 30,
“paymentCount”: 1,
},
{
“amount”: 20.00,
“unit”: 30
}
],
“resetSubscription”: null,
“memo”: “This payment is for order orderId”,
“timeExpire”: null,
“sendEmail”: false,
“postbackUrl”: “myapp.io/api/callback
}
And I am getting this as the response
“errors”: {
“$.subscription”: [
“The JSON value could not be converted to System.String. Path: $.subscription | LineNumber: 7 | BytePositionInLine: 25.”
]
},

Does this have to do with the unit being incorrect? The api says it is a number but I only ever saw references to the atlos.RECURRANCE_MONTH which I can’t use

Hi tee,

There appears to be in error in the documentation. The subscription should in fact be a string. Hence, this error. You should stringify your subscription object and pass it like this:

"subscription": "[{\"amount\": 10,\"unit\": 30,\"paymentCount\": 1},{\"amount\": 20,\"unit\": 30}]",

Also, these are the unit constants:

const recurrenceUnits = {
  NONE: 0,
  DAY: 1,
  WEEK: 2,
  MONTH: 3,
  YEAR: 4,
};
1 Like