Show user rights and status for a REST resource - web-services

An user can have different rights to a REST resource. Like delete or edit the resource. Also child resources can have different user rights.
Example:
GET /cats -> return all cats
GET /cats/{id} -> return cat {id}
UPDATE /cats/{id} -> update cat {id}
POST /cats/{id}/like -> create a like to the cat {id}
DELETE /cats/{id}/like -> delete your like to the cat {id}
When an user requests a cat resource I want to show him the rights (allowed actions) and the status of the object.
In this example:
Is the user allowed to update the cat?
Is the user allowed to like the cat?
Does the user already like the cat?
Our UI should use this information to show allowed actions for an objects:
Update button
Like button
Dislike button
How can I add this information to my resource response. It should be possible to add the information to one resource, but also to a list of objects.
I thought about Links in the http header for all allowed actions. But this would only be possible for one object. Is their a better solution?

I'm unclear on why you can't include collection-specific links in the header of the response containing the collection. I'll take you at your word that that's not possible, but it seems like it should be an option.
Another option is to use an envelope around your response data. That will let you include metadata, including links, at the collection level.
GET /cats?owner=12
{
"totalRecords": 2,
"links": [ ... ],
"records": [ ... ]
}
EDIT (based on comment)
You should add a links property to the cat representation, either as an envelope or as a direct property. So your cat would look like:
GET /cats/354
{
"name": "Poke",
...,
"links": [
{ "rel": "like", "href": "/cats/12/like" },
....
]
}
Then, each cat in your collection will have the relevant links associated with it. This is a generally accepted alternative to using link headers.
Variations:
Some people like including the verb in the link resource, such as { "rel": "like", "verb": "POST", "href": "/cats/12/like" }
Some people like making the ref the name of the link property, such as "links": { "like": "/cats/12/like", "delete": "/cats/12" }

Related

Create a Sharepoint list in a specific folder with Microsoft graph api

Premise:
I have a folder under the sharepoint site for e.g.
https://... <mycompany-sharepoint-site.com>/
under which we have folder so my url is something like
https://... <mycompany-sharepoint-site.com>/Documents/Sub_folder_1/Sub_folder_2
pertaining to our project.
I need to be able to create a Sharepoint list in the Sub_folder_2 - folder and not at the root level.
With Sharepoint - GraphApi - create list api url
POST https://graph.microsoft.com/v1.0/sites/{site-id}/lists
I will ONLY be able to create at the <mycompany-sharepoint-site.com> level (i.e. at the root level) which is not what I want.
FYI, I already tried (on Postman) to go with the drives//items/<folder_id> - route or I should say attempted to do so but failed.
Any help is greatly appreciated.
If you want to use Graph API to create a folder in SharePoint, please use the following query:
POST /groups/{group-id}/drive/items/{parent-item-id}/children
For more information: https://learn.microsoft.com/en-us/graph/api/driveitem-post-children?view=graph-rest-1.0&tabs=http#http-request
Hope this is helpful.
I don't think that SharePoint supports creating a list inside the folder but you can at least try to create a list and specify the path in the parent reference.
You need to find out the drive id.
POST https://graph.microsoft.com/v1.0/sites/{site_id}/lists
{
"displayName": "Test",
"columns": [
{
"name": "Column1",
"text": {}
},
{
"name": "Column2",
"number": {}
}
],
"list": {
"template": "genericList"
},
"parentReference": {
"driveType": "documentLibrary",
"driveId": "{drive_id}",
"path": "/drives/{drive_id}/root:/Documents/Sub_folder_1/Sub_folder_2"
# or
# "path": "/drives/{drive_id}/root:/Sub_folder_1/Sub_folder_2"
}
}
I don't think it's even possible at all, did you succeed that manually?

Facebook graph api. how to list all pages that my app is subscribed to?

So I am aware of how to check each page to get a list of all subscribed apps.
But I would like to get a list of all pages my app has real time update subscriptions for?
so i have tried this
https://graph.facebook.com/v2.5/$app_id/subscriptions?access_token=$app_token
but this just brings back basic info on the app.
I would like a list of pages that it has subscriptions to already?
Can anyone help?
This doesn't look to be possible.
Endpoint you're using - https://developers.facebook.com/docs/graph-api/reference/v2.8/app/subscriptions - is to get list of application webhooks (callback_url and type of changes), which are called subscriptions for some reason. It's not about pages that subscribed to this webhook (or this app in general).
Overall, even in https://developers.facebook.com/apps/ for your app, under e.g. Messenger tab, you will only see subset of all pages that subscribed to this app. The visible subset is limited by your facebook user account permissions, presumably only show pages that you're either Admin or Editor.
Therefore, if such call would be possible, it would be somehow tied to User Access Token as well, not only app token.
You can do this here: https://developers.facebook.com/tools/explorer
Once logged, you can click on right button and select "Get User Access Token". You will need at least manage_pages or pages_show_list permission to accomplish this.
Now, all you have to do is call this endpoint: /me/accounts.
It should list all subscribed pages on your app.
Hope it helps.
As per
https://developers.facebook.com/docs/facebook-login/access-tokens/#apptokens
it is possible (graph api):
GET /oauth/access_token
?client_id={app-id}
&client_secret={app-secret}
&grant_type=client_credentials
And then /<app_id>/subscriptions
which returns something like:
{
"data": [
{
"object": "application",
"callback_url": "https:...",
"active": true,
"fields": [
{
"name": "ads_rules_engine",
"version": "v2.9"
}
]
},
{
"object": "page",
"callback_url": "https://...",
"active": true,
"fields": [
{
"name": "leadgen",
"version": "v2.5"
}
]
}
]
}

