JSON server - Is it possible to update an object id? - json-server

Here is my db.json :
{
"users": [
{
"id": "1"
"name": "John"
}
]
}
I'd like to be able to update the user id by sending a PUT request on the existing user. But the following does not work:
Request URL :
PUT /users/1
with body:
{
"id": "2"
"name": "John"
}
Is there a way to update an object id?

If you are using PUT request means ,the request URL should be like this "PUT/users/1" .
Refer below mentioned image.
I'm using postman to send put request

This does not seem to be possible, as said in documentation:
Id values are not mutable. Any id value in the body of your PUT or
PATCH request will be ignored. Only a value set in a POST request will
be respected, but only if not already taken.

Related

How can I send an conditional GET method to elasticearch from postman?

I have a GET request with it's query body as shown below:
GET /courses/_search
{
"query": {
"bool": {
"must": [
{"match": {"teacher.keyword": "Andrew Ng"}}
]
}
}
}
In Postman, GET requests can not have a 'body'. so how can I send this request to the elasticsearch? How should I specify this neseted structure of the body in the request?
Use POST instead 😃
Elasticsearch is a bit more permissive and supports both GET and POST to send a request with a payload.

How to pass owner attribute when creating user story using Rally API?

I am trying to pass the owner attribute to create a user story in rally using rally API But I am encountering below error.
{
"CreateResult": {
"_rallyAPIMajor": "2",
"_rallyAPIMinor": "0",
"Errors": [
"Cannot parse object reference from \"{\"Owner\": {\"_refObjectName\": \"Ron\"}}\""
],
"Warnings": [
"Ignored JSON element HierarchicalRequirement.PortfolioItem during the processing of this request."
]
}
}
My request payload
{
"HierarchicalRequirement":{
"Name": "hello Wrold",
"Description":" 123 test description",
"Workspace": "/workspace/18686460234",
"Project":"/project/1025697468602323",
"PortfolioItem":"",
"Owner":{"_refObjectName":"Ron"},
"ScheduleState":"Defined"
}
}
Any thoughts?
In general, when referring to an object property that itself is an object (as in this case with the User object), you pass in the actual value of _ref, not another object. If you have previously been passed the reference to the user as a full blown URI, then you can still pass that in and the SDK will convert it to a _ref.
If you go to the webservice docs (https://rally1.rallydev.com/slm/doc/webservice/) for your subscription and go down to the User section, you can get the docs to fetch you some examples of users. The _ref will come back something like:
https://rally1.rallydev.com/slm/webservice/v2.0/user/39776836851
I believe that you can either use that, or just truncate it to the number at the end. So the code will need to be changed so that the Owner line reads:
"Owner" : "https://rally1.rallydev.com/slm/webservice/v2.0/user/39776836851"

Retrieve UserName from ServiceNow

I am able to retrieve records for a particular Incident ID using Invoke-RestMethod. However, while retrieving the data, values like Resolved To, Updated By, etc. get populated by a sysid.
Resolved By comes in this format:
https<!>://devinstance.servicenow.com/api/sysid, value= sysid
I would like to view the username instead of the sysid.
The 'User ID' (user_name) isn't on the Incident, it's on the sys_user table, so you'll have to dot-walk to it.
If you're using the table API, you'll need to specify a dot-walked field to return, using the sysparm_fields query parameter.
This is no problem, just specify your endpoint like this:
$uri = "https://YOUR_INSTANCE.service-now.com/api/now/table/incident?sysparm_query=number%3DINC0000001&sysparm_fields=resolved_by.user_name"
I've specified a query for a specific incident number is requested, but you can replace that with whatever your query is.The important part is sysparm_fields=resolved_by.user_name. You'll want to specify any other fields you need here, as well.
The JSON I get as a result of running this API call, is the following:
{
"result": [
{
"resolved_by.user_name": "admin"
}
]
}
Note the element name: "resolved_by.user_name".
Another option for doing this, would be to tell the API to return both display, and actual values by specifying the sysparm_display_value parameter and setting it to all to return both sys_id and display value, or just true to return only display values.
Your URI would then look like this:
https://dev12567.service-now.com/api/now/table/incident?sysparm_query=resolved_byISNOTEMPTY%5Enumber%3DINC0000001&sysparm_display_value=all
And your JSON would contain the following:
"number": {
"display_value": "INC0000001",
"value": "INC0000001"
},
"resolved_by": {
"display_value": "System Administrator",
"link": "https://YOUR_INSTANCE.service-now.com/api/now/table/sys_user/6816f79cc0a8016401c5a33be04be441",
"value": "6816f79cc0a8016401c5a33be04be441"
},
"sys_updated_by": {
"display_value": "admin",
"value": "admin"
},
This would be accessed by:
answer.result[n].resolved_by.display_value

Graph API get profile image from Comment object

As the Graph API documentation says, the /comment retreives a Comment Object, which contains a from attribute, which represents the user that made the comment. By default, that from attribute comes with an id and a name.
Although I know I can get the profile image with the id, it will depend on the access_token as the way would be like this:
return 'https://graph.facebook.com/' + id + '/picture?type=large&access_token=' + accessToken;
How can I do to get the profile img of the commentator without depending on the access_token? Because when the API retreives a User object, in the fields object, you can request { fields: "id,name,picture }. But how can i do to ask for the picture to the from attribute that comes in the Comment object? As this is not allowed { fields: "id,name,from.picture }
You should be able to ask for second level attributes
https://developers.facebook.com/docs/graph-api/using-graph-api/#fieldexpansion
$ fbapi '/v2.6/me/photos?fields=from{picture}' | jq '.data[0]'
{
"from": {
"picture": "https://scontent.xx.fbcdn.net/v/t1.0-1/xxxx/p50x50/xxxx.jpg",
"id": "9999999999"
},
"id": "000000000"
}

Can't post node that requires a pre assigned value with services api

I have setup a content type with a subject field that has pre assigned values in a dropdown field.
I am using the services api to post new content from a polymer app.
When I POST to the api I send the field structure and value in json but get and error.
"406 (Not Acceptable : An illegal choice has been detected. Please contact the site administrator.)"
Even though the object I am sending matches one of the required values in the field.
Do I need to prefix the value with something? I assume I'm posting to the right place to get that response but don't know why it would accept anything other than the string value.
Here is what I sent to the api which is picked up by my Charles proxy.
{
"node": {
"type": "case",
"title": "my case",
"language": "und",
"field_subject": {
"und": {
"0": {
"value": "subject1"
}
}
},
"body": {
"und": {
"0": {
"value": "my details of subject"
}
}
}
}
}
And here is an example of what I have setup in my Drupal field
subject1| first
subject2| second
subject3| third
subject4| forth
For anyone else with the same problem, this subject is poorly documented, but the answer is simple, my subject did not need the value key despite devel suggesting thats how it would be formatted.
"field_subject": {
"und": [
"subject1"
]
}
I could also shorten my code with "und" being an array.