Google tasks update error - javascript

I am attempting to update a task with the following code:
function updtsk(task,id)
{
var url = 'https://www.googleapis.com/tasks/v1/lists/#default/tasks/'+id;
var req = {
'method': 'PUT',
'headers': {
'Content-type': 'application/json'
},
'body': JSON.stringify(task)
};
var addDone = function(resp, xhr) {
if (xhr.status != 200) {
notifyFailure('Couldn\'t update task.', xhr.status);
return;
}
//notifySuccess(task['title']);
}
oauth.sendSignedRequest(url, addDone, req);
}
I get the following error however:
"{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Invalid Value"
}
],
"code": 400,
"message": "Invalid Value"
}
}
"
The update body is this:
{
'title': $(this).val()
};
I am using the chrome_ex_oauth api and could use some help.

Try passing the 'id' key/value pair together with the title information you are already sending.
I had this same problem, even using the API explorer. There's no documentation to indicate this is a required parameter, especially since it is included in the URL. Once I added id, it worked properly.

It's possible you need to include additional fields in the update.
The documentation here: http://code.google.com/apis/tasks/v1/reference.html#resource_tasks appears to indicate the status property is not optional (the other mutable fields are listed as optional in their descriptions). You may also need to include the kind property with the static value indicated there.

In Google Task API for updating any TaskList Task:
First we have to get task with use of TaskList Id and Task Id
Second step change/update in task and again update that task.
Hope this is helpful for you.

I read these answers several times, but only saw what I thought I already knew, which was wrong. The documentation for insert/update/etc. states
POST https://www.googleapis.com/tasks/v1/lists/tasklist/tasks
It is the id of the tasklist being modified (e.g. something like "MTA1MjEpoqwdNTMzMjAzo349YDA6MDow") and not the title of the tasklist e.g. "My Task List" that needs to be passed in the POST request header, e.g.
POST https://www.googleapis.com/tasks/v1/lists/MTA1MjEpoqwdNTMzMjAzo349YDA6MDow/tasks
You can find the id of the list by doing a tasklists 'list' query.
GET https://www.googleapis.com/tasks/v1/users/#me/lists
which returns, e.g. something like this:
{
"kind": "tasks#taskList",
"id": "MTA1MjEpoqwdNTMzMjAzo349YDA6MDow",
"title": "My Task List",
"updated": "2019-03-15T21:21:03.000Z",
"selfLink": "https://www.googleapis.com/tasks/v1/users/#me/lists/MTA1MjE0Njc5NTMzMjA1NDk0NDA6MDM1NDgwMjIxODgyMjcyODow"
}
You can see the tasklist id in the response, which can then be used in the POST to modify the desired tasklist.
Answers to this question have been posted, but none with explicit examples. Hopefully this example will help someone get past this newbie kind of problem.

Related

Kintone Add Record API call always returns 'required field' error

Please help me!
It takes two days for me. So I would like to ask for your help.
In my app on Kintone, I have only required field as below.
enter image description here
In postman
Header
Content-Type application/json
X-Cybozu-API-Token b7EMUSEfcDCbb0xxxxxxxxxxxxxxxxxx
Request body with json format
{
"app":xxx,
"record": {
"名": {
"value": "三宅"
}
}
}
I got error as below.
{
"code": "CB_VA01",
"id": "1RY4iPgdkvHACFShdidq",
"message": "入力内容が正しくありません。",
"errors": {
"record.名.value": {
"messages": [
"必須です。"
]
}
}
}
What is the problem and how can I solve it. Please help me!
#Kintone
#Add Record api call error
First of all, I built a test app and used the script you provided, but it worked fine.
And then I tried to mess with the settings and code to recreate the same error, but the only way I was able to recreate it was by making the value empty as follows:
{
"app":XXX,
"record": {
"名": {
"value": ""
}
}
}
The error is basically saying the field is a required field, so I'm assuming the value isn't properly set.
Could you check your settings (such as headers) and see if you are doing it correctly?
Thank you

How do I add an action to watson conversation response?

I've created intent, entity and dialog without a problem. But right now I'm trying to make it so when the user send "goodbye", the application would close. According to the doc, I'll have to name an action that goes along with an intent. How do I do that? Is it through code or through the conversation workspace platform?
You can use context variables or action variables for that.
How to use context variables? Add in your Advance response the "context" and the values, check my example.
I've used the conversation simple for that.
In your Watson Developer Cloud - IBM Bluemix - Watson Conversation, add in the Advanced response this JSON example, Assuming it is in this conversation node that your application will do something:
{
"context": {
"verified": true;
},
"output": {
"text": {
"values": [
"Please wait and I'll verified your request."
],
"selection_policy": "sequential"
}
}
}
Example (app.js):
function updateMessage(input, data, req, res) {
if (data.context.verified === true){
searchRequest(data, req, res);
} else if (data.output && data.output.text) {
return res.json(data);
}
return data;
}
You can use the data for sending something within conversation flow.
function searchRequest(data, req, res){
// something to do and return value
var sendRequest = "Thanks for wait, the request is" + valueRequest;
data.output.text[0] = sendRequest;
return data;
}
EDIT:
You can add one JSON object like "action", and your code will recognize this variable, with the same example that #Mikko said. And you can check this with:
data.output.action === 'close'
See more about Context variables.
See more about Building a dialog.
You need to be careful with context variables as your next dialog node may or may not update them. Another option is to add a custom variable in the output. This is the solution used in conversation-discovery samples available in the GitHub.
"output": {
"text": {
"values": [
"Goodbye..."
],
"selection_policy": "sequential"
},
"action": "close"
}
Please note that this will cause a warning when closing the JSON editor.

