When using WeSupply, you can replace the original My Account Order Links from your system, with the ones generated by the WeSupply API. To get the Order Links of the orders imported in WeSupply you just need to use your account credentials to get a token that can be used to get the links of each order. An example using PHP is detailed below. Feel free to change it per your needs or for a different programming language.
Step 1
You have to get your Client ID and Client Secret from your WeSupply Account, located in:
Settings -> Integrations -> Webhooks and API:
Step 2
You have to make a call to generate a token based on the above credentials, further to be used with the WeSupply API.
See API docs Get token section for more details: https://documenter.getpostman.com/view/11859344/T17AiAYq#30ca0a2d-df7e-486e-8f47-6776e978ce6a
<?php $url = "https://wesupply_client_url/api/oauth/token"; $clienttoken_post = array( "grant_type" => "client_credentials", "client_id" => 'your_client_id', "client_secret" => 'your_client_secret' ); $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => http_build_query($clienttoken_post), CURLOPT_HTTPHEADER => array( "cache-control: no-cache", "content-type: application/x-www-form-urlencoded" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } ?>
If everything is ok, you will receive the access token in a JSON response format:
{
"access_token":"03a769b3147c7974ca",
"token_type":"Bearer",
"expires_in":3599,
"scope":"*"
}
Step 3
With the above access token, you make one more call to authLinks URL, passing also the Order External ID(s) as a param separated through commas: orders=ID1,ID2,ID3
See API docs Order Links section for more details: https://documenter.getpostman.com/view/11859344/T17AiAYq#f0995f02-67c2-4909-bd67-b8681eb0ce65
<?php $accesToken = 'previously_generated' $externalOrderIdString = '00000001,0000002,0000003'; $params = array("orders"=>$externalOrderIdString); $buildQuery = http_build_query($params); $url = 'http://wesupply_client_url/api/authLinks?'.$buildQuery; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_FOLLOWLOCATION => TRUE, CURLOPT_HTTPHEADER => array("Authorization: Bearer $accesToken") )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } ?>
If everything went ok, you should receive a JSON object response as follows:
“order_id_1” : “link1”,
“order_id_2” : “link2”,
...
“order_id_N” : “linkN”
If one of the requested order IDs does not exist yet in WeSupply, then it will not appear in the response. Response example:
{
"ID1":"http://wesupply_client_url/vieworder?k=W%2BEK...KeKccfy",
"ID2":"http://wesupply_client_url/vieworder?k=RR4weT...5iuvJ9QKW2","ID3":"http://wesupply_client_url/vieworder?k=0%2B1t...KpqbJBW%2FP2D"
}
Note: It is recommended to implement a logic where if the order cannot be found in WeSupply (the API does not return anything) to maintain the original My account view order URL.
Comments
0 comments
Please sign in to leave a comment.