How to create a subscription in 'Draft' status?

Reply
Highlighted
bolaurent Master

Master

Master
Posts: 125
Registered: ‎04-10-2016
Accepted Solution

How to create a subscription in 'Draft' status?

[ Edited ]

I need to create subscriptions, via API, in Draft Status.

 

'Status' is not a valid parameter for the REST API Create Subscription endpoint ('/v1/subscriptions'), using zuora-version 211.0.

 

 

{'reasons': [{'code': 53000021, 'message': "Invalid parameter(s): 'status'."}], 'processId': 'AB50D6EB05E0DBBF', 'success': False}

 

I tried '/v1/create/subscription', but I got following message.

 

AssertionError: POST to /action/create/ failed: b'{"message":"Error - invalid object type: subscription"}\n'  

 

bolaurent Master

Master

Master
Posts: 125
Registered: ‎04-10-2016

Re: How to create a subscription in 'Draft' status?

According to the following article (October 2016), Zuora Support Team says this is not possible with REST; the recommendation there is to use SOAP.

 

REST api to create subscription with draft status

 

grrrr.

yamasaki1ma Master

Master

Master
Posts: 58
Registered: ‎02-22-2017

Re: How to create a subscription in 'Draft' status?

Hi @bolaurent

 

This discussion continues in the article you showed, and recently (July, 2017), @vu_phan indicated that this can be achieved with REST's Subscribe call
https://community.zuora.com/t5/Subscriptions/REST-api-to-create-subscription-with-draft-status/td-p/...
In fact, I confirmed that Draft's Subscription was created in this way when this was posted .

 

(I know that Subscribe call exists from the SOAP era. What you want is just to use "Create Subscription"? If so, I can understand your thoughts very much ...!)

kevin_lussie Zuora SME

Zuora SME

Zuora SME
Posts: 7
Registered: ‎01-11-2016

Re: How to create a subscription in 'Draft' status?

[ Edited ]

Hi, 

 

Have you tried the Rest Action for Subscribe?

 

POST: https://rest.apisandbox.zuora.com/v1/action/subscribe

 

 

{
  "subscribes" : [
    {
      "Account": {
        "Id":"2c92c0f8602f9f7c016030df75050de5"
      },
      "SubscribeOptions" : {
        "GenerateInvoice": false
      },
      "SubscriptionData": {
        "Subscription": {
          "InitialTerm": "12",
          "Notes": "My Subscription Notes",
          "RenewalTerm": "12",
          "TermStartDate": "2018-06-05",
          "TermType": "TERMED",
          "IsInvoiceSeparate": "TRUE"
        },
        "RatePlanData": [
          {
            "RatePlan": {
              "ProductRatePlanId": "2c92c0f85a46888b015a490d7d2375a6"
            },
            "RatePlanChargeData" : [
              {
                "RatePlanCharge" : {
                  "ProductRatePlanChargeId" : "2c92c0f85a46888b015a490d7d4175a8"
                }
              }
            ]
          }
        ]
      }
    }
  ]
}

Output:

 

 

[
  {
    "SubscriptionId": "2c92c0f8602f9ebb016030e68381341d",
    "SubscriptionNumber": "A12967--S00000274",
    "AccountId": "2c92c0f8602f9f7c016030df75050de5",
    "Success": true,
    "AccountNumber": "A12967-00000167"
  }
]

 

Zuora.png
bolaurent Master

Master

Master
Posts: 125
Registered: ‎04-10-2016

Re: How to create a subscription in 'Draft' status?

Hooray! This worked for me.

 

For anyone else trying to follow this, I had to remove ContractAcceptanceDate, ContractEffectiveDate, and ServiceActivationDate from the call. When these were present, the subscription was created in Active status.

 

@kevin_lussie, thank you so much for posting the whole payload of your call; it was very helpful.

 

 

chdavid Savvy Scholar

Savvy Scholar

Savvy Scholar
Posts: 3
Registered: ‎08-31-2016

Re: How to create a subscription in 'Draft' status?

And after, what is the call in REST API to update de subscription with the contractn service and acceptance dates ?

 

Maxime Honor Student

Honor Student

Honor Student
Posts: 2
Registered: ‎01-10-2018

Re: How to create a subscription in 'Draft' status?

Hi, 

 

The problem with the Rest Action for Subscribe Is that it will automatically create an account and one subscription.

 

What if I need to create a subscription in "PendingActivation" status for an existing account ?

What if I need to create 2 or 3 subscriptions in "PendingActivation" status at the same time ?

 

Please give me a solution.

 

Maxime

 

bolaurent Master

Master

Master
Posts: 125
Registered: ‎04-10-2016

Re: How to create a subscription in 'Draft' status?

I'm pretty sure that's not accurate, Maxime. I am using the Rest Action for Subscribe to create subscriptions, in pending status, without creating accounts.

 

If you look at the payload that @kevin_lussie shows above, subscribes is an array (there can be multiple subscribes), and Account for the subscribe element he showed was an account id (meaning the account already exists).

bolaurent Master

Master

Master
Posts: 125
Registered: ‎04-10-2016

Re: How to create a subscription in 'Draft' status?

[ Edited ]

Here's my working code (in python, using https://github.com/bolaurent/zuora_restful_python):

 

 
    def deploy(self, subscription_owner_account):
        self.subscribe = {
            'Account': {
                'Id': subscription_owner_account['Id']
            },
            'SubscribeOptions': {
                'GenerateInvoice': False,
                'ProcessPayments': False
            },
            'SubscriptionData': self.subscriptiondata()

        responses = self.zuora.subscribe({
            'subscribes': [self.subscribe]
        })

        for response in responses:
            logger.info(response)

 

Maxime Honor Student

Honor Student

Honor Student
Posts: 2
Registered: ‎01-10-2018

Re: How to create a subscription in 'Draft' status?

Wow thank you very much !

 

To be honest, I was only focus on the online documentation which does not specify the field "Id" that you mentionned, and which even affirm :

Capture.JPG

 

Thanks a lot !