Author Topic: ajax api login format  (Read 291 times)

Offline kevmoe

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
    • View Profile
ajax api login format
« on: November 30, 2016, 01:48:47 PM »
I am a beginner, so forgive me if I am asking a simple question... I am attempting to pull data from our content manager api docs. I am getting this error on testing: ERR_CONNECTION_REFUSED
... Where am I going wrong?

$.ajax({
     url: '.../ContentManager/api/rest/auth/login',
         type: 'POST',
         Authorization: 'user:password',
                   
         crossDomain: true,
         dataType: 'jsonp',
            
    success: function () {
         alert("success");
     },

     error: function (xhr, ajaxOptions, thrownError) {
         alert("You Failed DumbAss");
         
     },
   });

I assume my issue has something to do with the authorization... I have tried several formats for stating the user and password info.

Any assistance is appreciated.
« Last Edit: November 30, 2016, 01:51:38 PM by kevmoe »

Offline rhuffman8

  • Full Member
  • ***
  • Posts: 69
  • Karma: 0
  • VPC, Inc.
    • View Profile
    • VPC, Inc.
Re: ajax api login format
« Reply #1 on: December 21, 2016, 06:16:13 PM »
Have you tried submitting the username and password as two separate pieces like this:
Code: [Select]
$.ajax({
     url: '.../ContentManager/api/rest/auth/login',
         type: 'POST',
         Username: 'username',
         Password: 'password',
                   
         crossDomain: true,
         dataType: 'jsonp',
           
    success: function () {
         alert("success");
     },

     error: function (xhr, ajaxOptions, thrownError) {
         alert("You Failed DumbAss");
         
     },
   });

I'm not sure if that's a good or bad guess but for what it's worth, here's the command line login structure using Python, which may give you an idea of which direction to head in using ajax:
Code: [Select]
> http --verbose post localhost:8000/ContentManager/api/rest/auth/login
  username=Michael.Bolton password=PCLoadLetter

POST /ContentManager/api/rest/auth/login HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, compress
Content-Length: 53
Content-Type: application/json; charset=utf-8
Host: localhost:8000
User-Agent: HTTPie/0.6.0

{
    "username": "Michael.Bolton",
    "password": "PCLoadLetter"
}
Ryan Huffman
VPC, Inc.
240 Business Center Drive
Reisterstown, Maryland 21136

www.vpcinc.net