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

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.

Related

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"
}
]
}

Salesforce JSON Nested Self-Related Objects?

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?

Get href value Json linking with HAL

Hi I try to figure out how to get the value of a link in the response of a request of this type :
{
"_links" : {
"self" : {"href" : "https://link.net/someInfo" },
"profile" : {"href" : "https://link.net"},
==> "https://link.net/item1" : {"href" : "https://thelinkIwanttohave.net"},
"https://link.net/item2" : {"href" : "https://link.net"},
},
"reference" : "723bb02f-8e24-11e6-9184-000000000000"
}
Following this (http://blog.stateless.co/post/13296666138/json-linking-with-hal)
if I want to get the self href value. I can get it through :
json._links.self.href
But how can I get the href value of https://link.net/item1.
If I type :
json._links.https://link.net/item1.href
I got an Uncaught SyntaxError: Unexpected token. I can't find example of this.
Have a look at property accessors, you can access javascript properties in two ways:
object.property
object["property"]
So in your case try:
json._links['https://link.net/item1'].href

How can I use AJAX with web methods to send JSON objects to a jQuery DataTable using asp.net?

So I have the jQuery datatable using AJAX to call for the JSON in this format.
$(document).ready(function () {
$('#test').DataTable({
ajax:{
url:"players.json",
dataSrc:""
},
columns: [
{data: "id"},
{ data: "player" },
{ data: "points" },
{ data: "steals" },
{ data: "blocks" },
{ data: "assists" },
{ data: "MPG" },
{ data: "shot %" },
{ data: "3 %" }
]
});
});
My aspx.cs file has a method to create the JSON file which works.
[System.Web.Services.WebMethod]
public static void loadTable()
{
NBAPlayerRepository players = new NBAPlayerRepository();
DataTable dt = players.GetAll();
var json = dt.ToJson();
System.IO.File.WriteAllText(#"C:\Users\wheres\Downloads\nbaStats\nbaStats\nbaStats\players.json", json);
}
And the JSON looks like this:
[{"id" : "67926aa7-46b7-4418-96db-fc7e5216aac4","playername" : "Wilson Heres","points" : "34534","steals" : "34","blocks" : "34","assists" : "343","mpg" : "343","shootingpercentage" : "33.3429985046387","threepointpercentage" : "33.3429985046387"}
,{"id" : "6dc42e0b-8750-463d-a9ef-5a025a27154b","playername" : "Wilson Heres","points" : "34534","steals" : "34","blocks" : "34","assists" : "343","mpg" : "343","shootingpercentage" : "33.3429985046387","threepointpercentage" : "343.334014892578"}
,{"id" : "f727130c-5b94-4730-a653-cfb603c73b8a","playername" : "Wilson Heres","points" : "34534","steals" : "34","blocks" : "34","assists" : "343","mpg" : "343","shootingpercentage" : "33.3429985046387","threepointpercentage" : "343.334014892578"}
]
But now I am getting this error "jquery.dataTables.min.js:48 Uncaught TypeError: Cannot read property 'length' of undefined"
Edit: This all works now. Just had to add dataSrc:""
Cleaned-up version of your DataTables initialization
$(document).ready(function () {
$('#test').DataTable({
ajax: {
url: "players.aspx/loadTable"
},
columns: [
{ data: "id" },
{ data: "player" },
{ data: "points" },
{ data: "steals" },
{ data: "blocks" },
{ data: "assists" },
{ data: "MPG" },
{ data: "Shot %" },
{ data: "3 %" },
]
});
});
This may seem like a lot of stuff was removed from your code, so let me make some explanations/assumptions about what was changed.
Assumptions
First, an assumption: DataTables will always try to use a GET request, not a POST when first getting the data from the table, so make sure that your data processing code expects that.
I also am assuming that you have no strong desire to have your Ajax separate from your initialization and that was just how you decided to do it as a first attempt. If that is the case, let me know and I'll update the code to match that.
Explanation
Your formatting is incorrect in some areas and against DataTables standard in others, so this version should do most of what you were trying to do in a much simpler form. A lot of your Ajax options are unnecessary because they are already the default (JSON for the data type, for example), which is why they have been removed.
One nice thing about DataTables is that you can have the Ajax options in the initialization, which is what I have done here. You do lose the success and failure callbacks but I think that for debugging purposes they aren't really necessary and having any extra code increases the amount of stuff to debug (I don't even use those callbacks in most of my final code).
Most of the other changes were mainly incorrect nomenclature (e.g. data instead of title in the column definitions.
Disclaimer
While I would recommend these changes in general just to improve your code, I would make sure to take a look at the format of the JSON that is being sent to and from the server. If you don't know how to do that I'd recommend downloading Fiddler to 'listen in' on the JSON data being sent.
If your JSON is wrong, no amount of changes to the page are going to make the table appear.
Finally, make sure you have no JS errors on the page. Use your browser's developer console (F12) to check that.
If you do find any JS errors, post them in your question. I'd also recommend posting the JSON data being sent to the question as well so that we can ensure the format is correct.

AngularJS http post not sending object as expected

I'm trying to post changes to a row in a table via a form in AngularJS. However, it looks like the data selected in the view is not pushed to the object correctly, and I get a 500 error when posting on my real dev environment.
Here's my code
Edit:
The format I would like to post is: { "id" : "1", "name" : "5k", "distance" : "3.1 miles", "date" : "3/14/2014", "time" : "8 am" }
If I change your save button to run the save() method on the scope, then the following is the request payload to some/url.
{
"name":{
"type":"Afternoon",
"_embedded":{
"event":{
"_links":{
"self":{
"href":"www.example.com/events/shift/2"
}
},
"name":"10k",
"distance":"6.2 miles"
}
}
}
}
This is exactly the same data as is in your scope.
As such, I would suggest your server code is doing something wrong with the data..