Why is my JavaScript API call returning a 400 error?










1















I have an API call that is receiving the "Failed to load Resource" 400 error. I have tried deleting cookies and cache and using a different browser. I also removed an image when I saw that image size could be the issue. I read about the need for HTTP headers, but did not understand where that would go in my code or what it would look like. Any assistance would be greatly appreciated! Here is my JS:



 const app = document.getElementById('root');

const container = document.createElement('div');
container.setAttribute('class', 'container');

app.appendChild(container);

var request = new XMLHttpRequest();
request.open('GET', 'https://www.themuse.com/api/public/jobs', true);
request.onload = function ()

// Begin accessing JSON data here
var data = JSON.parse(this.response);
if (request.status >= 200 && request.status < 400)
data.forEach(job =>
const card = document.createElement('div');
card.setAttribute('class', 'card');

const h1 = document.createElement('h1');
h1.textContent = job.title;

const p = document.createElement('p');
job.description = job.description.substring(0, 300);
p.textContent = `$job.description...`;

container.appendChild(card);
card.appendChild(h1);
card.appendChild(p);
);
else
const errorMessage = document.createElement('marquee');
errorMessage.textContent = `Darn, it's not working!`;
app.appendChild(errorMessage);



request.send();









share|improve this question

















  • 1





    The error is Not a valid argument for 'page', is the API being used correctly?

    – Hodrobond
    Nov 15 '18 at 22:39











  • themuse.com/developers/api/v2 On the docs for that endpoint it says the page number is required, you will have to send that up for a valid response.

    – Sunny Wong
    Nov 15 '18 at 22:49















1















I have an API call that is receiving the "Failed to load Resource" 400 error. I have tried deleting cookies and cache and using a different browser. I also removed an image when I saw that image size could be the issue. I read about the need for HTTP headers, but did not understand where that would go in my code or what it would look like. Any assistance would be greatly appreciated! Here is my JS:



 const app = document.getElementById('root');

const container = document.createElement('div');
container.setAttribute('class', 'container');

app.appendChild(container);

var request = new XMLHttpRequest();
request.open('GET', 'https://www.themuse.com/api/public/jobs', true);
request.onload = function ()

// Begin accessing JSON data here
var data = JSON.parse(this.response);
if (request.status >= 200 && request.status < 400)
data.forEach(job =>
const card = document.createElement('div');
card.setAttribute('class', 'card');

const h1 = document.createElement('h1');
h1.textContent = job.title;

const p = document.createElement('p');
job.description = job.description.substring(0, 300);
p.textContent = `$job.description...`;

container.appendChild(card);
card.appendChild(h1);
card.appendChild(p);
);
else
const errorMessage = document.createElement('marquee');
errorMessage.textContent = `Darn, it's not working!`;
app.appendChild(errorMessage);



request.send();









share|improve this question

















  • 1





    The error is Not a valid argument for 'page', is the API being used correctly?

    – Hodrobond
    Nov 15 '18 at 22:39











  • themuse.com/developers/api/v2 On the docs for that endpoint it says the page number is required, you will have to send that up for a valid response.

    – Sunny Wong
    Nov 15 '18 at 22:49













1












1








1








I have an API call that is receiving the "Failed to load Resource" 400 error. I have tried deleting cookies and cache and using a different browser. I also removed an image when I saw that image size could be the issue. I read about the need for HTTP headers, but did not understand where that would go in my code or what it would look like. Any assistance would be greatly appreciated! Here is my JS:



 const app = document.getElementById('root');

const container = document.createElement('div');
container.setAttribute('class', 'container');

app.appendChild(container);

var request = new XMLHttpRequest();
request.open('GET', 'https://www.themuse.com/api/public/jobs', true);
request.onload = function ()

// Begin accessing JSON data here
var data = JSON.parse(this.response);
if (request.status >= 200 && request.status < 400)
data.forEach(job =>
const card = document.createElement('div');
card.setAttribute('class', 'card');

const h1 = document.createElement('h1');
h1.textContent = job.title;

const p = document.createElement('p');
job.description = job.description.substring(0, 300);
p.textContent = `$job.description...`;

container.appendChild(card);
card.appendChild(h1);
card.appendChild(p);
);
else
const errorMessage = document.createElement('marquee');
errorMessage.textContent = `Darn, it's not working!`;
app.appendChild(errorMessage);



request.send();









share|improve this question














I have an API call that is receiving the "Failed to load Resource" 400 error. I have tried deleting cookies and cache and using a different browser. I also removed an image when I saw that image size could be the issue. I read about the need for HTTP headers, but did not understand where that would go in my code or what it would look like. Any assistance would be greatly appreciated! Here is my JS:



 const app = document.getElementById('root');

const container = document.createElement('div');
container.setAttribute('class', 'container');

app.appendChild(container);

var request = new XMLHttpRequest();
request.open('GET', 'https://www.themuse.com/api/public/jobs', true);
request.onload = function ()

