I'm trying to structure a REST webservice but I don't know the correct way of returning the results. Could you please give me some hints?
/countries/{id_country}/cities/{id_cities}/categories/
Option 1:
Resource link and some parts of the resource description
[ { "id": 1,
"name": "cine",
"url": "http://domain/countries/1/cities/1/categories/1"
},
{ "id": 2,
"name": "restaurante",
"url": "http://domain/countries/1/cities/1/categories/2"
}
]
Option 2
Resources link
[ { "url": "http://domain/countries/1/universities/1/categories/1" },
{ "url": "http://domain/countries/1/universities/1/categories/2" },
]
Option 3
Resources description
[ { "id": 1,
"name": "cine",
"description": "text text",
"url": "http://domain/countries/1/cities/1/categories/1" },
{ "id": 2,
"name": "restaurante",
"description": "text text",
"url": "http://domain/countries/1/cities/1/categories/2" }
]
Related
long time lurker in the loopback posts. I'm finally getting around to implementing some CRUD stuff with relations but I'm having some issues.
I have a form model that has a hasMany relation with leverOnes
and levelOnes has a hasMany relation with levelTwos
the individual patches are working fine (for example, if I need to update a single levelOne), but I have a page where the client essentially updates a bunch of levelOnes and levelTwos for a single Form at the same time. I can't update the form with my relation directly.
the patch is taking place at /forms/{id} at the top level, and I am getting a 500 error because when I attempt to patch
"id": "acmeform1",
"name": "ACME Assessment",
"userId": "string",
"org": "Complaints Department",
"clientId": "user#acme.com",
"dueDate": "2022-03-25T18:25:55.734Z",
"readyForReview": true,
"workDriverOnes": [
{
"id": "21740e676035c083fc20004803e88380",
"name": "Governance and Culture",
"description": "Governance and Culture",
"formId": "acmeform1",
"workDriverTwos": [
{
"id": "21740e676035c083fc20004803e8925f",
"name": "Annual Compliance Plan",
"description": "Annual Compliance Plan",
"workDriverOneId": "21740e676035c083fc20004803e88380",
"unitsPerPeriod": 1,
"amount": 20,
"unitType": "Annually",
"ongoing": true,
"roles": [
{
"id": "36c5b6399e951d45a7179f10b1b2df28",
"demandAmount": 5,
"role": "VP - Grade 36 Manager",
"workDriverTwoId": "21740e676035c083fc20004803e8925f"
},
{
"id": "8b054a1cb5002b760d68695b29cf16f6",
"demandAmount": 10,
"role": "SVP - Director",
"workDriverTwoId": "21740e676035c083fc20004803e8925f"
},
{
"id": "b92d2ed082c108d76ee91887234c1b1e",
"demandAmount": 5,
"role": "VP - Grade 37 Manager",
"workDriverTwoId": "21740e676035c083fc20004803e8925f"
}
]
}
]
},
{
"id": "285deab3c703506ac7878327b06eb4bf",
"name": "Policy Governance",
"description": "Policy Governance",
"formId": "acmeform1",
"workDriverTwos": [
{
"id": "8403a66eab00b0de2d2131cfe8d51135",
"name": "Policies",
"description": "Policies",
"workDriverOneId": "285deab3c703506ac7878327b06eb4bf",
"unitsPerPeriod": 1,
"amount": 20,
"unitType": "# Policies",
"ongoing": true,
"roles": [
{
"id": "285deab3c703506ac7878327b06ed443",
"demandAmount": 6,
"role": "VP - Grade 36 Manager",
"workDriverTwoId": "8403a66eab00b0de2d2131cfe8d51135"
},
{
"id": "2e362351b4477cb26f61937a37db27cb",
"demandAmount": 6,
"role": "VP - Grade 37 Manager",
"workDriverTwoId": "8403a66eab00b0de2d2131cfe8d51135"
},
{
"id": "36c5b6399e951d45a7179f10b1b2e932",
"demandAmount": 6,
"role": "SVP - Director",
"workDriverTwoId": "8403a66eab00b0de2d2131cfe8d51135"
},
{
"id": "dd6a475d1ae8f76fc7e7835331a42ad5",
"demandAmount": 2,
"role": "VP - Grade 35 Manager",
"workDriverTwoId": "8403a66eab00b0de2d2131cfe8d51135"
}
]
}
]
},
{
"id": "dd6a475d1ae8f76fc7e7835331a411c6",
"name": "Monitoring",
"description": "Monitoring",
"formId": "acmeform1",
"workDriverTwos": [
{
"id": "dd6a475d1ae8f76fc7e7835331a445a5",
"name": "Monitoring Scripts and Monitoring Plan Development and Drafting",
"description": "Monitoring Scripts",
"workDriverOneId": "dd6a475d1ae8f76fc7e7835331a411c6",
"unitsPerPeriod": 3,
"amount": 1,
"unitType": "# Monitoring Reviews",
"ongoing": true,
"roles": [
{
"id": "36c5b6399e951d45a7179f10b1b2ff49",
"demandAmount": 0.3,
"role": "SVP - Director",
"workDriverTwoId": "dd6a475d1ae8f76fc7e7835331a445a5"
},
{
"id": "9bc41d8a3a9eb3a435d946d8049cc97a",
"demandAmount": 2.7,
"role": "VP - Grade 37 Manager",
"workDriverTwoId": "dd6a475d1ae8f76fc7e7835331a445a5"
}
]
}
]
}
]
}
It says that workDriverOnes is already a relation and I can't update it directly. Do I have to manually loop through my levelOnes and patch each one individually? Or can I batch update at the form level?
I have posted data(ex:title field) in different languages, when i try to filter the data in get request it is giving empty result
GET /rails:
My get request result is :
[
{
"id": 1,
"type": "channel",
"filter": [
1
],
"data": [
1
],
"status": 0,
"rows": 0,
"title": "string"
},
{
"id": 2,
"type": "appgg",
"filter": [
2
],
"data": [
2
],
"status": 1,
"rows": 2,
"title": "ಚಲನಚಿತ್ರ"
}
]
GET /rails?title=string
it is giving proper result:
[
{
"id": 1,
"type": "channel",
"filter": [
1
],
"data": [
1
],
"status": 0,
"rows": 0,
"title": "string"
}
]
when i try to filter title data other than english i am getting empty result
GET /rails?title=ಚಲನಚಿತ್ರ:
expected result :
[
{
"id": 2,
"type": "appgg",
"filter": [
2
],
"data": [
2
],
"status": 1,
"rows": 2,
"title": "ಚಲನಚಿತ್ರ"
}
]
Actual result:
[]
when I try to print request params in my django views like below:
title = self.request.query_params.getlist('title',None)
print(title)
I am getting the following log:
title filter �²¨�¿¤Í°
Django is unable to identify the language I am passing, How can I add multi-language support in Django?
Thanks
I have a loopback.io API with a MongoDB database.
I have a model called Project with 2 hasMany relationships
Project has many ProjectArticle objects
Project has many ProjectWorkHours objects
When I run I do a request: http://0.0.0.0:3000/api/Projects?filter[include][projectArticles]
I get the following response, which is good
{
"title": "Project 1",
"description": "My project number one",
"dateCreated": "2015-10-31T00:00:00.000Z",
"id": "5634b3af340faf570c7e70a8",
"projectArticles": [
{
"articleName": "brick",
"quantity": 5,
"unitPrice": 2,
"id": "5634b9ea5ab833960c8fbf6d",
"projectId": "5634b3af340faf570c7e70a8"
}
]
}
and when I do: http://0.0.0.0:3000/api/Projects?filter[include][workHours] I get the right answer:
{
"title": "Project 1",
"description": "My project number one",
"dateCreated": "2015-10-31T00:00:00.000Z",
"id": "5634b3af340faf570c7e70a8",
"workHours": [
{
"description": "blabla",
"startDate": "2015-10-31T00:00:00.000Z",
"endDate": "2015-10-31T00:00:00.000Z",
"id": "5634e11d5f6471f10d2e0dd7",
"workHourId": "5634b3af340faf570c7e70a8"
},
{
"description": "blabla 2",
"startDate": "2015-10-31T00:00:00.000Z",
"endDate": "2015-10-31T00:00:00.000Z",
"id": "5634e1265f6471f10d2e0dd8",
"workHourId": "5634b3af340faf570c7e70a8"
}
]
}
but how do i combine the two includes in one request? so I have the following result:
{
"title": "Project 1",
"description": "My project number one",
"dateCreated": "2015-10-31T00:00:00.000Z",
"id": "5634b3af340faf570c7e70a8",
"workHours": [
{
"description": "blabla",
"startDate": "2015-10-31T00:00:00.000Z",
"endDate": "2015-10-31T00:00:00.000Z",
"id": "5634e11d5f6471f10d2e0dd7",
"workHourId": "5634b3af340faf570c7e70a8"
},
{
"description": "blabla 2",
"startDate": "2015-10-31T00:00:00.000Z",
"endDate": "2015-10-31T00:00:00.000Z",
"id": "5634e1265f6471f10d2e0dd8",
"workHourId": "5634b3af340faf570c7e70a8"
}
],
"projectArticles": [
{
"articleName": "brick",
"quantity": 5,
"unitPrice": 2,
"id": "5634b9ea5ab833960c8fbf6d",
"projectId": "5634b3af340faf570c7e70a8"
}
]
}
I tried this: http://0.0.0.0:3000/api/Projects?filter[include][workHours]&[include][projectArticles] but it only applies the first one and the second filter is kind of ignored
any ideas?
I've found the syntax for doing it
http://0.0.0.0:3000/api/Projects?filter={"include":["workHours", "projectArticles"]}
Can anyone help me, When I request using link
https://graph.facebook.com/search?&limit=2&until=now&q=hi&type=post&access_token=AAAAAAITEghMBAIScEzst3h5VpV8pKZA7di2ZC3czxr5
Note: I am not giving valid token for security reason.
I always get the result for 27 Nov 2012, while I tried to search for latest post. Am I missing something? Please help.
Thanks in Advance.
RESULT I get:
{
"data": [
{
"id": "730221920_10151138508071921",
"from": {
"name": "Pinky Saowichit",
"id": "730221920"
},
"message": "\u0e2d\u0e32\u0e17\u0e34\u0e15\u0e22\u0e4c\u0e19\u0e35\u0e49\u0e2d\u0e32\u0e08\u0e44\u0e21\u0e48\u0e44\u0e14\u0e49\u0e2d\u0e2d\u0e31\u0e19\u0e1a\u0e48\u0e2d\u0e22\u0e46 \u0e19\u0e30\u0e04\u0e30 \u0e41\u0e1f\u0e19\u0e04\u0e25\u0e31\u0e1a \u0e43\u0e2b\u0e49\u0e23\u0e39\u0e49\u0e27\u0e48\u0e48\u0e32\u0e04\u0e34\u0e14\u0e16\u0e36\u0e07\u0e19\u0e30\u0e04\u0e30 \u0e41\u0e15\u0e48\u0e15\u0e2d\u0e19\u0e19\u0e35\u0e49\u0e40\u0e23\u0e32\u0e01\u0e33\u0e25\u0e31\u0e07\u0e04\u0e34\u0e14\u0e16\u0e36\u0e07\u0e04\u0e38\u0e13 \u0e04\u0e32\u0e19\u0e18\u0e35\u0e41\u0e25\u0e30\u0e40\u0e17\u0e40\u0e23\u0e0b\u0e48\u0e32\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e21\u0e32\u0e01\u0e46 \u0e2b\u0e38 \u0e2b\u0e38",
"privacy": {
"value": ""
},
"type": "status",
"status_type": "mobile_status_update",
"created_time": "2012-11-27T03:12:32+0000",
"updated_time": "2012-11-27T07:44:54+0000",
"likes": {
"data": [
{
"name": "Weniefredo Laud",
"id": "100004751890183"
},
{
"name": "\u0e1e\u0e23\u0e15 \u0e1c\u0e25\u0e14\u0e35",
"id": "100001056963372"
},
{
"name": "\u0e08\u0e23\u0e34\u0e0d\u0e32 \u0e25\u0e2d\u0e27",
"id": "100000046347271"
},
{
"name": "Noolek Tikamborn",
"id": "100003048464258"
}
],
"count": 6
}
},
{
"id": "100003971930240_283727615063091",
"from": {
"name": "Mariana Salcedo",
"id": "100003971930240"
},
"story": "Mariana Salcedo shared a link.",
"picture": "http://external.ak.fbcdn.net/safe_image.php?d=AQASxQms6c0xFkdO&w=90&h=90&url=http\u00253A\u00252F\u00252Fask.fm\u00252Fimages\u00252F50x50.gif",
"link": "http://ask.fm/marianasalcedo/answer/15735435637",
"name": "CRUSH hi",
"caption": "jajajajaja que enfadosa erees!",
"icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yN/x/aS8ecmYRys0.gif",
"privacy": {
"value": ""
},
"type": "link",
"status_type": "shared_story",
"application": {
"name": "Ask.fm",
"id": "129215213762342"
},
"created_time": "2012-11-27T03:11:38+0000",
"updated_time": "2012-11-27T03:11:38+0000"
}
],
"paging": {
"previous": "https://graph.facebook.com/search?q=hi&limit=2&type=post&access_token=AAAAAAITEghMBAIScEzst3h5VpV8pKZA7di2ZC3czxr5ANnvKPPc1wqYJJZAANd9PI0NKLX5Xk5ReRX3T01iim8BoJp6r16itU8vPxRP&since=1353985952&__previous=1",
"next": "https://graph.facebook.com/search?q=hi&limit=2&type=post&access_token=AAAAAAITEghMBAIScEzst3h5VpV8pKZA7di2ZC3czxr5ANnvKPPc1wqYJJZAANd9PI0NKLX5Xk5ReRX3T01iim8Bo&until=1353985897"
}
}
My application creates posts on user's wall, but it's marked as link.
I see that other applications doing same thing but for some reason facebook don't mark their posts as links. Tried to find the difference between them and me in graph api explorer, and the only difference is status_type attribute (this is not even documented). Mine set to "shared_story" and in other applications is "app_created_story". Tried to set it manualy but facebook still use shared_story even if I set it to app_created_story
Data from graph api explorer (first is my application)
[{
"id": "100001302536317_168939309896943",
"from": {
"name": "Андрей Реаскович",
"id": "100001302536317"
},
"story": "Андрей Реаскович shared a link.",
"story_tags": {
"0": [
{
"id": "100001302536317",
"name": "Андрей Реаскович",
"offset": 0,
"length": 16,
"type": "user"
}
]
},
"picture": "http://external.ak.fbcdn.net/safe_image.php?d=AQBcrRQnipKHB6g6&w=90&h=90&url=http%3A%2F%2Fstatic.jackpotrush.com%2Fimages%2Fviral%2Fgames%2Fjoker_jester.png",
"link": "http://apps.facebook.com/jackrush/?ref=bonus-game",
"name": "I Won Big on a Bonus Round at Jackpot Rush!",
"caption": " ",
"description": "I Just Won 200 Coins at a Jackpot Rush Bonus Round and it Feels Amazing!",
"icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/100001302536317/posts/168939309896943"
},
{
"name": "Like",
"link": "http://www.facebook.com/100001302536317/posts/168939309896943"
}
],
"privacy": {
"description": "Only Me",
"value": "SELF"
},
"type": "link",
"status_type": "shared_story",
"application": {
"name": "Jackrush Development",
"namespace": "jackrush",
"id": "434595133235542"
},
"created_time": "2012-11-12T08:48:18+0000",
"updated_time": "2012-11-12T08:48:18+0000",
"comments": {
"count": 0
}
},
{
"id": "100001302536317_420171444702936",
"from": {
"name": "Андрей Реаскович",
"id": "100001302536317"
},
"picture": "http://platform.ak.fbcdn.net/www/app_full_proxy.php?app=242829452408559&v=1&size=z&cksum=cd0fa7a15202d05700bf1464fd989d42&src=http%3A%2F%2Fc.cdn.blueshellgames.com%2Fs%2F%3Aac05b878%2Fmonte%2Fi%2Ffeed_story_image-logo_black.png",
"link": "http://apps.facebook.com/luckyslotsgame/?action=shareLevelUpReward&posterID=fb%3A100001302536317&k_utag=df3f4636aabab65e&levelUpToken=6553%3AsVFCJmW43zW_Nni9vBB9xg%3D%3D&level=4&refID=fb%3A100001302536317&utm_medium=viral&utm_source=levelUp",
"name": "First 5 Clickers get 150 Free Coins!",
"caption": "Андрей just reached level 4 and is giving away 150 Free Coins to celebrate!",
"description": "Play the best slots on Facebook! Get free chips daily! Unlock new slot machines and new bonus games! Don't miss out, play now!",
"icon": "http://photos-d.ak.fbcdn.net/photos-ak-snc7/v85006/51/242829452408559/app_2_242829452408559_9481.gif",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/100001302536317/posts/420171444702936"
},
{
"name": "Like",
"link": "http://www.facebook.com/100001302536317/posts/420171444702936"
},
{
"name": "Claim BONUS Coins",
"link": "http://apps.facebook.com/luckyslotsgame/?action=shareLevelUpReward&posterID=fb%3A100001302536317&k_utag=df3f4636aabab65e&levelUpToken=6553%3AsVFCJmW43zW_Nni9vBB9xg%3D%3D&level=4&refID=fb%3A100001302536317&utm_medium=viral&utm_source=levelUp"
}
],
"privacy": {
"description": "Public",
"value": "EVERYONE"
},
"type": "link",
"status_type": "app_created_story",
"application": {
"name": "Lucky Slots",
"namespace": "luckyslotsgame",
"id": "242829452408559"
},
"created_time": "2012-11-12T08:13:25+0000",
"updated_time": "2012-11-12T08:13:25+0000",
"comments": {
"count": 0
}
}]