2. Creating a case
For each step, get the global variable definitions
In the previous step, we retrieved a product iteration, including the step definitions. Now we’re going to use these definitions to figure out the additional parameters the cases need to be created successfully.
- Products can have parameters, they are called
global variables - These global variables are used to generate custom forms in the Portal, one per product. These forms are usually manually filled when creating a case from the Portal, but here we’re going to automate it.
Where to find them
Let’s see where we can find the global variable definitions. Here’s an extract of a product iteration. There are two possible versions for backward compatibility reasons.
|
|
|
|
You must support both style of global variables, a product iteration can contain steps which uses old and new style, depending on when the step’s component was created.
Here is some python pseudo-code to illustrate how to access all global variable definitions:
|
|
What do they contain?
Now that we know where to find the list of global variable defintions, we can look at one example of a global variable defintion.
|
|
The three most important parts are the
- Its interaction: Whether is a
ManualorAutomaticvariable. - Its label: it is what the system uses to identify the variable. The
other attribute
titleis a more user-friendly name that is shown when building a form to fill the variable’s values in the Portal. - Its type.
You only need to provide the values for the Manual variables, the
Automatic variables are automatically filled by the system.
Taking the snippet “to access all global variable definitions”:
|
|
Building the request to create a case
To create the case, you need to make an HTTP POST request with
multipart form data to the path /v1/orders-tracking (remember:
cases in the Portal are called order-tracking in the API).
There are two required parameters:
- the product iteration, named
products, because of backward compatibilty - the list of options for each step, each named
options[]
And one optional parameter:
- the reference id, named
referenceId, which is used by our client to link the cases to their management systems
Here is one example of an options[], it is a JSON-encoded string
that specifies the options (global variables) for which step
(stepOrder) and then provides a value for each options. In this
example, we set the boolean global variable named “Left” for step 1,
to true.
|
|
Finally, the requests must also contain the input scan file.
Here is some python pseudo-code to build the right request:
|
|
To see how options was built and how this snippet fits with the rest
of the workflow, see the function create_case in the full example
script
Start the case
Once you have created the case you need to start the processing. To do
so, you need to make a HTTP PATCH request to
/v1/orders-tracking/{case_id} to change the first step’s status to
Start Process.
|
|