Asana task field "hearts" user ids - api

Asana task field hearts contains user ids that are not equal to the workspace's user ids. Is that a bug or a feature?
According to the api documentation:
hearts
[ { id: 1123, name: 'Mittens' }, ... ]
Read-only. Array of users who have hearted this task.

Note: a Heart is an object in its own right, with its own ID. If you want the ID of the User who "created" the heart, you need to use hearts.user.id, which is the same as the ID of the user in the workspace (i.e. you could do GET /users/:id).
Example using ?opt_expand=hearts:
"hearts" : [
{
"target" : {
"name" : "Task name here",
"id" : 1234 // ID OF TASK
},
"id" : 1235, // ID OF HEART
"user" : {
"name" : "User name",
"id" : 1236 // ID OF USER
},
"created_at" : "2015-11-30T12:40:13.516Z"
}
],

Related

Karate - Conditional JSON schema validation

I am just wondering how can I do conditional schema validation. The API response is dynamic based on customerType key. If customerType is person then, person details will be included and if the customerType is org organization details will be included in the JSON response. So the response can be in either of the following forms
{
"customerType" : "person",
"person" : {
"fistName" : "A",
"lastName" : "B"
},
"id" : 1,
"requestDate" : "2021-11-11"
}
{
"customerType" : "org",
"organization" : {
"orgName" : "A",
"orgAddress" : "B"
},
"id" : 2,
"requestDate" : "2021-11-11"
}
The schema I created to validate above 2 scenario is as follows
{
"customerType" : "#string",
"organization" : "#? response.customerType=='org' ? karate.match(_,personSchema) : karate.match(_,null)",
"person" : "#? response.customerType=='person' ? karate.match(_,orgSchema) : karate.match(_,null)",
"id" : "#number",
"requestDate" : "#string"
}
but the schema fails to match with the actual response. What changes should I make in the schema to make it work?
Note : I am planning to reuse the schema in multiple tests so I will be keeping the schema in separate files, independent of the feature file
Can you refer to this answer which I think is the better approach: https://stackoverflow.com/a/47336682/143475
That said, I think you missed that the JS karate.match() API doesn't return a boolean, but a JSON that contains a pass boolean property.
So you have to do things like this:
* def someVar = karate.match(actual, expected).pass ? {} : {}

$in query with $elemMatch in mongoDB

I need to find a document where "components" not exist OR if exists, its id is 1111 and isActive is true and "issues" not exist OR its id is 1111 and isActive is true.
Example:
Document 1: ////this contains "components" but not "issues"
{..
"components" : [
{
"id" : "1111",
"name" : "component1",
"isActive" : true
}
],
}
Document 2://this contains "issues" but not "components"
{..
"issues" : [
{
"id" : "1111",
"name" : "issue 1",
"isActive" : true
}
],
..}
Document 3://This is not having both
Query:
db.sample.find({
"issues":{$in:[null, {"$elemMatch" : {"id":"1111","isActive": {"$in":[true,null]}}}]},
"components":{$in:[null, {"$elemMatch" : {"id":"1111","isActive": {"$in":[true,null]}}}]}
})
But I am getting an error, "errmsg" : "cannot nest $ under $in",
Please help to form the query that returns all the above 3 documents.
You don't require $in. You need $or operator.
Try
db.sample.find({
$or:[
{"issues":{$exists:true,"$elemMatch" : {"id":"1111","isActive": true}}},
{"components":{$exists:true,"$elemMatch" : {"id":"1111","isActive": true}}}
]
})
Based on OP's comments. here is the working version.
db.Sample.find({
$or:[
{"issues":{$exists:true,"$elemMatch":{"id":"1111","isActive":true}},
"components":{$exists:false} },
{"components":{$exists:true,"$elemMatch":{"id":"1111","isActive":true}},
"issues":{$exists:false}},
{"issues":{$exists:true,"$elemMatch":{"id":"1111","isActive": true}},
"components":{$exists:true,"$elemMatch":{"id":"1111","isActive":true}}},
{"issues":{$exists:false}, "components":{$exists:false}}
]
})

