Multiple Function Calls in a Single API Request#
The Miva JSON API supports both single function requests as well as multiple function requests in a single call. This gives you the flexibility combine multiple requests into a single API call reducing the number of overall calls needed.
Single Request & Response#
Single Request#
{
"Function": "...",
... request-specific-parameters ...
}
Single Response#
{
"success": 1,
...
}
Multiple Iterations of the Same Function#
This allows you to call the same function multiple times in a single call. An example of this would be updating inventory for multiple products all within a single call.
Multiple Iteration Request#
{
"Function": "...",
... optional parameters that will not change per call ...
"Iterations":
[
{
... pararameters specific to this iteration ...
},
{
... pararameters specific to this iteration ...
},
...
]
}
Multiple Iteration Response#
[
{
"success": 1,
...
},
{
"success": 1,
...
},
...
]
Multiple Separate Function Calls#
Multiple Separate Function Request#
{
"Operations":
[
{
"Function": "xxx",
... request specific parameters ...
},
{
"Function": "xxx",
... request specific parameters ...
},
...
]
}
Multiple Separate Call Response#
[
{
"success": 1,
...
},
{
"success": 1,
...
},
...
]
Combinations#
{
"Operations":
[
{
"Function": "xxx",
... optional parameters that will not change per call ...
"Iterations":
[
{
... pararameters specific to this iteration ...
},
{
... pararameters specific to this iteration ...
},
...
]
},
{
"Function": "xxx",
... optional parameters that will not change per call ...
"Iterations":
[
{
... pararameters specific to this iteration ...
},
{
... pararameters specific to this iteration ...
},
...
]
},
...
]
}
Response:
[
[
{
"success": 1,
...
},
{
"success": 1,
...
}
],
[
{
"success": 1,
...
},
{
"success": 1,
...
}
]
]
Headers#
HTTP_X_MIVA_API_TIMEOUT
#
The default timeout for a single Miva request is 60 seconds. The API supports passing in a custom header that allows you to increase this timeout for your single request. This can be useful if you are sending up bulk product/inventory updates using the multi-call format.
The below example would change the timeout to 100 seconds for that specific request
'X-Miva-API-Timeout': 100
Note
It is much better performance wise to split the number of functions you wish to execute into manageable chunks vs sending a single request with thousands or tens of thousands of function to run. You don’t want a single Miva process running for several minutes.
CONTENT-RANGE
#
The CONTENT-RANGE
response header is only returned when there are multiple operations sent in a single request, ie the multi-call format is being used. If a request is submitted with multiple operations, between each operation Miva will check to see whether a timeout has occurred and if one has, Miva will set the Content-Range
header with how many operations we were able to complete and set the Status of the http response to 206.
If your request gets a response of 206, you have the option of resubmitting the exact same request again but this time with your own request header for “Range” with the Operations you wish to run that did not get run previously because it hit a timeout.
'Content-Range':'3/5', 'Status': 206
The below header would tell Miva to ignore the first 3 functions in the multi-call and only process the 4th and 5th functions.
'Range': 'Operations=4-5'