Getting number of page likes, post shares and website clicks

How can I get number of page likes, post shares and website clicks aggregated by ad group. Post comments and post likes are fetched through field 'inline_actions' - https://developers.facebook.com/docs/reference/ads-api/adreportstats#columns (/reportstats/date_preset=yesterday&data_columns=['adgroup_id','inline_actions']&actions_group_by=['action_type']). I need a way to fetch these report items using api, just like they are returned using https://www.facebook.com/ads/manage/reporting.php.
To get data per adgroup level you must include adgroup_id or adgroup_name in data_columns - as you're doing.
Comments, Likes and many other actions are returned in column actions
You can specify which actions types you're interested in by specifying filters:
filters=[
{
"field": "action_type",
"type": "in",
"value": [
"like",
"page_engagement",
"post_engagement",
"post_like",
"comment",
"games.plays",
"post",
"photo_view",
"link_click",
"receive_offer",
"checkin",
"mention",
"tab_view",
"vote",
"follow",
"gift_sale",
"video_play",
"video_view",
"offsite_conversion",
"offsite_conversion.checkout",
"offsite_conversion.registration",
"offsite_conversion.lead",
"offsite_conversion.key_page_view",
"offsite_conversion.add_to_cart",
"offsite_conversion.other",
"app_install",
"app_engagement",
"app_story",
"app_use",
"credit_spent",
"mobile_app_install",
"app_custom_event",
"app_custom_event.fb_mobile_activate_app",
"app_custom_event.fb_mobile_complete_registration",
"app_custom_event.fb_mobile_content_view",
"app_custom_event.fb_mobile_search",
"app_custom_event.fb_mobile_rate",
"app_custom_event.fb_mobile_tutorial_completion",
"app_custom_event.fb_mobile_add_to_cart",
"app_custom_event.fb_mobile_add_to_wishlist",
"app_custom_event.fb_mobile_initiated_checkout",
"app_custom_event.fb_mobile_add_payment_info",
"app_custom_event.fb_mobile_purchase",
"app_custom_event.fb_mobile_level_achieved",
"app_custom_event.fb_mobile_achievement_unlocked",
"app_custom_event.fb_mobile_spent_credits",
"app_custom_event.other",
"rsvp"
]
}
]
However that's optional IIRC, API should send you all non-zero actions by default.

Get total number of Custom Actions on Open Graph Object

I want to access number of custom actions (that I've defined) done on my Open Graph object. Facebook will return number of Like actions in response(like this) but they don't include number of custom actions.
Apps can retrieve actions published for the authorized user. For example, a Recipe app can retrieve all the recipes I've cooked or plan on cooking and customize the app experience based the data.
This API returns the action’s metadata including timestamps along with custom properties and their values. Objects referenced from an action are returned a single level deep.
GET /{action-instance-id}
The following retrieves a specific action instance
https://graph.facebook.com/{action-instance-id}?access_token=USER_ACCESS_TOKEN
Response
{
"id": "1538292028372"
"start_time": 1303502229,
"end_time": 1303513029,
"data": {
"type": "recipebox:recipe",
"url": "http://www.example.com/pumpkinpie.html",
"id": "1234567890",
"title": "Pumpkin Pie"
},
}
The above content is from FB Documentaion

Can we post Actions on an object outside of the app (ie FB Page, FB Place)?

Is it at all possible to post an action (owned by the app) to an object (NOT owned by the app)? Specifically on Faceook Page and Places, objects owned by FB.
For example I want to create an action called "shop", so that I can create the action
"John drank *Coke*"
in which Coke refers to the FB Page.
I have done a test via the Graph API Explorer and it seems that the app's action POST must refer to an object also owned by the same app. Mind you, I also do not know what shud be syntax to refer to objects owned by FB.
You can tag a place to a post but it will simply prefix it with " -at Walmart"
Yes, this is possible. To set the "at Walmart" part, set the action's "place" field when creating an action via a POST. For example, you can pass this:
?place=https://www.facebook.com/pages/Pizzeria-Delfina/53645450697
which should result in setting the place on an action like:
"place": {
"location": {
"city": "San Francisco, CA",
"zip": "94110",
"country": 398,
"region": 0,
"address": "3611 18th Street/2406 California St.",
"id": 2421836
},
"id": "53645450697",
"name": "Pizzeria Delfina"
},
Documentation on the basic action properties is here:
https://developers.intern.facebook.com/docs/beta/opengraph/actions/#create