How can I set a task to completed using the Asana API? - asana

I'm wondering how to use the Asana APIs to send the command to complete a task.
I was trying something like:
https://app.asana.com/api/1.0/tasks/417207316735809/?opt_pretty&completed=true
but it doesn't work like that, I've checked the documentation, but couldn't find an answer.
Asana doc (someone requested it in comments): https://asana.com/developers/documentation/getting-started/input-output-options
Since I want to use it in my chrome extension I can't use curl so I treid ajax:
$.ajax({
type : "GET",
url : "https://app.asana.com/api/1.0/tasks/417207316174232/?opt_pretty",
data: {
completed: true,
},
success : function(result) {
result = JSON.stringify(result);
alert(result);
},
error : function(result) {
alert('xxx');
}
});
Any idea how to pass "completed=true" from doc in js?

If you are updating a resource you need to make a PUT request, not a GET request.
When I made this change, your AJAX request worked.

Related

What do I do with low Scores in reCAPTCHA v3?

I have set up reCAPTCHA v3 on my ASP.NET MVC project. Everything is working fine and is passing back data properly.
So the code below depends on another dll I have, but basically, the response is returned in the form of an object that shows everything that the JSON request passes back, as documented by https://developers.google.com/recaptcha/docs/v3
It all works.
But now that I know the response was successful, and I have a score, what do I do? What happens if the score is .3 or below? Some people recommend having v2 also set up for secondary validation (i.e. the 'choose all the stop signs in this picture' or 'type the word you see'). Is that really the only 'good' option?
Obviously the code isn't perfect yet. I'll probably handle the solution in the AJAX call rather than the controller, but still. What should I do if the score is low?
I read this article
reCaptcha v3 handle score callback
and it helped a little bit, but I'm still struggling to understand. I don't necessarily need code (although it would never hurt) but just suggestions on what to do.
VIEW:
<script src="https://www.google.com/recaptcha/api.js?render=#Session["reCAPTCHA"]"></script>
grecaptcha.ready(function () {
grecaptcha.execute('#Session["reCAPTCHA"]', { action: 'homepage' }).then(function (token) {
$.ajax({
type: "POST",
url: "Home/Method",
data: JSON.stringify({token: token }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
console.log('Passed the token successfully');
},
failure: function (response) {
alert(response.d);
}
});
});
});
CONTROLLER:
[HttpPost]
public void ReCaptchaValidator(string token)
{
ReCaptcha reCaptcha = new ReCaptcha();
Models.ReCaptcha response = new Models.ReCaptcha();
response = reCaptcha.ValidateCaptcha(token);
//response returns JSON object including sucess and score
if (response.Success)
{
//WHAT DO I DO HERE????
}
}
Ended up getting the answer from another forum. Basically, the answer is "anything you want". There is no right or wrong when handing a successful response.
So what could be done, is if the response is successful and CAPTCHA doesn't throw a flag, do nothing. But if CAPTCHA is unhappy, you could display an alert or a banner that says 'could not process', or you could even add in CAPTCA version 2, which would make them do the picture test or the 'I am not a robot' checkbox, etc.

How to call servlets using AJS in JIRA plugin?

I know a way to call REST APIs using AJS.
I want to call POST of servlet using AJS. Via given docs, I could only find a way to call GET of servlets via hitting http://localhost:2990/jira/plugins/servlet/{servletURL} in browser. Is there a way to call same url with POST method using AJS?
You can use AJAX calls
AJS.$.ajax({
url: "http://localhost:2990/jira/plugins/servlet/{servletURL}",
type: "GET",
data: ({projectsOnly : "true"}),
dataType: "json",
success: function(msg){
alert(msg);
}
});
see their documentation

Rails Active Model Serializers conflict with Ajax?

When I use gem "active_model_serializers", my all Ajax can't work, my code like following:
$(document).on('change','#brand_id_dropdown', function () {
var request = "/beacons/find_beacon_uuid_given_brand_id?brand_id="
+ $('#brand_id_dropdown').val();
var aj = $.ajax({
url: request,
type: 'get',
data: $(this).serialize()
}).done(function (data) {
change_uuids(data);//modify the majors' dropdown
}).fail(function (data) {
console.log('AJAX request has FAILED');
});
});
I tried change to
data: { get_param: 'value' },
dataType: 'json'
still conflict, whenever I gem serializer and start rails server, all Ajax fail. how can I fix that?
I can't comment because I don't have enough rep. But you need to supply a little more information.
What's the failure message in the rails server logs? Check the rails server output and copy paste the errors into your question. Also, open your browser console and paste the "console" or "network" errors (in chrome: OPTION+CMD+I to show console). Lastly, throw a debugger; statement into your ajax call and play around with the variables.

Catch and pass hangout url to my rails app

I have a button to start a google hangout, everything works great, now I need to get the url using the
gapi.hangout.getHangoutUrl();
but I since this is a JS on my server, I know is possible to pass this to my app. But I don't know how (AJAX or anything else). I need this, because other user could join to this hangout.
Any suggestion with code would be appreciate
Within your hangout script....
Include jQuery - it's useful for X-browser support.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Get the Hangout URL:
var hoUrl = gapi.hangout.getHangoutUrl();
Get/Post the hangout URL to your server:
var uri = encodeURI(server + '?hoUrl=' + hoUrl);
$.ajax(uri,
{
async: true,
beforeSend: function(request) {
// Any beforesend code goes here, e.g. adding headers.
},
data: data,
error: function(jqhr, status, error){
// Error handling goes here.
},
type: verb,
success: callback
});
Handle the AJAX GET request and do your magic with the hoUrl parameter.
To clarify further:
A URL is formed before the AJAX get request to include a GET parameter, hoUrl, that has the hangout URL in it. Your server just needs to use whatever CGI/parameter parser to retrieve the 'hoUrl' parameter and then do whatever backend magic you want to do with it. Hope that helps to clarify.

Sencha Touch 2 & Spring Security cross-domain login

I need use API of some server from Sencha Touch 2 app . For using this API I need authenticate on server.
So I already implemented login functionality :
Ext.Ajax.request({
url: 'http://192.168.1.2:8080/spring-security-extjs-login/j_spring_security_check',
method: 'POST',
params: {
j_username: 'rod',
j_password: 'koala',
},
withCredentials: false,
useDefaultXhrHeader: false,
success: function(response){
var text = response.responseText;
Ext.Msg.alert("success", text, Ext.emptyFn);
},
failure: function(response){
var text = response.responseText;
Ext.Msg.alert('Error', text, Ext.emptyFn);
}
});
But how I can call API , because after authentication I try call API but they already want authentication. Probably I need save JSESSIONID and added it to another request, but I don't know how I can do it.
I can't use withCredentials: true , so I need to find another solution.
How I can get Set-Cookies from response HTTP Header ?
I see in Chrome console, that JSESSIONID present in response header , so , i need get it.
Please, help me find any solutions.
You can use requestcomplete & beforerequest events to read response headers and to write request headers respectively. Here is sample code :
Ext.Ajax.on('requestcomplete', function(conn, response, options, eOpts){
var respObj = Ext.JSON.decode(response.responseText);
Helper.setSessionId(options.headers['JSESSIONID']);
}, this);
Ext.Ajax.on('beforerequest', function(conn, options, eOptions){
options.headers['JSESSIONID'] = Helper.getSessionId();
}, this);

Resources