Example of presenceGroup used in apiRTC.init

In the documentation it is indicated that presenceGroup and subscribeToPresenceGroup can be set in the apiRTCinit. They are json parameters, but what exactly is the format? What do they each do, they sound redundant, so I am not clear.
Here is a sample of apiRTC.init() :
//apiRTC init
apiRTC.init({
apiKey : "myDemoApiKey",
//apiCCId : "229",
onReady : sessionReadyHandler,
userData : {
"lastName": "lastName",
"firstName": "firstName"
},
presenceGroup : ["agent"],
subscribeToPresenceGroup : ["visitor", "agent"]
});
presenceGroup : define the groups of the user : user will be considered as present in these groups
subscribeToPresenceGroup : define the presence group to which the user has subscribed : user will receive the presence information for these groups.
In our sample : user is connected to group "agent", but will receive presence information for group "visitor" and group "agent"

Mongo adding an object to original object

I am not sure if I am asking the correct question but I assume this is just a basic mongodb question.
I currently have this:
{
"_id" : ObjectId("57af98d4d71c4efff5304335"),
"fullname" : "test",
"username" : "test",
"email" : "test#gmail.com",
"password" : "$2a$10$Wl29i6FemBrnOKq/ZErSguxlfvqoayZQkaEDirkmDl5O3GDEQjOV2"
}
and I would like to add an exercise object like this:
{
"_id" : ObjectId("57af98d4d71c4efff5304335"),
"fullname" : "test",
"username" : "test",
"email" : "test#gmail.com",
"password" : "$2a$10$Wl29i6FemBrnOKq/ZErSguxlfvqoayZQkaEDirkmDl5O3GDEQjOV2",
"exercises": {
"benchpress",
"rows",
"curls",
}
I am just unsure how to create exercises with the object without using $push which just opens up an array. I don't want an array, I want an object.
Any help would be greatly appreciated it.
An object is a key-value pair. In your representation of the second document, you have a nested document exercises as a key and its value as an object containing only strings. Don't you see something strange there? An object without keys?
It should probably be an array of strings. Note that an array is indeed an object where the key is the numeric index starting from 0 and the value is the string in that position.
(You have an additional comma and a missing curly-brace. Lets fix that.)
This is the document we wish to see after updating the document.
{
"_id" : ObjectId("57af98d4d71c4efff5304335"),
"fullname" : "test",
"username" : "test",
"email" : "test#gmail.com",
"password" : "$2a$10$Wl29i6FemBrnOKq/ZErSguxlfvqoayZQkaEDirkmDl5O3GDEQjOV2",
"exercises": [
"benchpress",
"rows",
"curls"
]
}
Now, back to your question. How can we update the existing document with the exercises document? Its pretty simple. Mongodb has a 'update' method which exactly does that. Since we don't want to replace the entire document and just add additional fields, we should use $set to update specific fields. Fire up the mongo shell and switch to your database using use db-name. Then execute the following command. I assume you have an existing document with id ObjectId("57af98d4d71c4efff5304335"). Note that ObjectId is a BSON datatype.
db.scratch.update({ "_id" : ObjectId("57af98d4d71c4efff5304335") }, { $set: {"exercises": ["benchpress", "rows", "curls"] } })
This will update the document as
{
"_id" : ObjectId("57af98d4d71c4efff5304335"),
"fullname" : "test",
"username" : "test",
"email" : "test#gmail.com",
"password" : "$2a$10$Wl29i6FemBrnOKq/ZErSguxlfvqoayZQkaEDirkmDl5O3GDEQjOV2",
"exercises" : [
"benchpress",
"rows",
"curls"
]
}
Here scratch refers to the collection name. The update method takes 3 parameters.
Query to find the document to update
The Update parameter(document to update). You can either replace the whole document or just specific parts of the document(using $set).
An optional object which can tell Mongodb to insert the record if the document doesn't exist(upsert) or update multiple documents that match the criteria(multiple).
EXTRA
Warning: If you execute the following in the mongo shell,
db.scratch.update({ "_id" : ObjectId("57af98d4d71c4efff5304335") }, {"exercises": ["benchpress", "rows", "curls"] })
the entire document would be replaced except the _id field. So, the record would be something like this:
{
"_id" : ObjectId("57af98d4d71c4efff5304335"),
"exercises" : [
"benchpress",
"rows",
"curls"
]
}
You should only do this when you are aware of the consequence.
Hope this helps.
For more, see https://docs.mongodb.com/manual/reference/method/db.collection.update/

Lookback API: Deleted items

I'd like to use the lookback API to view the history of a deleted object, which I think should be simple if I know the formatted id. I just need to query:
{ FormattedID: 'DEXXXX' }
But does the Lookback API record anything special for when an object is deleted (like can I tell exactly when it was deleted or by whom)? Can it help point me to the correct place in the Recycle bin so that I could try to undelete it?
If you know the specific FormattedID, you can just query for its history, as you mentioned above. There isn't a special indicator that a snapshot represents the last valid state before a deletion, but the _ValidTo date will have been changed from the apoc (9999-01-01) to the date and time it was deleted. Unfortunately, the _User field of that last snapshot will be of the person that caused the last change to the object (before deletion), since we don't record a snapshot for when we delete.
Interesting. I just ran a REST query on the Recycle Bin with fetch=true and got back a lot more data on the result set than I'm used to:
GET https://rally1.rallydev.com/slm/webservice/1.40/recyclebinentry/12345678914.js
{ "RecycleBinEntry" : { "DeletedBy" : { "_rallyAPIMajor" : "1",
"_rallyAPIMinor" : "40",
"_ref" : "https://rally1.rallydev.com/slm/webservice/1.40/user/12345678910.js",
"_refObjectName" : "User One",
"_type" : "User"
},
"DeletionDate" : "2012-05-15T02:53:10.087Z",
"Errors" : [ ],
"ID" : "DE32",
"Name" : "Error found in TC43: TC07-011",
"ObjectID" : 12345678911,
"Subscription" : { "_rallyAPIMajor" : "1",
"_rallyAPIMinor" : "40",
"_ref" : "https://rally1.rallydev.com/slm/webservice/1.40/subscription/12345678912.js",
"_refObjectName" : "My Subscription",
"_type" : "Subscription"
},
"Type" : "Defect",
"Warnings" : [ ],
"Workspace" : { "_rallyAPIMajor" : "1",
"_rallyAPIMinor" : "40",
"_ref" : "https://rally1.rallydev.com/slm/webservice/1.40/workspace/12345678913.js",
"_refObjectName" : "My Workspace",
"_type" : "Workspace"
},
"_CreatedAt" : "May 14, 2012",
"_objectVersion" : "1",
"_rallyAPIMajor" : "1",
"_rallyAPIMinor" : "40",
"_ref" : "https://rally1.rallydev.com/slm/webservice/1.40/recyclebinentry/12345678914.js",
"_refObjectName" : "Error found in TC43: TC07-011"
}
}
I didn't realized Rally released an enhancement to this information, but this data includes the Name and Ref of the User that deleted the Object.
You can walk the Recycle bin of the current Workspace/Project using this REST URL:
https://rally1.rallydev.com/slm/webservice/1.40/recyclebin.js?workspace=/workspace/12345678919&project=/project/12345678920&fetch=true
Where 12345678919 and 12345678920 are the Workspace and Project OIDs, respectively.
Unfortunately Lookback API doesn't provide anything along the lines of tracking deletions or entries in the Recycle Bin. The focus is definitely on Analytics and providing a robust reporting engine for agile metrics.
This doesn't exclude the possibility that at some point LBAPI or other aspects of Rally services could be enhanced with trace-ability and tracking/accountability type of functionality. Enhanced trace-ability in Rally is something customers have expressed a need for and is definitely something that Rally's Product Management team is aware of as a customer need.