Answers.Body: <p>finally I got the issue. It was related to the api URL. In ubuntu we created a link folder so the url worked. In windows the symbolic link was not created and also doesn't work so based on htaccess since the api was not found at the location it was redirecting to login page .
  Small thing but took hours to nail it down . Thanks anyways :)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-21T10:51:49.700Z
Answers.LastActivityDate: 2017-12-21T10:51:49.700Z
Answers.UserDisplayName: Vinay Jadhav
Body: <p><a href="http://crmqa.org/sites/crmqa.org/modules/civicrm/extern/rest.php?json=1&amp;entity=pax&amp;action=fetchAddressDetails&amp;api_key=apikeyofcontact&amp;key=sitekey" rel="nofollow noreferrer">http://crmqa.org/sites/crmqa.org/modules/civicrm/extern/rest.php?json=1&amp;entity=pax&amp;action=fetchAddressDetails&amp;api_key=apikeyofcontact&amp;key=sitekey</a></p>
  
  <p>When I call this through ajax and check in console I see 302 found and response is the login page of my application.
  In some other cases the api works fine it gives the required response when it is passed as form data.<br>
  Eg: Doesn't work <br></p>
  
  <pre><code>$.ajax({
             url: weblink,
             dataType: "json",
             method: "POST",
             contentType: "application/json; charset=utf-8",
             data: '{"pincode" : "' + pincode + '"}',
             success: function(data) {                    
                 if (data.length &gt; 0) {                        
                 } else {                            
                 }
             }});
  </code></pre>
  
  <p>but this: Works</p>
  
  <pre><code>$.ajax({
              url: weblink,
              dataType: "json", 
              method: "POST",
              data: { "event_id": event_id },
              success: function(data) {
                  $('.loading').remove();
                  $('.event_id').val(event_id);
                  //my code
              }});
  </code></pre>
  
  <p>Please help.</p>
  
Tags: <api><rest>
Title: Rest api's Give a 302 found and redirects to Login Page
ThreadText: # Rest api's Give a 302 found and redirects to Login Page
  
  (Asked by: username_0 on 2017-12-21)
  
  http://crmqa.org/sites/crmqa.org/modules/civicrm/extern/rest.php?json=1&entity=pax&action=fetchAddressDetails&api_key=apikeyofcontact&key=sitekey
  When I call this through ajax and check in console I see 302 found and response is the login page of my application.
  In some other cases the api works fine it gives the required response when it is passed as form data.
  Eg: Doesn't work 
  $.ajax({
             url: weblink,
             dataType: "json",
             method: "POST",
             contentType: "application/json; charset=utf-8",
             data: '{"pincode" : "' + pincode + '"}',
             success: function(data) {                    
                 if (data.length > 0) {                        
                 } else {                            
                 }
             }});
  
  but this: Works
  $.ajax({
              url: weblink,
              dataType: "json", 
              method: "POST",
              data: { "event_id": event_id },
              success: function(data) {
                  $('.loading').remove();
                  $('.event_id').val(event_id);
                  //my code
              }});
  
  Please help.
  
  **Tags:** api, rest
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-12-21. Score: 1
  
  finally I got the issue. It was related to the api URL. In ubuntu we created a link folder so the url worked. In windows the symbolic link was not created and also doesn't work so based on htaccess since the api was not found at the location it was redirecting to login page .
  Small thing but took hours to nail it down . Thanks anyways :)
  
  
  ---
  
  