URL design for GET resource in REST API for images - rest

I have a Rest API that allows users to POST to an endpoint to upload a photo:
POST /api/photos
The response would be as follows:
{
"id": "1",
"title": "my image"
"url": "https://some_s3_url"
}
The user can then access the photo metadata through the GET endpoint
GET /api/photos/1
What is the best way to model a url for getting the content of the image url? Note that I'd like to ensure the user has the ability to access this image, so requesting the s3 bucket url directly will not work here.
I have considered doing something like:
GET /api/photos/1/content
Though that seemed hacky

first of all POST request should not return response, it could return header called location to return URI of created resource for ex. http://youer-server/api/photos/1 then in GET request for this URL you can return the json object as:
{
"id": "1",
"title": "my image",
"url": "https://some_s3_url",
"base64": .....
}
then you can encode your image as base64 and provide its content in the same object.

Related

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

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."
}
]
}

Get scraped data from facebook graph api using url reliably

My app needs to get data facebook scrapes from URLs. Up until now we were getting it using
POST /?id={object-instance-id or object-url}&scrape=true
Which is detailed in updating object section in https://developers.facebook.com/docs/sharing/opengraph/using-objects
For example
POST /?id=http://google.com
{
"url": "http://www.google.com/",
"type": "website",
"title": "Google",
"image": [
{
"url": "http://www.google.com/images/branding/googleg/1x/googleg_standard_color_128dp.png"
}
],
"description": "Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.",
"updated_time": "2015-10-06T11:34:58+0000",
"id": "381702034999"
}
Notice image section.
Unfortunately if og tags are configured wrongly on the server
POST /?id=http://some.page.with.bad.tags.com
{
"error": {
"message": "Invalid parameter",
"type": "FacebookApiException",
"code": 100,
"error_subcode": 1611016,
"is_transient": false,
"error_user_title": "Object Invalid Value",
"error_user_msg": "Object at URL 'http://some.page.with.bad.tags' of type '' is invalid because the given value '/some-bad-value' for property 'og:url' could not be parsed as type 'url'.",
"fbtrace_id": "abcabcabc"
}
}
Which returns nothing interesting.
Attempt to GET the url returns this:
{
"og_object": {
"id": "381702034999",
"description": "Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.",
"title": "Google",
"type": "website",
"updated_time": "2015-10-06T11:40:04+0000",
"url": "http://www.google.com/"
},
"share": {
"comment_count": 2,
"share_count": 13494003
},
"id": "http://www.google.com"
}
Which misses image section. I cannot find in the documentation any way to retrieve result with images without using POST /?id={url}, but that fails on any errors in og tags.
GET /{ObjectId}
returns only type and created_time
Entering the same broken link in https://developers.facebook.com/tools/debug/ results in page which contains image, description, title and captions for the page. Which I need. So it means facebook stores them, even though page has wrong tags, but I need a way to fetch them. Unfortunatelly I cannot provide link for broken url due to NDA, and I couldn't find other page with broken tags.
If the page contains invalid Open Graph markup this seems expected, also do not confuse the Graph API with some sort of datasource or a scraping service you can utilize to generate the preview for web content.
If Facebook , for whatever reason, can't parse the Open Graph tags of a URL it will try to make a good guess based on the content of the page (large junks of text, images it finds, title tags etc.) to build the preview so you might get some sort of data back from GET /{object-id} which can just be a guess instead of actual og:.. data.
In case you really need a more or less failsafe solution, you could build your own scraper that looks for Open Graph tags.

Get facebook id from url (?ids=url) some url are not working

Get facebook id from url (?ids=url) by fb graph some url are not working.
For example;
https://graph.facebook.com/?ids=https://www.facebook.com/groups/Happypattaya
The link above work fine, so I got this json (it's right).
{
"https://www.facebook.com/groups/Happypattaya": {
"id": "589515601153720",
"created_time": "2014-10-09T17:16:29+0000",
"is_scraped": false,
"type": "website",
"updated_time": "2014-10-09T17:16:29+0000",
"url": "https://www.facebook.com/groups/Happypattaya"
}
}
But
https://www.facebook.com/groups/663908986989589
and other links, as I noticed it was a numeric, I can use "preg_match" to get it if find an integer ,but I really want to grab id from fb graph anyway.
You should always add a valid access_token to any graph api request.
e.g.
https://graph.facebook.com/?ids=https://www.facebook.com/groups/Happypattaya&access_token=CAACXXXXX

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.

Facebook: Link Request's sender to it's recipient?

When using the requests dialog, facebook issues a notification like this:
What I'm looking to achieve is for the user to click the request link shown above and to present a "Random User invited you to..." message on our App.
However, when clicking that link Facebook doesn't seem to pass through the id of "Random User" to the App. The url accessed by the link looks something like:
http://apps.facebook.com/randomcomp/?fb_source=notification&request_ids=350578327437399,350578327437399&ref=notif&app_request_type=user_to_user&notif_t=app_request
which doesn't contain any reference to the user who initiated the request.
From the App's side, there doesn't seem to be a way to get this information from Facebook. Sure, you can get a list of requests, but that list can contain information for many requests, including requests from other users in addition to the one we're interested in, so it's not useful in this case. For example, here's a snapshot of data:
{
"data": [
{
"id": "340083146057323_100003817986566",
"application": {
"name": "Random Competition",
"namespace": "randomcomp",
"id": "350578327437399"
},
"to": {
"name": "Hannah Smith",
"id": "100003817986566"
},
"from": {
"name": "Random User",
"id": "100002286042525"
},
"data": "100002286042525",
"message": "Use the app!",
"created_time": "2012-05-14T13:26:30+0000"
}, {
"id": "358318457550141_100003817986566",
"application": {
"name": "Random Competition",
"namespace": "randomcomp",
"id": "350578327437399"
},
"to": {
"name": "Hannah Smith",
"id": "100003817986566"
},
"from": {
"name": "Jane Young",
"id": "100003771838663"
},
"data": "100002286042525",
"message": "Use the app!",
"created_time": "2012-05-14T10:54:25+0000"
}],
}
}
As you can see, the data is being passed in, but there's still no way to join the click from the link mentioned above (for Random User) to the correct request in the list; the link passes through the ID for both requests, not just the one for Random User, and while the link states "Random User" it doesn't pass through an identifier.
Am I missing something? Is there a mechanism that isn't in the docs that will allow me to pick-up the "Random User" id so I can provide a nice "Random User invited you to..." message in the App when they click through?
Edit:
Turns out that this isn't possible - see my answer.
You can add some data to the request so that when you process the request you can differentiate that from other requests.
The data can be sent with app requests and users requests and the parameter name is "data".
For example, in the guide for the Requests Dialog you can see it in the properties table at the (almost) end of the document, it says:
Optional, additional data you may pass for tracking. This will be
stored as part of the request objects created. The maximum length is
255 characters
There's also some info about it in the Social Channels documentation, and a sample of (php) usage in the official blog post about Upgrade to Requests 2.0.
I hope that this is what you're looking for.
Edit
When you send the request you know who is sending it right? It's the logged in user, and so you can put the user id/name/etc in the data parameter of the request.
Then, when someone clicks on a request, get the request by the id that facebook passes to you, and from the data extract the user id of the sender.
As the documentation states, you have 255 characters to use, and with that you can do what ever you want, you can even serialize an object to that parameter and deserialize it later.
As it turns out, this is in fact not possible at all.
The link, as shown in the image below, can present multiple users:
which is why multiple request IDs are passed in, and the sender's ID isn't.