Is there an API for sharing an attachment in RingCentral Glip? - share

I want to build an app that can monitor one Glip team for posts including screenshots and then post that message to another Glip team. I can read a post, download an attachment and repost / upload it, but is there a way to simply share an existing attachment without reposting it. This can be done in the app UI but I didn't see a share API in the Glip API Reference.
Here's the Glip API Reference which includes endpoints for creating, reading, updating and deleting posts but not sharing:
https://developers.ringcentral.com/api-reference/team-messaging
The icon for sharing is the 6th from the left in the app screenshot below.
Is there a way to do this in Glip without downloading and re-uploading the file?

To share an attachment via the Glip API, create a new post with an existing attachment.
Create Post API
The Create Post API takes an optional attachments array which references existing attachments. Both the id and type properties are required. Both properties are present in the post API response.
POST /restapi/v1.0/glip/chats/{chatId}/posts
{
"text": "Please check out this file",
"attachments": [
{
"id":"123456789",
"type":"File"
}
]
}
Ref: https://developers.ringcentral.com/api-reference/Posts/createGlipPost
Example Get Posts API
The following is an example of a post showing the attachments array with the id and type properties. The attachment URL is an AWS Presigned Object URL as shown below.
GET /restapi/v1.0/glip/chats/{chatId}/posts
{
"records": [
{
"id": "11111111",
"creatorId": "22222222",
"creationTime": "2019-08-26T21:41:56.648Z",
"lastModifiedTime": "2019-08-26T21:41:56.648Z",
"type": "TextMessage",
"chatId": "33333333",
"mentions": [],
"attachments": [
{
"id": "123456789",
"name": "sharedfile.png",
"contentUri": "https://glip-vault-1.s3.amazonaws.com/web/customer_files/44444444/testimage.png?Expires=55555555&AWSAccessKeyId=myAccessKeyId&Signature=myAWSPresignedObjectUrlSignature",
"type": "File"
}
],
"text": "Check this out!"
}
},
"navigation": {}
}
Ref: https://developers.ringcentral.com/api-reference/Posts/readGlipPosts
Sharing Permissions
Attachments can only be shared by the original poster or within the same chat. If a different user wants to share an attachment in a different team, it will be necessary to download and repost the file, generating a new attachment id.
If a different user attempts to share an attachment in a different chat, a 403 Forbidden error will be encountered:
403 Forbidden
{
"errors": [
{
"errorCode": "PST-011",
"message": "The requester must be attachment creator or attachment must belong to the requested chat."
}
]
}

Related

FB Graph API is not returning user object in post's comments, likes, reactions

