Skip to content

Instantly share code, notes, and snippets.

@madiodio
Last active November 28, 2019 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madiodio/3eb7b4746b9c8fbd432bcad10b01ca4e to your computer and use it in GitHub Desktop.
Save madiodio/3eb7b4746b9c8fbd432bcad10b01ca4e to your computer and use it in GitHub Desktop.
const apiUrl = "http://api.paps.sn/api/v1/"
const apiKey = "7090e4f41fd0dd4750b1bab1b0fa563e222aee17272"
const methodName = "getQuotes"
const params = {
origin: "Les Almadies, Dakar, Senegal", // Représente l'origine de la course. Doit être une adresse géocode valide
destionation: "Medina, Dakar, Senegal", // Représente la destination de la course. Doit être une adresse géocode valide
packageSize: "small" // Représente le poids du colis à transporter. Doit être entre les valeurs "small" (S correspond à max 5kg), "medium" (M à max 30 kg), "large" (L à max 60 kg) ou "xLarge" (XL à max 100kg). Visitez la documentation pour bien distinguer pour en savoir plus.
}
const isTest = "test=true"
var esc = encodeURIComponent;
var query = Object.keys(params)
.map(k => esc(k) + '=' + esc(params[k]))
.join('&');
const response = await fetch(`${apiUrl}/${methodName}?${query}&${isTest}`, headers: { 'Content-Type': 'application/json' });
const myJson = await response.json()
console.log(JSON.stringify(myJson));
/*
{
"code": "200",
"message": "Successful",
"data": {
"origin": "Les Almadies, Dakar, Senegal",
"destination": "Medina, Dakar, Senegal",
"legs": [
{
"distance": {
"text": "5.7 km",
"value": 5663
},
"duration": {
"text": "19 mins",
"value": 1120
},
"start_address": "Les Almadies, Dakar, Senegal",
"end_address": "Medina, Dakar, Senegal",
"start_location": {
"lat": 14.7165766,
"lng": -17.467633
},
"end_location": {
"lat": 14.691815,
"lng": -17.4332306
}
}
],
"total_distance": 5663,
"quote": 1000,
"normal_quote": 1000,
"package_size": "small",
"coupon_quote": 0,
"delivery_type": "standard"
}
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment