I am using the RT::Extension::REST2 api (https://metacpan.org/pod/RT::Extension::REST2) for a project and i am having a problem requesting additional fields in some requests.
I need to make a TicketSQL query and for performance reasons i am trying to obtain all the information of a ticket with something like /REST/2.0/ticket/8?fields=Requestor and i get something like
"Requestor": [
{
"_url" : "http://<>/REST/2.0/user/example#example.com",
"id" : "example#example.com",
"type" : "user"
},
{
"_url" : "http://<>/REST/2.0/user/example#example.com",
"id" : "example#example.com",
"type" : "user"
}
]
Notice it is a List of dictionaries, so when i try to do /REST/2.0/ticket/8?fields[Requestor]=Name the field Name does not appear on the dictionaries inside the list.
So i am trying to get something like this:
"Requestor": [
{
"_url" : "http://<>/REST/2.0/user/example#example.com",
"id" : "example#example.com",
"type" : "user",
"Name" : "user20",
},
{
"_url" : "http://<>/REST/2.0/user/example#example.com",
"id" : "example#example.com",
"type" : "user",
"Name" : "user20",
}
]
Is there any way i can do this ?
Thank you for your help!
Related
I am trying to create custom field using Tooling API in Salesforce. First to check Tooling API, I tried using workbench but it is showing following error:
JSON Parser Error:
message: Cannot deserialize instance of complexvalue from VALUE_STRING value text or request may be missing a required field at [line:5, column:25]
errorCode: JSON_PARSER_ERROR
Following is the JSON body I am using:
{
"DeveloperName" : "CusField",
"Metadata":
{
"type" : "text",
"description" : "test",
"inlineHelpText" : "testhelp",
"label" : "cus Field",
"required" : false,
"precision" : null,
"length" : 255,
"unique" : false,
"externalId" : false,
"trackHistory" : false
},
"TableEnumOrId" : "Account",
"ManageableState" : "installed"
}
Please let me know what is wrong with body?
Thanks in Advance.
There are a few things wrong with the body.
Remove ManageableState
Do not include DeveloperName and TableEnumOrId, instead, use FullName as shown below
Capitalize the field type Text
Here's a working post body:
{
"FullName" : "Account.CusField__c",
"Metadata": {
"type" : "Text",
"description" : "test",
"inlineHelpText" : "testhelp",
"label" : "cus Field",
"required" : false,
"precision" : null,
"length" : 255,
"unique" : false,
"externalId" : false,
"trackHistory" : false
}
}
Did anyone knows how to store data in mongoDB to be used with https://github.com/gian788/i18next-node-mongodb-backend. Tried couple of things and its not translating keys.
Here is how I am storing my data in mongo
{"en" : { "translation" : { "FirstName" : "First Name", "LastName" : "Lastwq Name" } } }
While printing it always prints key with error
i18next::translator: missingKey en translation FirstName FirstName
Any help?
The format is the following :
{
"_id" : ObjectId("581f3645caa6b31c074dd91c"),
"language" : "en",
"namespace" : "translation",
"data" : {
"FirstName" : "First Name",
"LastName" : "Lastwq Name"
}
}
Obviously you can change the namespace in the init options
Actually i am not trying to match two collection's . I am looking for match the field with secondary collection. I'll explain my problem clearly:
this is my primary collection "bags".which contains
{
"_id" : ObjectId("568f43e08a9f71b70b22a694"),
"bagNo" : "HBBN/00001/16",
"category" : "Voluntary",
"regNo" : "DNR/00001/16",
"status": "Accepted"
},
{ "_id" : ObjectId("568f4645fa0758af0e3fef26"), "bagNo" :"HBBN/00002/16", "category" : "Voluntary", "regNo" : "DNR/00002/16", "status": "Rejected" },
{ "_id" : ObjectId("568f4645fa4546gygfef26"), "bagNo" : "HBBN/00003/16", "category" : "Voluntary", "regNo" : "DNR/00003/16", "status": "Accepted" }
now my join collection "donor" contains
{"donorType" : "H",
"regNo" : "DNR/00001/16",
"surName" : "pandey",
"firstName" : "rakesh"},
{"donorType" : "C", "regNo" : "DNR/00002/16", "surName" : "pandey", "firstName" : "rakesh" },
{"donorType" : "C", "regNo" : "DNR/00003/16", "surName" : "pandey", "firstName" : "rakesh" }
from these two collections i want to get the accepted bags data from bags collection which having 'donortype' as 'H' in donor collection.Please let me know if it is possible.explain with some example
To combine two collections, you could try to do it with $lookup in aggregation.
donor.aggregation([
// filter the `donortype` of `H`
{$match: {donortype: 'H'}},
// join with `bags` collection for the foreign key `regNo`, and put bags into `h_bags` result.
{$lookup: {
from: "bags",
localField: "regNo",
foreignField: "regNo",
as: "h_bags"
}},
// unwind the `h_bags` array
{$unwind: '$h_bags'},
// filter the status of bags is `Accepted`
{$match: {'h_bags.status': 'Accepted'}}
]);
I'm trying to figure out how a json schema should be implemented (as standardized as possible).
I have noticed that if I define a schema for a form using the v4 draft, I cannot voice the requirements my project has. So I created a schema that uses the v4 schema ("$schema": "http://json-schema.org/draft-04/schema#"), and gave it a custom id for the project, lets call it projectschema#. This schema validates, so all is good standard-wise. I have added two values to the type enum.
I then use this schema as $schema for another schema that describes form properties and validations, the formschema#. This schema too validates, this time against the projectschema#.
Now, as documented on www.json-schema.org, there's also a hyper-schema which allows the definition of links. Useful, as I can define where to POST the form to, or even where to get valueSets to use in the form (i.e. a rest service to get a list of user titles).
However, the v4 schema itself does not support links. I see how the v4 hyper-schema draft does support links, and is referencing the v4 schema draft, but I cannot figure out how to implement the hyper-schema, which probably means I'm missing some fundamental part of the 'how to use and implement json schema' knowledge.
I found the following on http://json-schema.org/latest/json-schema-hypermedia.html:
JSON Schema is a JSON based format for defining the structure of JSON data. This document specifies hyperlink- and hypermedia-related keywords of JSON Schema.
The term JSON Hyper-Schema is used to refer to a JSON Schema that uses these keywords.
If the draft hyper-schema uses the draft schema keywords, then why is the 'links' keyword nowhere to be found in the schema?
Is my (or any) custom schema actually a hyper schema? And if so, is anything that implements a (custom or draft) json schema called a hyper schema?
I could fire off a hundred questions. Main question: what is the relation between a Schema and a Hyper Schema, and how should I implement a schema for a form that needs more types than defined in the v4 draft?
Sorry for the length of this answer. Hopefully it's helpful.
I too struggled to understand how to validate a particular link in Hyper-Schema so I implemented each link as a base JSON Schema then tied each link together with a Hyper-Schema.
Definitions (definitions.json):
{
"$schema" : "http://json-schema.org/schema#",
"definitions" : {
"id" : {
"type" : "integer",
"minimum" : 1,
"exclusiveMinimum" : false
},
"foreign_key_id" : {
"$ref" : "#/definitions/id"
},
"season_name" : {
"type" : "string",
"minLength" : 1,
"maxLength" : 1,
"pattern" : "^[A-T]{1,1}$"
},
"currency" : {
"type" : "integer"
},
"shares" : {
"type" : "integer"
},
"username" : {
"type" : "string",
"minLength" : 1,
"maxLength" : 19,
"pattern" : "^[^ ]{1,19}$"
},
"name" : {
"type" : "string",
"minLength" : 1,
"maxLength" : 64,
"pattern" : "^[A-Za-z0-9][A-Za-z0-9_\\- ]*$"
},
"email" : {
"type" : "string",
"format" : "email"
},
"timestamp" : {
"type" : "string",
"format" : "date-time"
}
}
}
Base object schema:
{
"$schema" : "http://json-schema.org/schema#",
"type" : "object",
"properties" : {
"id" : { "$ref" : "definitions.json#/definitions/id" },
"season_name" : { "$ref" : "definitions.json#/definitions/season_name" },
"user_id" : { "$ref" : "definitions.json#/definitions/foreign_key_id" },
"coins" : { "$ref" : "definitions.json#/definitions/currency" },
"bonus_coins" : { "$ref" : "definitions.json#/definitions/currency" },
"created_at" : { "$ref" : "definitions.json#/definitions/timestamp" },
"updated_at" : { "$ref" : "definitions.json#/definitions/timestamp" }
},
"required" : [
"id",
"season_name",
"user_id",
"coins",
"bonus_coins",
"created_at",
"updated_at"
],
"additionalProperties" : false
}
POST schema (account_request_post.json):
{
"$schema" : "http://json-schema.org/schema#",
"type" : "object",
"properties" : {
"season_name" : { "$ref" : "definitions.json#/definitions/season_name" },
"user_id" : { "$ref" : "definitions.json#/definitions/foreign_key_id" }
},
"required" : [
"season_name",
"user_id"
],
"additionalProperties" : false
}
Hyper Schema:
{
"$schema" : "http://json-schema.org/schema#",
"type" : "object",
"links" : [
{
"description" : "Create a new account.",
"href" : "accounts",
"method" : "POST",
"rel" : "create",
"title" : "Create",
"schema" : { "$ref" : "account_request_post.json#" }
},
{
"description" : "List accounts.",
"href" : "accounts",
"method" : "GET",
"rel" : "index",
"title" : "List"
}
]
}
Json hyper-schema is a subset of Json-schema standard dedicated to hyperlink and hypermedia keywords and rules.
The "links" keyword is defined in the hyper-schema section of the draft. Indeed it is a part of json-schema (despite it is defined in a special draft section)
If your are defining an API interface, it is likely you want to use hyper-schema. If you are just defining validation contracts, plain Json-schema keywords are enough.
I'm trying to remove from MongoDB collection an object (not document) that meets specific value condition, in this case - "Accessible" : "null" - while keeping other instances of this objects. I tried db.collection.update({}, {$unset: { "Accessible":"null"}}, false, true) but it removed all objects with "Accessible" key.Thanks in advance
My MongoDB collection before update
{
"_id" : ObjectId("52e5f09e8f3d99e1046abccc"),
"Name" : "Skyline",
"Accessible" : "Y"
}
{
"_id" : ObjectId("52e5f09e8f3d99e1046abccd"),
"Name" : "Highland",
"Accessible" : "null"
}
Desired result:
{
"_id" : ObjectId("52e5f09e8f3d99e1046abccc"),
"Name" : "Skyline",
"Accessible" : "Y"
}
{
"_id" : ObjectId("52e5f09e8f3d99e1046abccd"),
"Name" : "Highland"
}
You need to first identify the documents you wish to update and then unset that specific field:
db.collection.update(
{"Accessible" : "null"},
{$unset: { "Accessible" : ""}},
{ multi: true }
)
Further documentation on $unset operator:
http://docs.mongodb.org/manual/reference/operator/update/unset/