I've FacebookApp [ type: business ] which fetches all posts, post-comments, and post-likes from the owned Facebook pages.
Verified permissions are ['pages_show_list', 'pages_read_user_content']
When I'm fetching the post and their comments/likes then the user-object is missing in the response body.
Sample JSON
API : https://graph.facebook.com/v2.12/<PAGE-ID>/? \
fields=posts{message, comments{message, from{id, name, link}},reactions{from{id, name, link}}} \
&access_token={{pagetoken}}
response body sample :
...
"message": "For cancer awareness month we are sharing stories of survivors! \n\nManorama is sharing story ... Cancer Campaign (India)",
"comments": {
"data": [
{
"message": "Thank u so much to the entire team.",
"id": "420757949533461_421416076134315",
// USER OBJECT IS MISSING : [id, name]
},
{
"message": "Thank u for sharing ma's story with all!",
"id": "420757949533461_421407146135208",
// USER OBJECT IS MISSING : [id, name]
}
],
...
I'm not sure what is wrong with the above API call because the API call is working fine with TestPage and TestUser. Do I need to ask for some additional permissions from Facebook?
Facebook Graph api does not return user's name anymore by calling this endpoint.
There is one solution you can try: use hooks.
Set a page webhook to retrieve all the comments written on your page. Find the documentation here: https://developers.facebook.com/docs/pages/realtime
The comments' data you'll receive from facebook will contain a name

Facebook API Lead retrieval for internal business app should i submit for App Review

I am building a dedicated CRM solution and it is supposed to show the list of Facebook leads of the client and then convert manually it to internal lead . I am managed to setup a websocket client and Facebook is sending me lead details including leadgen_id.
{
"object":
"page" ,
"entry": [{
"id": "*****" ,
"time": 1627211279 ,
"changes": [{
"value": {
"form_id": "******" ,
"leadgen_id": "******" ,
"created_time": 1627211277 ,
"page_id": "******"} ,
"field": "leadgen"}
]}
]}
Then i have created an user access_token using Facebook's graph api and requested for the details of the leadgen_id using api endpoint
https://graph.facebook.com/v11.0/<LEADGEN_ID>?access_token=<ACCESS_TOKEN>
I was able to get the details of the test lead I created with the Facebook 's lead testing tool. But when accessing the production leadgen_id I am getting an exception with following as response.
{
"error": {
"message": "Unsupported get request. Object with ID '<LEADGEN_ID' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"error_subcode": 33,
"fbtrace_id": "*********"
}
}
Then I have tried using a system user token and its not even working for the test leads. In some part of documentation it is saying that I need to complete App review to access live data using lead_retrieval and in some other part of documentation its quoted that I don't need app review to use API for internal users . And I don't get the point of creating a 'login with Facebook' for this internal app specific for one user .
Is there anyway other way than completing app review to access lead details using leadgen_id ?
Its turns out I need to complete the app review specifying it as a 'Server to server app' on the review description, which doesn't need any Login with facebook button . Got the idea from https://developers.facebook.com/docs/app-review/resources/sample-submissions/server-to-server/

Facebook graph api page post with multiple photos

I am trying to publish a page post with multiple photos via the Facebook's graph api.
Currently from the docs and another question here it's stated that the photos should be uploaded separately and then publish the post with attached_media parameter.
The photos are uploaded fine without any problem and I get their IDs.
The issue is that the request for publishing the post gives:
{
"error": {
"message": "An unknown error has occurred.",
"type": "OAuthException",
"code": 1,
"fbtrace_id": "SOME TRACE ID"
}
If I remove the attached_media parameter from the request the post is published fine.. Any Idea what can be the issue?
Specially for CBroe here are the reqiests:
For the photo upload:
endpoint: /{page-id}/photos
payload:
{
"url": "some-image-url",
"caption": "Some image caption",
"published": false
}
endpoint: /{page-id}/feed
payload:
{
"message": "Some post message",
"published": false,
"attached_media": [
{"media_fbid": "PHOTO_ID_RETURNED_FROM_THE_ABOVE_REQUEST"}
]
}
The payload is send as json to the endpoint. This request works only if I remove the attached_media parameter.
TL;DR
Add publish_to_groups permission to the access token and the request for the post should be with parameter published: true. It appears to have a bug in the graph api or lack of information in the official docs.
Details:
Currently in order to publish a page post with multiple photos you will need to:
upload individually the photos and obtain their IDs
use PAGE access token which contains publish_to_groups permission
attach all photo IDs with attached_media[0..N]: {"media_fbid": "PHOTO_ID"}
currently the request for publishing the post fails if it's with parameter published: false, so it needs to be published: true
All of this does not make really sense to me, so I opened a bug report in the developers platform of Facebook. It does not looks right during development of the App to publish live posts to the page...
I'll edit the answer once I have a feedback.

Custom Internal Facebook App Graph API not returning Page's Post Comments

I am trying to create a Facebook app that can pull down the comments on the posts of a business page I have created. I have successfully created the app and connected my Facebook page through OAuth. However, none of the comments on the page's posts are coming through. Any help would be appreciated, please see below code.
https://graph.facebook.com/v3.2/{pageId}/?access_token={accessToken}&fields=id,name,posts
Response:
{
"id": "{pageId}",
"name": "Page Name",
"posts": {
"data": [
{
"created_time": "2016-01-15T19:46:28+0000",
"message": "POST 1",
"id": "47829695884833182_111061999222282539"
},
{
"created_time": "2016-01-15T19:45:56+0000",
"message": "POST 2",
"id": "4734458296958848182_111061922795615892"
}
}
}
The same thing happens if I use the following endpoint:
https://graph.facebook.com/v3.2/{pageId}/feed?access_token={accessToken}
Or
https://graph.facebook.com/v3.2/{pageId}/posts?access_token={accessToken}
I found a reference showing I may be able to get comments through this endpoint:
https://graph.facebook.com/v3.2/{pageId}/comments?access_token={accessToken}
However I get the following response:
{
"error": {
"message": "(#100) Tried accessing nonexisting field (comments) on node type (Page)",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "EN938TNAHM6"
}
}
With all but the last request you are not asking for comments anywhere. And with the last one you are trying to ask for comments on the page object itself, which are not a thing.
You need to ask for the comments, on either the feed or posts endpoint:
/{pageId}/feed?fields=comments
/{pageId}/posts?fields=comments
And if you want to get other info about the page as well in the same request, you can use Field Expansion syntax,
/{pageId}?fields=id,name,posts{comments}
(Any other fields of the posts you might want besides the default id, you’d need to list there comma separated - posts{message,comments,...})
I was able to get comments by using the following request:
https://graph.facebook.com/{post_id}/comments?access_token={accessToken}&summary=true
post_id looks something like this - 57042555475_57045425233226
You have to get comments by posts not pages so first you need to make a call to get all your posts and then make a call for each post to get comments.

BOX API to invite external user

Just am trying to use BOX API for collaboration. i just wanted to know is there any REST api call available to invite a external user.
You just POST to https://api.box.com/2.0/collaborations with the proper auth header for your user that is authenticated (the person doing the invitation to collaborate). In the body of the request you would put the JSON to specify the folder and the invitee.
{"item": { "id": "12137", "type": "folder"}, "accessible_by": { "login": "rob#winterfell.com"}, "role": "editor"}
Then rob#winterfell.com will get an email telling them that they've been invited to see the appropriate folder.