Best way to call python app apis inside of the camunda bpmn

Hello,

I am a newbie to Camunda’s BPMN, so I have a lot of questions.

I am currently working on python rest APIs and would like to call those APIs inside of the BPMN.
It should be called through requests.
But, if I use http-connector to call APIs, it gives me error. {“type”:“ConnectorRequestException”,“message”:“HTCL-02007 Unable to execute HTTP request”}

and I have no idea how to do http call inside of the external task.

Would you please share any tutorials or documentation that I could figure out?

I’ve watched this video - { "External Client" : { "REST": true, "Language": "*"}} (CamundaCon 2019) - YouTube
But I couldn’t get the idea of how I could call the external python rest API inside of the external task or http-connector.

I am using pycamunda package. Please recommend any other python camunda packages.

Best Regards,

I think @Nele would be the perfect person to help answer this question

Hey @annna ,

If you use a REST client like PyCamunda the HTTP connector implementation is not the right one to choose. You need to implement your Services as External Tasks and match the topic name to your External task workers.

Could you share your bpmn model and your code? This way it is easier to see what exactly is missing :slight_smile:

Kind regards
Nele

Hello @Niall and @Nele,

Thanks for answering.

Please find out the attached bpmn below.
external-ping.bpmn (2.7 KB)

I am still trying to figure out the external task, so my code could be wrong.

def get_resource_ping(uri):
    url = 'http://127.0.0.1:5620/v1/ping'
    psession = requests.Session()
    psession.trust_env = False
    psession.verify = False
    response = psession.get(url)
    result = response.json()
    return result

if __name__ == "__main__":
    url = 'http://127.0.0.1:7150/engine-rest'
    worker_id='extservice_test'
    start_instance = pycamunda.processdef.StartInstance(url=url, key=worker_id)
    start_instance.add_variable('input', '123')
    process_instance = start_instance()
    variables=['input']
    fetch_and_lock = pycamunda.externaltask.FetchAndLock(url=url, worker_id=worker_id, max_tasks=1)
    fetch_and_lock.add_topic(name='Ping', lock_duration=10000, variables=variables)
    tasks = fetch_and_lock()

    for task in tasks:
        result = get_resource_ping(start_instance.variables['input'])
        complete = pycamunda.externaltask.Complete(url=url, id_=task.id_, worker_id=worker_id)
        complete.add_variable(name='result', value=result)  # Send this variable to the instance
        complete()
  1. Can I call the my service api after fetch_and_lock?
  2. I would like to add result from my service api on the external task as a output, not the process, how can I do that?
  3. when I print the complete at bottom of the code, I could see this log.
Complete(url='http://127.0.0.1:7150/engine-rest/external-task/50331577-e769-11ec-a706-0242ac110002/complete', id_='50331577-e769-11ec-a706-0242ac110002', worker_id='extservice_test', variables={'result': {'value': {'result': 'pong'}, 'type': None, 'valueInfo': None}}, local_variables={})

But, in the cockpick, the number ‘1’ on the task is not disappeared. I am wondering if it is right to call complete.

Thanks for your help.

Best Regards,
annna