BPMN Variable Scopes and Service Task Execution in Camunda HTTP API

Hi everyone,

I’m working with PHP and studying Camunda. I’ve created a simple BPMN, but I’m encountering a problem when starting the process. Two variables are created: one with a global scope and the other with a process scope. I’m passing them in the request "/process-definition/key/$key/start" body like this:

php

[
    "variables" => [
        "number" => [
            "value" => "324341324",
            "type" => "String"
        ]
    ],
    "tenantId" => "laraveltenant",
    "businessKey" => "2100d7e1-ac48-4183-93cf-ebfeda0807e3",
    "withVariablesInReturn" => true
]

My question is: How can I pass a variable that will only be needed for a single service task?

Additionally, all my service tasks are implemented as listeners in my application. As soon as a task with a specific topic name appears, my application immediately starts execution.

I’m wondering if I’ve structured the architecture correctly, and I would appreciate any advice or suggestions. I’m a bit confused about this setup and could use some help. Thanks in advance!

My bpmn

<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1dtovj1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.27.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.21.0">
  <bpmn:signal id="Signal_1sdvvlx" name="Signal_0pnkjgp" />
  <bpmn:collaboration id="Collaboration_0qfxhfj">
    <bpmn:participant id="Participant_17b8kqy" name="Call Center Business process" processRef="IncomingCall" />
  </bpmn:collaboration>
  <bpmn:process id="IncomingCall" name="IncomingCall" isExecutable="true">
    <bpmn:startEvent id="StartEventIncomingCall" name="StartEventIncomingCall">
      <bpmn:extensionElements />
      <bpmn:outgoing>Flow_0hzefzv</bpmn:outgoing>
      <bpmn:signalEventDefinition id="SignalEventDefinition_1221fdi" signalRef="Signal_1sdvvlx" />
    </bpmn:startEvent>
    <bpmn:sequenceFlow id="Flow_0hzefzv" sourceRef="StartEventIncomingCall" targetRef="createCall">
      <bpmn:extensionElements />
    </bpmn:sequenceFlow>
    <bpmn:serviceTask id="createCall" name="createCall" camunda:type="external" camunda:topic="createCall">
      <bpmn:extensionElements>
        <camunda:inputOutput>
          <camunda:inputParameter name="number" />
          <camunda:outputParameter name="callId" />
        </camunda:inputOutput>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_0hzefzv</bpmn:incoming>
      <bpmn:outgoing>Flow_1sbgorz</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:serviceTask id="createClient" name="createClient" camunda:type="external" camunda:topic="createClient">
      <bpmn:extensionElements>
        <camunda:inputOutput>
          <camunda:inputParameter name="callId" />
          <camunda:outputParameter name="clientId" />
        </camunda:inputOutput>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_1sbgorz</bpmn:incoming>
      <bpmn:outgoing>Flow_1439x67</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:sequenceFlow id="Flow_1sbgorz" sourceRef="createCall" targetRef="createClient" />
    <bpmn:sequenceFlow id="Flow_1439x67" sourceRef="createClient" targetRef="Event_0owoj7v" />
    <bpmn:endEvent id="Event_0owoj7v">
      <bpmn:incoming>Flow_1439x67</bpmn:incoming>
    </bpmn:endEvent>
  </bpmn:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_0qfxhfj">
      <bpmndi:BPMNShape id="Participant_17b8kqy_di" bpmnElement="Participant_17b8kqy" isHorizontal="true">
        <dc:Bounds x="160" y="80" width="800" height="420" />
        <bpmndi:BPMNLabel />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="BPMNShape_1j0co1m" bpmnElement="StartEventIncomingCall">
        <dc:Bounds x="272" y="252" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="252" y="295" width="84" height="27" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="BPMNShape_1nm60tv" bpmnElement="createCall">
        <dc:Bounds x="360" y="230" width="100" height="80" />
        <bpmndi:BPMNLabel />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_0evqxel_di" bpmnElement="createClient">
        <dc:Bounds x="520" y="230" width="100" height="80" />
        <bpmndi:BPMNLabel />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_0owoj7v_di" bpmnElement="Event_0owoj7v">
        <dc:Bounds x="672" y="252" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="Flow_0hzefzv_di" bpmnElement="Flow_0hzefzv">
        <di:waypoint x="308" y="270" />
        <di:waypoint x="360" y="270" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1sbgorz_di" bpmnElement="Flow_1sbgorz">
        <di:waypoint x="460" y="270" />
        <di:waypoint x="520" y="270" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1439x67_di" bpmnElement="Flow_1439x67">
        <di:waypoint x="620" y="270" />
        <di:waypoint x="672" y="270" />
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>