0

I try to use the $resource service with surveygizmo api.
My code :

html :

<div ng-app="Survey">
<body>
<div ng-controller="SurveyCtrl">
    {{survey.data.title}}
</div>
</body>
</div>

my script :

angular.module('Survey', ['ngResource']);

function SurveyCtrl($scope, $resource) {
    $scope.surveygizmo = $resource('https://restapi.surveygizmo.com/v3/survey/:id',
        {id: '@id'},
        {get:{method:'JSONP', params: {'user:pass':'xxx@xxxx:xxxx', q:'angularjs', callback:'JSON_CALLBACK'}, isArray:true}});

$scope.survey = $scope.surveygizmo.get({id:xxxx}, function(survey) {
        alert('this is ok');
    }, function(err){
        alert('request failed');
    });
}

When i try it, the alert 'request failed' appear in my page. No json result in the page but i can see it in the firebug network menu.
May i miss something?
kalaoke

1
  • does the API support JSONP Commented Jun 11, 2013 at 5:56

2 Answers 2

1

I know this question is old, but I thought I might be able to help. I actually work at SurveyGimzo. We actually do support JSONP, JSON and XML. However; in order to request JSONP you need to specify this in the url. Using your example URL, it would look like this.

https://restapi.surveygizmo.com/v3/survey/:id.jsonp

Now when you request JSON_CALLBACK as part of the your ngResource parameters for your get action, you will get a properly wrapped object back.

I have been tinkering around with a minnie AngularJS app using SG REST api. You are welcome to take a look at my github https://github.com/sfisherGizmo/ang-app

I hope this helps anyone else who may happen across this as well.

Sign up to request clarification or add additional context in comments.

Comments

0

Survey Gizmo does not support JSONP. HTTP Methods which are supported by Survey Gizmo are PUT, POST, DELETE see http://developer.surveygizmo.com/rest-api-documentation/methods/

Or if they support they did not specify that in the API doc.

this is what i see when u change .get to .query

Request URL:https://restapi.surveygizmo.com/v3/survey/xxxx
Request Method:OPTIONS
Status Code:200 OK

and if you go ahead with .get the response is

Request URL:https://restapi.surveygizmo.com/v3/survey/xxxx
Request Method:GET
Status Code:200 OK

But the response is not wrapped in JSONP callback. Though you are able to see a response in firebug network console but angular is not able to unwrap it since its not a JSONP response.

Check http://jsfiddle.net/jhsousa/aQ4XX/ for angularjs examples using ngResource

3 Comments

Hi ty for your answer, i'm not sure to understand...Here for getting a survey we don't use a GET method ? [link]developer.surveygizmo.com/rest-api-documentation/objects/…
yes docs say to use a GET method but you are using JSONP method:'JSONP',
i try first with GEt method but nothing appears in firebug. With JSONP method data result is visible in firebug

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.