Attention:

We strongly recommend to use the connect-openapi-client with python instead of this SDK.

Overview

Python SDK is a library that simplifies work with Connect APIs and could be found at

Key Features

The library can be consumed in your project in order to automate the fulfillment of requests. Once imported into your project, it will allow you to:

  • Establish connectivity with the API using your api credentials
  • List all requests, and filter them:
    • by the particular Product
    • by the particular Status
  • Retrieve detailed Request representation
  • Modify Request’s properties in order to:
    • Inquiry for additional information
    • Store updated parameter values in the Request
  • Change Request Status (Pending, Inquiring, Failed, Approved)
  • Generate logs
  • Collect debug logs in case of the failure

Your code may use any scheduler to execute, from a simple cron to a cloud scheduler like the ones available in the major cloud providers, like:

and others.

Additionally you may use the webhooks functionality from Connect to instantiate your solution,

Requirements

Installation

We recommend to install using pip:

# pip install connect-sdk

Usage Example

from connect import FulfillmentAutomation
from connect.logger import logger
from connect.models import ActivationTemplateResponse, ActivationTileResponse
from connect.models.exception import FulfillmentFail, FulfillmentInquire, Skip


class ExampleRequestProcessor(FulfillmentAutomation):
    def process_request(self, request):

        # custom logic
        if request.type == 'purchase':
            for item in request.asset.items:
                if item.quantity > 100000:
                    raise FulfillmentFail(
                        message='Is Not possible to purchase product')

            for param in request.asset.params:
                if param.name == 'email' and not param.value:
                    param.value_error = 'Email address has not been provided, please provide one'
                    raise FulfillmentInquire(params=[param])

            # approve by ActivationTile
            return ActivationTileResponse(tile='\n  # Welcome to Fallball!\n\nYes, '
                                               'you decided to have an account in our amazing service!')
            # or
            # return TemplateResource().render(pk='TEMPLATE_ID', request_id=request.id)

            # aprrove by Template
            return ActivationTemplateResponse(template_id="TL-497-535-242")
            # or
            # return TemplateResource().get(pk='TEMPLATE_ID')

        elif request.type == 'change':
            # fail
            raise FulfillmentFail()
        else:
            # skip request
            raise Skip()

if __name__ == '__main__':
    request = ExampleRequestProcessor()
    request.process()

Additional documentation

Additional documentation on how to use the Python SDK for Connect can be found at Read The Docs.

Is this page helpful?
Translate with Google
Copied to clipboard