Salesforce JSON Nested Self-Related Objects? - json

Looks like I need some help here. Salesforce documentation and multiple google searches not gave me an answer.
Problem description:
I'm trying to insert (POST) nested self-related records using REST with JSON, but every time this error appears:
{
"message": "Cannot deserialize instance of <unknown> from FIELD_NAME value records or request may be missing a required field",
"errorCode": "JSON_PARSER_ERROR"
}
JSON:
{
"records" :[{
"attributes" : {"type" : "Test_Obj1__c", "referenceId" : "ref1"},
"name" : "integr parent",
"Test_Obj1__r" : {
"records" : [{
"attributes" : {"type" : "Test_Obj1__c", "referenceId" : "ref2"},
"name" : "integr child"
}]
}
}]
}
Request:
https://mySandboxInstance.com/services/data/v37.0/composite/tree/Test_Obj1__c/
Authorization: OAuth security_token
Content-Type: application/json
So, as you can see Test_Obj1__c is self-related and Child Relationship Name is "Test_Obj1".
I've tested with different self-related objects - it gives same result.
If I'm changing Test_Obj1__r to relation with different child object - it works fine.
Is there any way to insert nested self-related objects through one REST request?

Related

How to update the whole array of objects using Put http request with a json raw body?

I have a json Array something like below and I want to make an update to the whole list without passing by a specefic ID.
List before update
[ { id:"1", name : "name_1" }, { id:"2", name : "name_2" } ]
Wanted list after update
[ { id:"1", name : "name_3" }, { id:"2", name : "name_4" } ]
I tried using PUT request and passing the target list in a json raw body, but it always return "404 not found"
I tried it with Postman but it returns the same error. Is it possible to do like so ?

tMongoDBOutput - Configuring JSON tree

Trying to configure JSON tree for tMongoDBOutput. Only 1 element is getting created in subelement array. Can someone please give a example of configuring the JSON tree. Requirement is one document can have multiple nested sub documents. Medical_records can have multiple sub documents, but only 1 sub document is getting created now skipping the rest.
Resulting JSON in MongoDB as follows
{
"first_name" : "testname",
"middle_name" : [],
"last_name" : "test",
"medical_records" : [
{
"dateofuploading" : "2016-09-29 12:49:21.5",
"filename" : "demo.pdf",
"isautogenerated" : "1",
"recordid" : "123"
}
]
}
enter image description hereIf you want to have multiple sub documents in array,You need to use the group by operation in the advance settings for the element inside the array .

Resolve error on deep insert of navigation property Dynamics WebAPI

I am using the Microsoft Dynamics Web API to write data to an entity in Microsoft Dynamics 365. When I try to do a deep insert I am receiving the error
An undeclared property 'ccseq_employeeid' which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values.
Why am I receiving this error and how can I resolve the error?
JSON
{
"ccseq_importdate" : "2017-05-28T04:00:00Z",
"ccseq_month" : "1",
"ccseq_year" : "2017",
"ccseq_name" : "Test",
"ccseq_status" : "100000000", "ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID" :
[
{
"ccseq_employeeid#odata.bind": "/systemusers(6d2fd71b-32d1-dd11-a4f5-001a6449bbe7)",
"ccseq_clientid#odata.bind": "/ccseq_clients(663ebd00-73b9-4faf-90ed-f56bb9c2dc9b)",
"ccseq_navemployeeid" : "11111",
"ccseq_employeefirstname" : "John"
}
]
}
ExpenseTransactionSet is the parent of ExpenseTransaction meaning that ExpenseTransaction has a lookup to ExpenseTransactionSet. ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID is one to many relationship. systemuser and ccseq_clients are separate entities that are lookups in ExpenseTransaction.
I've also tried the below variations on the "ccseq_employeeid#odata.bind"
objectid_systemuser#odata.bind
objectid_ccseq_employeeid#odata.bind
ccseq_employeeid#data.bind
ccseq_employeeid#odata.bind : systemusers()
ccseq_employeeid_systemusers#odata.bind
systemuserid_systemusers#odata.bind
I have seen this question and this question and tried the suggested resolutions without success.
I discovered the answer reading this thread. The correct syntax for a Navigation Property in a deep insert is to use the Child Entity Name followed by brackets with the field name. The json needs to be changed to the below
{
"ccseq_importdate" : "2017-05-28T04:00:00Z",
"ccseq_month" : "1",
"ccseq_year" : "2017",
"ccseq_name" : "Test",
"ccseq_status" : "100000000",
"ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID" :
[
{
// Next two lines are changed
"ExpenseTransaction[ccseq_employeeid#odata.bind]": "/systemusers(6d2fd71b-32d1-dd11-a4f5-001a6449bbe7)",
"ExpenseTransaction[ccseq_clientid#odata.bind]": "/ccseq_clients(663ebd00-73b9-4faf-90ed-f56bb9c2dc9b)",
"ccseq_navemployeeid" : "11111",
"ccseq_employeefirstname" : "John"
}
]
}
In the metadata document {org-url}/api/data/v8.0/$metadata, can you check the element-type of the collection-valued navigation property ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID?
Is it the same type which has ccseq_employeeid as its navigation property? If not, and the property ccseq_employeeid belongs to the derived type, you may need to annotate the navigation property object as below:
{
"ccseq_importdate" : "2017-05-28T04:00:00Z",
"ccseq_month" : "1",
"ccseq_year" : "2017",
"ccseq_name" : "Test",
"ccseq_status" : "100000000",
"ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID" :
[
{
"#odata.type": "Microsoft.Dynamics.CRM.ccseq_navemployee",
"ccseq_employeeid#odata.bind": "/systemusers(6d2fd71b-32d1-dd11-a4f5-001a6449bbe7)",
"ccseq_clientid#odata.bind": "/ccseq_clients(663ebd00-73b9-4faf-90ed-f56bb9c2dc9b)",
"ccseq_navemployeeid" : "11111",
"ccseq_employeefirstname" : "John"
}
]
}

