Skip to content

Instantly share code, notes, and snippets.

@romainnorberg
Last active September 4, 2019 04:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romainnorberg/9847a6707a26a77039358d85cce3d7aa to your computer and use it in GitHub Desktop.
Save romainnorberg/9847a6707a26a77039358d85cce3d7aa to your computer and use it in GitHub Desktop.
Work with OVH-Api using Postman Pre-request scripts (Blog post: https://blog.romainnorberg.be/post/work-with-ovh-api-using-postman)
pm.sendRequest({
url: "https://api.ovh.com/1.0/auth/time",
method: "GET",
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
body: {}
},
function (err, res) {
pm.expect(err).to.not.be.ok;
pm.expect(res).to.have.property('code', 200);
pm.expect(res).to.have.property('status', 'OK');
var serverTimestamp = res.text();
postman.setGlobalVariable("lf_ovh_api_app_server_timestamp", serverTimestamp);
var time_delta = serverTimestamp - Math.round(new Date().getTime()/1000);
var now = Math.round(new Date().getTime()/1000) + time_delta;
var body = '';
postman.setGlobalVariable("lf_ovh_api_app_timestamp", now);
var toSign = environment.lf_ovh_api_app_secret + '+' + environment.lf_ovh_api_app_consumer_key + '+' + pm.request.method + '+' + pm.request.url.toString() + '+' + body + '+' + now;
var signature = '$1$' + CryptoJS.SHA1(toSign);
postman.setGlobalVariable("lf_ovh_api_app_consumer_signature", signature);
}
);
curl -X GET \
https://api.ovh.com/1.0/sms \
-H 'Content-Type: application/json; charset=utf-8' \
-H 'X-Ovh-Application: xxxxxx' \
-H 'X-Ovh-Consumer: {{lf_ovh_api_app_consumer_key}}' \
-H 'X-Ovh-Signature: {{lf_ovh_api_app_consumer_signature}}' \
-H 'X-Ovh-Timestamp: {{lf_ovh_api_app_timestamp}}' \
-H 'cache-control: no-cache'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment