I am using the Hackerrank API for a Project. See the official documentation, click here!
There is an example on their website which uses UNIREST,
unirest.post("https://hackerrank-hackerrank.p.rapidapi.com/https://api.hackerrank.com/checker/submission.json") .header("X-RapidAPI-Host", "hackerrank-hackerrank.p.rapidapi.com") .header("X-RapidAPI-Key", "a72a0f1b5dmshdc3f55e233876eap1b8939jsnffad2a5b6e6e") .header("Content-Type", "application/x-www-form-urlencoded") .send("callback_url=https://mywebsite.com/responseHandler") .send("source=puts 'Hello World'") .send("lang=8") .send("testcases=["This is input 1", "This is input 2"]") .send("wait=false") .send("format=json") .end(function (result) { console.log(result.status, result.headers, result.body); }); Since I am using axios, I converted it to an equivalent axios code which looks like:
var params = { "callback_url": "https://mywebsite.com/responseHandler", "source": "puts 'Hello World'", "lang": 8, "testcases": "[\"This is input 1\", \"This is input 2\"]", "wait": false, "format": "json" } var config = { mode: "no-cors", headers: { "X-RapidAPI-Host": "hackerrank-hackerrank.p.rapidapi.com", "X-RapidAPI-Key": "a72a0f1b5dmshdc3f55e233876eap1b8939jsnffad2a5b6e6e", 'Access-Control-Allow-Origin': '*', "Content-Type": "application/x-www-form-urlencoded" } } axios.post("https://hackerrank-hackerrank.p.rapidapi.com/https://api.hackerrank.com/checker/submission.json", params, config) .catch((error) => { console.log(error.message); }) .then((response) => { console.log(response); }) I expect this to work just the example shown in the example, but it gives me the following error:
Request failed with status code 400
Error: Request failed with status code 400
at createError (createError.js:16)
at settle (settle.js:18)
at XMLHttpRequest.handleLoad (xhr.js:77)
I am relatively new to this, if someone can point out what i am doing wrong, that would be very helpful!