Sending parameters and array in POST ajax

I am calling a POST where I need to send request parameters and array in request body. Am I sending it correctly? For some reason, the call is returning 401 Unauthorized.

        $.ajax({
             type: "Post",
             url: "https://myserver.com/WebServices/upms/giveCompanyDatasetDBInfo?personnelId=1234&projectId=80&companyId=3222&companyShortName=testNameSept1",
             data: JSON.stringify(selectedRows) ,
             async: true,
             cache: false,
             success: function(data) {
                console.log("Inside success of giveStandardDatasetDBInfo endpoint");
                 console.log(data);
             }
         });

If you are wondering what is selectedRows, it’s the following array which is obtained when you click get rows button in this JSfiddle:

    [{
      available: true,
      boundindex: 1,
      firstname: "Mayumi",
      lastname: "Petersen",
      price: 4.5,
      productname: "Caffe Latte",
      quantity: 10,
      total: 45,
      uid: 1,
      uniqueid: "2527-22-22-30-262925",
      visibleindex: 1
    }, {
      available: true,
      boundindex: 3,
      firstname: "Regina",
      lastname: "Davolio",
      price: 3,
      productname: "Caffe Espresso",
      quantity: 2,
      total: 6,
      uid: 3,
      uniqueid: "2625-21-18-21-302517",
      visibleindex: 3
    }, {
      available: true,
      boundindex: 5,
      firstname: "Antoni",
      lastname: "Nodier",
      price: 4.5,
      productname: "Caffe Latte",
      quantity: 4,
      total: 18,
      uid: 5,
      uniqueid: "1722-19-21-21-291926",
      visibleindex: 5
    }, {
      available: true,
      boundindex: 7,
      firstname: "Nancy",
      lastname: "Nagase",
      price: 4,
      productname: "Peppermint Mocha Twist",
      quantity: 1,
      total: 4,
      uid: 7,
      uniqueid: "2820-23-31-17-222721",
      visibleindex: 7
    }, {
      available: true,
      boundindex: 9,
      firstname: "Lars",
      lastname: "Nagase",
      price: 3.25,
      productname: "Espresso con Panna",
      quantity: 3,
      total: 9.75,
      uid: 9,
      uniqueid: "2826-22-19-25-252329",
      visibleindex: 9
    }]

Well the error is pretty self explanatory, you are not authorized. The question is, how are you authorizing requests? Is there some kind of key you need to pass to your URL? Is it based on a cookie which you are not passing along with the request you are making? Do you have to get a token and provide that as a header? Tell us more about how you go about determining if someone is authorized to use that endpoint. My guess is that you are expecting this request to just work without passing the additional info needed for the URL/endpoint to know if you are authorized to use it or not. :slight_smile:

Thanks for your response. So the request that I am sending looks correct?

I tested it using POSTMAN client and getting the following error:


<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>502 Proxy Error</title>
</head><body>
<h1>Proxy Error</h1>
<p>The proxy server received an invalid
response from an upstream server.<br />
The proxy server could not handle the request <em><a href="/WebServices/upms/giveCompanyDatasetDBInfo">POST&nbsp;/WebServices/upms/giveCompanyDatasetDBInfo</a></em>.<p>
Reason: <strong>Error reading from remote server</strong></p></p>
</body></html>

It sounds like you have some server-side issues or again missing some data. If it were me, I would work out the problem first in POSTMAN and then once you have it working there, you can work it into your JS. This will then tell you when your JS is the problem versus something on the server causing problems.

Yes, I will discuss with the people who developed web service. That’s the same reason I switched to POSTMAN. Thanks for your inputs.

There was an issue with the database stored procedure and hence it wasn’t working. It started working via POSTMAN. I will test it via JS soon.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.