1

Having some trouble turning this curl command which calls an internal api function to an $http.post request

curl -X POST 'https://api-dev.message360.com/api/v2/webrtc/authenticate.json' -u 'xxxxxxxxxxxxxxxxx:xxxxxxxxxxxxxxxxx' -d 'userName=test@test.com'

----EDIT------

I have it set up like this Theres a form with ng-model=user

var data = {
 accountSid : "xxxxxx-xxxx-x-xx",
 authToken : "xxxxxxxxxxxxxx",
 userName : "xxxxx@xxxx.com"
}

$http.post(url, data).then(function(response) {
console.log(response);
}

but i'm getting an error its not returning anything..

Daniel Park
  • 489
  • 2
  • 7
  • 20
  • 2
    Show us what you did that doesn't work, we answer questions here we don't do your work for you! – Daniel Stenberg Aug 10 '16 at 22:44
  • I have set up like this – Daniel Park Aug 10 '16 at 23:00
  • Possible duplicate of [How do I POST urlencoded form data with $http in AngularJS?](http://stackoverflow.com/questions/24710503/how-do-i-post-urlencoded-form-data-with-http-in-angularjs). The [second answer](http://stackoverflow.com/a/30970229/283366) is the better one – Phil Aug 11 '16 at 01:55

1 Answers1

2

To help debug a $http.post call, you need to add the callback when an error occurs. Based on your code, here is an example:

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope, $http) {
    $scope.name = 'World';

    var url = 'https://api-dev.message360.com/api/v2/webrtc/authenticate.json';

    var data = {
        accountSid: "xxxxxx-xxxx-x-xx",
        authToken: "xxxxxxxxxxxxxx",
        userName: "xxxxx@xxxx.com"
    }

    $http.post(url, data, {
        'timeout': 10000
    }).then(function(response) {
        console.log(response);
    },
    function(reason) {
        console.error('ERROR: ' + JSON.stringify(reason));
    });
});

Because of the fake data, I get a -1 after the timeout, but please share the error your get in the Javascript console (see the function(reason) I added to display the error message.)

Here is a plunker based on your example.

Gregori
  • 829
  • 5
  • 12