Api key provided on integrations tab in Easyflow platform.
Create subscription
Creates a subscription without an offer and charges its first recurrence on the buyer's credit card.
- Tokenize the card with the Easyflow JavaScript SDK and send the token in
creditCard.token. The token goes only in this request: no response and no webhook returns it. The next recurrences are charged to the card saved in the subscription, without a new token. - The API key must have write access to subscriptions, and its user must be a collaborator of the business sent in
business-id. - Every recurrence charges
valueInCents, the first one included. The first recurrence is charged by an order created with the subscription. ItsorderIdcomes in the response. - The subscription starts as
inactive. It becomesactivewhen the first order is paid. If the first order is refused, the subscription iscanceledand no other recurrence is charged. The response can already bringcanceled, and a retry with the sameidempotency-keybrings the current status, which can beactive.
Idempotency:
- Send the
idempotency-keyheader in every request. Retrying with the same key and the same body returns the same subscription and never charges twice. - The body is compared after removing fields with
nullvalues.buyer.deviceis not compared,buyer.emailis compared in lowercase, and the card token is part of the comparison. The same key with a different body returns409. - While another request with the same key is still running, the API returns
409. Retry later with the same key and body. - After a
500, or a422witherrorCodeSUBSCRIPTION_CARD_PAYMENT_SERVICE_UNAVAILABLE, retry with the same key and body. - When the card is refused (any other
errorCodein422), every retry with that key returns the same422. To try another card, use a new key.
Metadata:
- The items of
metadataare copied to the first order. Easyflow also writes the keyssubscription-creation-request-id,subscription-terms,ip,fingerprint-idanduser-agentto that order, so these keys are reserved.subscription-termsholds, as a JSON string, thename,valueInCents,periodicity,numberRecurrences,repeatIndefinitely,retryandinvoiceDescriptionof the subscription. Sending one of them (compared without leading and trailing spaces and ignoring case) returns400withInvalid param: [metadata].
Split with other businesses:
commissionedParticipantsis optional. Send it to split the subscription with other businesses. Each item has thecommissionedIdof a business that receives a part, and exactly one ofcommissionedValueInCents(a fixed value, in cents) andcommissionedPercentage(a percentage).- The participants receive their part in every recurrence, the first one included, with the same value or percentage sent at creation. The business sent in
business-id, which owns the subscription, receives the rest. - The sum of the fixed values and of the percentages applied to
valueInCentscannot exceed 60% ofvalueInCents. For example, withvalueInCentsequal to4990, the parts can add up to2994. In the request example, two businesses other than the owner receive a part: one receives 10% and the other a fixed500, which add up to999. The amount paid to each business in a recurrence is calculated by Easyflow with the same split rules used for orders. - The participants cannot be changed after the subscription is created. The API has no endpoint to add, remove or change them.
- The response and Get subscription do not return the participants. The subscription webhook lists in
participants, and the order webhook lists in theparticipantsof each item, only theidandnameof each business, without its part. - Invalid participants are refused with
400before theidempotency-keyis used, so you can fix the body and retry with the same key. The messages are listed in the400response.
Limits:
- Up to 30 requests per minute for each user (all API keys of the same user share the limit). Above that, the API returns
429with theRetry-Afterheader.
Headers
x-api-keystringrequiredx-api-secretstringrequiredApi Secret provided on integrations tab in Easyflow platform.
business-idstringrequiredIdentifier of the business the request refers to. The user of your API key must be linked to this business, as explained in The business identifier. A value that is not a business identifier returns
400withInvalid param: [businessId], and a business that the user is not linked to returns403.idempotency-keystringrequiredKey chosen by you that identifies the request. Send the same key when you retry the same request. It must have 1 to 255 characters after leading and trailing spaces are removed.
Request bodyrequired
Content typeapplication/jsonobject
namestringrequiredName of the subscription. It is also the description of the item of the first order. It cannot be empty or contain only spaces.
valueInCentsintegerrequiredValue charged in every recurrence, the first one included, in cents. It must be equal to or greater than the minimum charge value of the platform (by default, 1000).
periodicitystringrequiredInterval between recurrences.
repeatIndefinitelybooleanrequiredWhen
true, the subscription has no end andnumberRecurrencesmust be omitted,nullor0.numberRecurrencesintegernullableTotal number of recurrences, the first one included. Required, as an integer from 1 to 1200, when
repeatIndefinitelyisfalse. WhenrepeatIndefinitelyistrue, omit it or sendnullor0.retryobjectHow Easyflow retries a failed recurrence. When omitted, it makes 5 attempts every 3 days. When sent, it must be an object (otherwise the API returns
400withInvalid param: [retry]) and both fields are required.Show child attributesHide child attributes
retriesMaxNumberintegerrequiredMaximum number of attempts.
intervalInDaysintegerrequiredDays between attempts.
buyerobjectrequiredBuyer who pays the subscription.
Show child attributesHide child attributes
namestringrequiredemailstringrequiredE-mail of the buyer. It is stored in lowercase.
phoneobjectrequiredShow child attributesHide child attributes
areaCodestringCountry code with
+, such as+55.dddstringArea code with 2 digits, such as
11.numberstringPhone number with 8 or 9 digits.
isMobileboolean
documentobjectrequiredShow child attributesHide child attributes
typestringnumberstringDocument number with digits only.
addressobjectShow child attributesHide child attributes
zipCodestringZip code with digits only, such as
01310100.streetstringnumberstringcomplementstringneighborhoodstringcitystringstatestringState code with 2 letters, such as
SP.
deliveryAddressobjectShow child attributesHide child attributes
zipCodestringZip code with digits only, such as
01310100.streetstringnumberstringcomplementstringneighborhoodstringcitystringstatestringState code with 2 letters, such as
SP.
deviceobjectrequiredDevice of the buyer, sent with the card. When the subscription is created, it is also written to the metadata of the first order.
Show child attributesHide child attributes
ipstringrequiredIP address of the buyer. Never send the IP address of your server.
fingerprintIdstringrequiredFingerprint of the device of the buyer.
userAgentstringrequiredUser agent of the browser of the buyer.
creditCardobjectrequiredCredit card of the buyer. The card number is sent only inside
token, created with the Easyflow JavaScript SDK.Show child attributesHide child attributes
tokenstringrequiredEncrypted card token returned by the Easyflow JavaScript SDK. Sent only in this request. No response and no webhook returns it.
last4NumbersstringrequiredLast 4 digits of the card.
holderNamestringrequiredName printed on the card.
expiresAtMonthintegerrequiredExpiration month of the card.
expiresAtYearintegerrequiredExpiration year of the card.
flagstringrequiredCard brand.
commissionedParticipantsarray of objectsOptional. Businesses that receive a part of every recurrence, the first one included. The business sent in
business-idreceives the rest. The sum of the fixed values and of the percentages applied tovalueInCentscannot exceed 60% ofvalueInCents; otherwise the API returns400withInvalid param: [commissionedParticipants.commission]. When sent, it must be a list of objects; otherwise the API returns400withInvalid param: [commissionedParticipants]. The participants cannot be changed after the subscription is created.Show child attributesHide child attributes
commissionedIdstring · uuidrequiredID of the business that receives this part. When it is missing or is not a valid ID, the API returns
400withInvalid param: [commissionedId]. When no business has this ID, the API returns400withInvalid param: [invalid commissionedId: <id>].commissionedValueInCentsintegernullableFixed part of each recurrence, in cents. It must be an integer equal to or greater than 1; otherwise the API returns
400withInvalid param: [commissionedParticipants.commissionedValueInCents].commissionedPercentagenumbernullablePart of each recurrence as a percentage, such as
10for 10%. It must be a number greater than 0 and can have decimals; otherwise the API returns400withInvalid param: [commissionedParticipants.commissionedPercentage]. For the 60% limit, it is applied tovalueInCents.
invoiceDescriptionstringText shown on the card statement of the buyer. When omitted, Easyflow derives it from
name. When it is not a string, the API returns400withInvalid param: [invoiceDescription].metadataarray of objectsYour own key and value pairs, copied to the first order. The keys
subscription-creation-request-id,subscription-terms,ip,fingerprint-idanduser-agentare reserved. Whenmetadatais not a list, an item does not havekeyandvalueas strings, or a key is reserved, the API returns400withInvalid param: [metadata].Show child attributesHide child attributes
keystringrequiredvaluestringrequired
Responses
200The subscription was created, or a retry with the same idempotency-key and body found it.
The subscription was created, or a retry with the same idempotency-key and body found it.
Content typeapplication/jsonobject
statusCodeintegerdataobjectShow child attributesHide child attributes
subscriptionIdstring · uuidID of the subscription.
orderIdstring · uuidID of the order that charges the first recurrence.
statusstringStatus of the subscription. It is
inactiveuntil the first order is paid andcanceledwhen the first order is refused.
400A field or header is missing or invalid. The message names it, such as Missing param: [idempotency-key], Missing param: [numberRecurrences], Invalid param: [repeatIndefinitely], Invalid param: [numberRecurrences], Invalid param: [retry] or Invalid param: [retry.intervalInDays].
A field or header is missing or invalid. The message names it, such as Missing param: [idempotency-key], Missing param: [numberRecurrences], Invalid param: [repeatIndefinitely], Invalid param: [numberRecurrences], Invalid param: [retry] or Invalid param: [retry.intervalInDays].
Messages about commissionedParticipants:
Invalid param: [commissionedParticipants]: it is not a list, or one of its items is not an object.Invalid param: [commissionedParticipants.commission]: an item has none or both ofcommissionedValueInCentsandcommissionedPercentage, or the sum of the parts exceeds 60% ofvalueInCents.Invalid param: [commissionedParticipants.commissionedValueInCents]: the fixed value is not an integer equal to or greater than 1.Invalid param: [commissionedParticipants.commissionedPercentage]: the percentage is not a number greater than 0.Invalid param: [commissionedId]: thecommissionedIdof an item is missing or is not a valid ID.Invalid param: [invalid commissionedId: <id>]: no business has this ID.<id>is the value you sent.
The errors listed here are returned before the idempotency-key is used, so you can fix the body and retry with the same key.
Content typeapplication/jsonobject
messagestringInvalid param: []
errorstringBad Request
statusCodeinteger400
errorCodestringCode that identifies the error. Present only on some errors.
401The credential is missing or invalid, or the business-id header is missing (message BusinessId is required).
The credential is missing or invalid, or the business-id header is missing (message BusinessId is required).
Content typeapplication/jsonobject
messagestringInvalid field
errorstringUnauthorized
statusCodeinteger401
403The API key has no write access to subscriptions, or its user is not a collaborator of the business sent in business-id.
The API key has no write access to subscriptions, or its user is not a collaborator of the business sent in business-id.
Content typeapplication/jsonobject
messagestringForbidden resource
errorstringForbidden
statusCodeinteger403
409The idempotency-key was already used with a different body (message idempotency-key already used with a different payload), or a request with this key is still running (message subscription creation in progress, retry later with the same idempotency-key).
The idempotency-key was already used with a different body (message idempotency-key already used with a different payload), or a request with this key is still running (message subscription creation in progress, retry later with the same idempotency-key).
Content typeapplication/jsonobject
statusCodeintegerrequiredHTTP status code.
messagestringrequiredExplanation of the error.
errorstringName of the HTTP status, such as
Bad RequestorConflict.errorCodestringCode that identifies the error. Present only on some errors.
422The card could not be used. The errorCode field tells why: SUBSCRIPTIONCARDINVALIDCARDTOKEN, SUBSCRIPTIONCARDCUSTOMERNOTFOUND, SUBSCRIPTIONCARDDATAUNREADABLE or SUBSCRIPTIONCARDREJECTED (the card was refused and the key returns the same error on every retry), or SUBSCRIPTIONCARDPAYMENTSERVICEUNAVAILABLE (temporary failure; retry with the same key and body).
The card could not be used. The errorCode field tells why: SUBSCRIPTION_CARD_INVALID_CARD_TOKEN, SUBSCRIPTION_CARD_CUSTOMER_NOT_FOUND, SUBSCRIPTION_CARD_DATA_UNREADABLE or SUBSCRIPTION_CARD_REJECTED (the card was refused and the key returns the same error on every retry), or SUBSCRIPTION_CARD_PAYMENT_SERVICE_UNAVAILABLE (temporary failure; retry with the same key and body).
Content typeapplication/jsonobject
statusCodeintegerrequiredHTTP status code.
messagestringrequiredExplanation of the error.
errorstringName of the HTTP status, such as
Bad RequestorConflict.errorCodestringCode that identifies the error. Present only on some errors.
429More than 30 requests in a minute for the user (all API keys of the same user share the limit). The message is Too many requests, retry after the Retry-After seconds. Wait the number of seconds in the Retry-After header before sending a new request.
More than 30 requests in a minute for the user (all API keys of the same user share the limit). The message is Too many requests, retry after the Retry-After seconds. Wait the number of seconds in the Retry-After header before sending a new request.
Content typeapplication/jsonobject
statusCodeintegerHTTP status code.
messagestringExplanation of the error.
500An unexpected error occurred. Retry with the same idempotency-key and body: the request continues from where it stopped and never charges twice.
An unexpected error occurred. Retry with the same idempotency-key and body: the request continues from where it stopped and never charges twice.
Content typeapplication/jsonobject
statusCodeintegerHTTP status code.
messagestringExplanation of the error.