Azure Graph api user creation - property values specified are invalid

I have a problem with Azure AD Graph API integration where we try to create user to existing Active directory. Used azure documentation to work on this (https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#UpdateUser)
For some reason the example dataset is not working, but I'm receiving:
{
"odata.error": {
"code": "Request_BadRequest",
"message": {
"lang": "en",
"value": "One or more property values specified are invalid."
},
"values": null
}
}
The dataset I'm passing is
{
"accountEnabled": true,
"displayName": "Test User",
"mailNickname": "TestUser",
"passwordProfile": {
"password": "Test1234",
"forceChangePasswordNextLogin": false
},
"userPrincipalName": "Test#_MY_DOMAIN_.onmicrosoft.com"
}
_MY_DOMAIN_ is one of the domains defined in the Active directory's domains.
If I try e.g. removing any of the required fields, I'm receiving error which defines the missing property.
Listing and updating users is working just fine, there is some weird issue with adding.
Usually, we will get this issue when we haven't set the Url in the correct format. I tested your dataset on my side, it worked fine. Please double check the url.
Here is the capture of my test request:
Any further concern, please feel free to let me know.
Most probably problem was related to Azure AD permissions. Somehow started suddenly working.
One thing figured out is that the error message above will also come e.g. if you have property key mistyped. Sometimes response describes the missing property, but not always.
Thanks everyone for your time..

MongoDb: Find the generated id of the inserted child on parent save

If I have a document representing a post with comments that looks like this:
{
"_id": "579a2a71f7b5455c28a7abcb",
"title": "post 1",
"link": "www.link1.com",
"__v": 0,
"comments": [
{
"author": "Andy",
"body": "Wish I had thought of that",
"_id": "579a2a71f7b5455c28a7abcd",
"upvotes": 0
},
{
"author": "Jim",
"body": "Just a comment",
"_id": "579a2a71f7b5455c28a7abcc",
"upvotes": 0
}
],
"upvotes": 5
}
In the calling (javascript) code, I add a new comment, by pushing to the post.comments array, then save the post using .save with a callback. In the save callback, I want to get the generated _id of the new comment I just saved. How do I do this?
I've got the parent post document in the callback, of course, but that's not useful as I can't tell which comment was just inserted.
Is there another document method or an alternate form of the .save callback to deal with my situation?
Or do I have to just follow what I'd usually do and generate a unique id on the comment myself before the save?
EDITED: I'm using Mongoose, sorry, forgot to say!
You did not specifically tell, but I assume you use Mongoose because standard MongoDB will not add an _id property to subdocuments.
As mentioned in the Mongoose documentation regarding adding sub-documents, you can use the following code example:
var Parent = mongoose.model('Parent');
var parent = new Parent;
// create a comment
parent.children.push({ name: 'Liesl' });
var subdoc = parent.children[0];
console.log(subdoc) // { _id: '501d86090d371bab2c0341c5', name: 'Liesl' }
subdoc.isNew; // true
parent.save(function (err) {
if (err) return handleError(err)
console.log('Success!');
});
Instead of parent.children[0] you have to use parent.children[parent.children.length - 1] to access the inserted element, though.
I'd assume the item you pushed on the array would be the last one, but that wouldn't work in a multi user system.
Also you could make a comparison against the author and comment fields, though this seems like a lot of trouble, and with just the author and the comment text, you might not be assured a match.
Finally, you could also create the object id and assign it to the comment, then save it. You do that like this:
var mongoose = require('mongoose');
var id = mongoose.Types.ObjectId();
That's what I would do.

Slack API (JSON Data)

I'm trying to use this method provided via the Slack API to grab the "name" attribute of the "user" object and the code I'm using to do that is as follows:
controller.hears(['users'], 'direct_message, direct_mention, mention', function(bot, message){
bot.api.users.info({}), function(err, response) {
bot.reply(message, response);
var slack_username = message["user"][2];
console.log(">>>>> " + slack_username);
});
});
I'm not sure what I'm doing wrong/missing and any help would be greatly appreciated! Thanks in advance!
EDIT:
Expected Output: "dkulas"
Terminal Output" "U"
debug: Got response null {"OK":false,"error":"user_not_found"}
degub: SAY { ok: false, error: 'user_not_found', channel" 'D0UV5S7MZ' }
The Slack API method users.info requires you to provide the Slack User ID in the query. The format is U12345678. (also see here for the usage documentation)
If you want to get the user info for a user by name, use the API method users.list to get the list of all users including name and user ID and then search that list for the right match. users.list provides all information about a user, so you don't need to call user.info.
See here for the documentation on this method.

Categories

Resources