// Begin accessing JSON data here
var data = JSON.parse(this.response);
if (request.status >= 200 && request.status < 400)
data.forEach(job =>
const card = document.createElement('div');
card.setAttribute('class', 'card');

const h1 = document.createElement('h1');
h1.textContent = job.title;

const p = document.createElement('p');
job.description = job.description.substring(0, 300);
p.textContent = `$job.description...`;

container.appendChild(card);
card.appendChild(h1);
card.appendChild(p);
);
else
const errorMessage = document.createElement('marquee');
errorMessage.textContent = `Darn, it's not working!`;
app.appendChild(errorMessage);



request.send();






javascript api http-status-code-400






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 22:31







user9905066














  • 1





    The error is Not a valid argument for 'page', is the API being used correctly?

    – Hodrobond
    Nov 15 '18 at 22:39











  • themuse.com/developers/api/v2 On the docs for that endpoint it says the page number is required, you will have to send that up for a valid response.

    – Sunny Wong
    Nov 15 '18 at 22:49












  • 1





    The error is Not a valid argument for 'page', is the API being used correctly?

    – Hodrobond
    Nov 15 '18 at 22:39











  • themuse.com/developers/api/v2 On the docs for that endpoint it says the page number is required, you will have to send that up for a valid response.

    – Sunny Wong
    Nov 15 '18 at 22:49







1




1





The error is Not a valid argument for 'page', is the API being used correctly?

– Hodrobond
Nov 15 '18 at 22:39





The error is Not a valid argument for 'page', is the API being used correctly?

– Hodrobond
Nov 15 '18 at 22:39













themuse.com/developers/api/v2 On the docs for that endpoint it says the page number is required, you will have to send that up for a valid response.

– Sunny Wong
Nov 15 '18 at 22:49





themuse.com/developers/api/v2 On the docs for that endpoint it says the page number is required, you will have to send that up for a valid response.

– Sunny Wong
Nov 15 '18 at 22:49












1 Answer
1






active

oldest

votes


















0














If you try loading https://www.themuse.com/api/public/jobs in a browser you a 400 error along with the following error message:




"code": 400, "error": "Not a valid argument for 'page'"




That page requires you to supply it with a non-null variable called page via your GET request.



If you load the page as https://www.themuse.com/api/public/jobs?page=1 (eg) instead you can successfully load the data and your problem disappears!






share|improve this answer























  • The addition of /jobs?/page=1 cleared the error! Thanks so much. Now, onto the next error message. :)

    – user9905066
    Nov 16 '18 at 14:45










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328794%2fwhy-is-my-javascript-api-call-returning-a-400-error%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown
























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














If you try loading https://www.themuse.com/api/public/jobs in a browser you a 400 error along with the following error message:




"code": 400, "error": "Not a valid argument for 'page'"




That page requires you to supply it with a non-null variable called page via your GET request.



If you load the page as https://www.themuse.com/api/public/jobs?page=1 (eg) instead you can successfully load the data and your problem disappears!






share|improve this answer























  • The addition of /jobs?/page=1 cleared the error! Thanks so much. Now, onto the next error message. :)

    – user9905066
    Nov 16 '18 at 14:45















0














If you try loading https://www.themuse.com/api/public/jobs in a browser you a 400 error along with the following error message:




"code": 400, "error": "Not a valid argument for 'page'"




That page requires you to supply it with a non-null variable called page via your GET request.



If you load the page as https://www.themuse.com/api/public/jobs?page=1 (eg) instead you can successfully load the data and your problem disappears!






share|improve this answer























  • The addition of /jobs?/page=1 cleared the error! Thanks so much. Now, onto the next error message. :)

    – user9905066
    Nov 16 '18 at 14:45













0












0








0







If you try loading https://www.themuse.com/api/public/jobs in a browser you a 400 error along with the following error message:




"code": 400, "error": "Not a valid argument for 'page'"




That page requires you to supply it with a non-null variable called page via your GET request.



If you load the page as https://www.themuse.com/api/public/jobs?page=1 (eg) instead you can successfully load the data and your problem disappears!






share|improve this answer













If you try loading https://www.themuse.com/api/public/jobs in a browser you a 400 error along with the following error message:




"code": 400, "error": "Not a valid argument for 'page'"




That page requires you to supply it with a non-null variable called page via your GET request.



If you load the page as https://www.themuse.com/api/public/jobs?page=1 (eg) instead you can successfully load the data and your problem disappears!







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 22:46









seisvelasseisvelas

2,03911229




2,03911229












  • The addition of /jobs?/page=1 cleared the error! Thanks so much. Now, onto the next error message. :)

    – user9905066
    Nov 16 '18 at 14:45

















  • The addition of /jobs?/page=1 cleared the error! Thanks so much. Now, onto the next error message. :)

    – user9905066
    Nov 16 '18 at 14:45
















The addition of /jobs?/page=1 cleared the error! Thanks so much. Now, onto the next error message. :)

– user9905066
Nov 16 '18 at 14:45





The addition of /jobs?/page=1 cleared the error! Thanks so much. Now, onto the next error message. :)

– user9905066
Nov 16 '18 at 14:45



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328794%2fwhy-is-my-javascript-api-call-returning-a-400-error%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線