Step 1
You have to get your Client ID and Client Secret from your WeSupply Account, located in:
Settings -> Providers -> WeSupply API Credentials
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.
<?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; } ?>
See API docs Get token section for more details: https://documenter.getpostman.com/view/11859344/T17AiAYq#30ca0a2d-df7e-486e-8f47-6776e978ce6a
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 trough commas: orders=ID1,ID2,ID3
<?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; } ?>
See API docs Get WeSupply order links section for more details: https://documenter.getpostman.com/view/11859344/T17AiAYq#f0995f02-67c2-4909-bd67-b8681eb0ce65
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 id’s 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.