AngularJS http post not sending object as expected - json

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..

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 ?

Zapier identifying JSON data as string

My question is how can I pull the values for events.payload.media.name?
I am posting to a raw zapier webhook from another app. If I check it using requestb.in it comes through as "Content-Type: application/json". The output is also validating as JSON.
{
"hook":{
"uuid":"1asdfasd5-asdf-4f52-bd31-c7a544897808"
},
"events":[
{
"uuid":"0asdfasdfasdf0",
"type":"viewing_session.turnstile.converted",
"payload":{
"visitor":{
"id":"28b606b_7853753-3868-4f07-9543-70da084452cc-7442322af-407bdc31d8fc-2739"
},
"viewing_session":{
"id":"154284_b40c5358-1faf-40e9-a44e-60aa641a11cd-fd3c69d8d-302471c603f4-8245"
},
"name":null,
"media":{
"url":"https://things.wistia.com/medias/asdfasdf",
"thumbnail":{
"url":"http://embed.wistia.com/deliveries/asdfasdfasdfasdfasdfasdfasd.jpg?image_crop_resized=200x120"
},
"name":"this is what I want!",
"id":"asdfasdfasdf",
"duration":52.872
},
"last_name":null,
"foreign_data":{
},
"first_name":null,
"email":"email#email.com"
},
"metadata":{
"account_id":"asdfasdfasdf"
},
"generated_at":"2017-05-02T07:31:08Z"
}
]
}
However, when I check the typeof data in the output it is telling me that it is a string (see my code to check below). This prevents me from pulling the info out of it using:
return {stuff: typeof inputData.thing.events.payload.media.name};
I'm a huge noob, am I missing something fundamental here?
screenshot to check typeof data
events is an array, so you would access it like this:
inputData.thing.events[0].payload.media.name
is there a way to have the whole payload without creating a new App in Zapier? inputData didn't work

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?

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.

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.