Unable to capture JSON response in Vugen using Web http/html

Step Functionality: creation of draft; success status shown by creation of draft id in server response
Call:
web_custom_request("draft",
"URL=https://xxx.yyy.com/__services/v2/rest/draft",
"Method=POST",
"Resource=0",
"RecContentType=text/xml",
"Referer=https://xxx.yyy.com/blog/create-post.jspa?containerType=14&containerID=1",
"Snapshot=t7.inf",
"Mode=HTML",
"EncType=application/json; charset=utf-8",
"Body={\"objectType\":38,\"draftObjectType\":2020,\"draftObjectID\":137742,\"subject\":\"perf test 2\",\"body\":\"<body><p>test data</p></body>\",\"properties\":{\"publishBar\":{\"container\":{\"objectType\":\"37\",\"objectID\":\"90094\"},\"visibility\":\"all\",\"commentStatus\":\"2\",\"blogPublishOption\":false,\"publishDate\":{\"selectedDate\":\"{p_Date}\",\"selectedHour\":\"1\",\"selectedMinute\":\"0\",\"selectedPeriod\":\"AM\"}}}}",
LAST);
Data correlated: draft ID; response of this call
Data parameterized: selectedDate
remaining values are constant
Recording response body:
{
"id" : 2814,
"objectType" : 38,
"draftObjectType" : 2020,
"draftObjectID" : 137742,
"subject" : "perf test",
"body" : "<body><p>this i</p></body>",
"modificationDate" : "2015-10-12T13:44:00.854+0000",
"properties" : {
"publishBar" : {
"container" : {
"objectType" : "37",
"objectID" : "90094"
},
"visibility" : "all",
"commentStatus" : "2",
"blogPublishOption" : false,
"publishDate" : {
"selectedDate" : "10/13/2015",
"selectedHour" : "1",
"selectedMinute" : "0",
"selectedPeriod" : "AM"
}
}
}
}
Error during replay:
{ "code" : 500, "message" :com.sun.istack.SAXException2: class java.util.LinkedHashMap nor any of its super class is known to this context.
javax.xml.bind.JAXBException: class java.util.LinkedHashMap nor any of its super class is known to this context." }
Kindly help.
It's obvious you're not correlating all that needs to be correlated.
Do some re-recordings and see what's different between the responses of each recording.
Without the complete script I can't say for sure, but at least change the following in your request:
"RecContentType=text/xml" to "RecContentType=application/json"
"Mode=HTML" to ""Mode=HTTP"
The 1st sets the expected response content type, and if it's not XML there might be problems. This is assuming the service responds with the correct content-type.
2nd sets the mode to HTTP as REST API responses usually do not need parsing of the content.

What is the correct way to use the fields request parameter when getting a list of StorageObjects from Google Cloud Storage?

I would like to do a lookup in the storage using the JSON API client library and only retrieve the name and generation of each object matching a specific prefix but I am having issues with the fields request parameter.
Executing the following returns the expected objects.
Storage.Objects.List listObjects = null;
listObjects.setVersions(true);
listObjects.setPrefix(myprefix);
URL being created for the request in com.google.api.client.http.HttpRequest is https://www.googleapis.com/storage/v1beta2/b/mybucketname/o?prefix=myprefix&versions=true
However, when I add
listObjects.setFields("name,generation");
with URL created being https://www.googleapis.com/storage/v1beta2/b/mybucketname/o?fields=name,generation&prefix=myprefix&versions=true the below is returned:
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"location" : "fields",
"locationType" : "parameter",
"message" : "Invalid field selection name",
"reason" : "invalidParameter"
} ],
"message" : "Invalid field selection name"
}
How am I supposed to be specifying the fields I want returned? Is the hierarchy of the fields I'm specifying not correct?
Thank you!
Ref:
Verified the composition of the URL based on this: https://developers.google.com/storage/docs/json_api/v1/how-tos/performance#partial
I think what you want is:
fields=items(generation,name)
or with the full URL:
https://www.googleapis.com/storage/v1beta2/b/mybucketname/o?fields=items(generation,name)&prefix=myprefix&versions=true
The APIs Explorer is a great tool for experimenting with request fields like this. It will generate the proper fields for you.