Get href value Json linking with HAL - json

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

Related

"expression not allowed in userFilter" gooddata api

I'm receiving this response when I try to create a user filter in the GoodData API, does anybody knows what is this error and how to solve it?
{
"error" : {
"parameters" : [
"[/gdc/md/PROJECT_ID/obj/OBJECT_ID]=[/gdc/md/PROJECT_ID/obj/OBJECT_ID/elements?id=ELEMENT_ID] OR [/gdc/md/PROJECT_ID/obj/OBJECT_ID]=[/gdc/md/PROJECT_ID/obj/OBJECT_ID/elements?id=ELEMENT_ID]"
],
"requestId" : "REQUEST_ID",
"component" : "Resource::Obj::Service",
"errorClass" : "GDC::Exception::User",
"message" : "Expression not allowed in userFilter '%s'."
}
}
Well I was picking the wrong id, I was using de url value instead the "formOf" value found in the /gdc/md/PROJECT_ID/obj/OBJECT_ID

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?

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.

SyntaxError: Unexpected token )

I am posting this because I have not seen this exact question before, and I have had no luck going through previous posts.
I am creating a layout of an application called Exhibit, one that lays out my data on a timeline. The html code is structured for Exhibit.
My data is stored in a JSON file. I have checked this with JLint and it seems to be in the correct format. Yet I am thrown the above error regarding my JSON file.
Here is one object from my JSON file.
{
"items" : [
{
"url" : "http:\/\/twitter.com\/acarvin\/statuses\/32815014167445504",
"uri" : "file:\/\/\/C:\/Users\/david\/Documents\/Work\/Exhibit\/CAR\/item#%40acarvin%3A%20AlJaz%20showing%20huge%20crowds%20rushing%20down%20a%20Cairo%20street.%20\'It%20is%20an%20intense%20battle%20here.\'%20%23jan25",
"time" : "2011-02-02 14:58:03",
"date" : "2005",
"action" : "reporting",
"hour" : "14:58:03",
"role" : "reporter",
"username" : "acarvin",
"keywords" : [
"crowd",
" battle",
" al jazeera"
],
"ignoretime" : "2\/2\/2011 14:58:03",
"type" : "Item",
"label" : "#acarvin: AlJaz showing huge crowds rushing down a Cairo street. \'It is an intense battle here.\' #jan25",
"gender" : "male",
"location" : "talaat harb",
"origin" : "file:\/\/\/C:\/Users\/david\/Documents\/Work\/Exhibit\/CAR\/hands-on.html#%40acarvin%3A%20AlJaz%20showing%20huge%20crowds%20rushing%20down%20a%20Cairo%20street.%20\'It%20is%20an%20intense%20battle%20here.\'%20%23jan25"
}
]
}
Can anyone see what may be happening?
note: I specified the type of my data as application/json when I called it.
There are several invalid escapes in your strings in the form \'. While those are valid in JavaScript strings (whether single-quoted or double-quoted), they are not valid JSON. In JSON, a ' is just a '.
With those in place, the string will not validate. With the extraneous \ removed, it will. (I used http://jsonlint.com to confirm.)

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.