API Example - Template Code#
Description#
API Example Via Miva Template Code. Includes both HMAC signature and Timestamp
Snippet#
<mvt:comment>
| Setup data needed for Miva JSON API calls
</mvt:comment>
<mvt:assign name="l.endpoint" value="g.secure_baseurl $ 'json.mvc?'" />
<mvt:assign name="l.access_token" value="'ACCESS_TOKEN'" />
<mvt:assign name="l.signature" value="crypto_base64_decode('SIGNATURE_KEY')" />
<mvt:assign name="l.timestamp" value="'\"Miva_Request_Timestamp\" : ' $ '\"' $ s.time_t $ '\",' " />
<mvt:assign name="l.return" value="'------------------------'" />
<mvt:comment>
| Pass in the JSON body along with signature variable to the crypto_hmac_sha256 function
| Base 64 the HMAC response using the crypto_base64_encode function
| Asssign the headers to the l.header variable
| Make an API call
</mvt:comment>
<mvt:capture variable="l.settings:json_request_data:queue_order_data">
{
<mvt:eval expr="l.timestamp"/>
"Store_Code":"XXX",
"Function":"Module",
"Module_Code":"orderworkflow",
"Module_Function":"QueueOrderList_Load_Query",
"Queue_Code":"XXX",
"Filter":[
{
"name":"ondemandcolumns",
"value":[
"items",
"charges",
"discounts",
"payments",
"notes",
"payment_data"
]
}
]
}
</mvt:capture>
<mvt:assign name="l.ok" value="crypto_hmac_sha256(l.settings:json_request_data:queue_order_data,l.signature,'binary',l.hmac_response)" />
<mvt:assign name="l.b64encoded_hmac_response" value="crypto_base64_encode(l.hmac_response)" />
<mvt:assign name="l.headers" value="'X-Miva-API-Authorization: MIVA-HMAC-SHA256 ' $ l.access_token $ ':' $ l.b64encoded_hmac_response $ asciichar( 13 ) $ asciichar( 10 )" />
<mvt:call action="l.endpoint" method="'RAW'" headers="l.headers" content-type="'application/json'" fields="'l.settings:json_request_data:queue_order_data'">
<mvt:assign name="l.api_response" value="l.api_response $ s.callvalue" />
</mvt:call>
Response: <br>
<textarea rows="20" cols="200">
<mvt:eval expr="l.api_response" />
</textarea>