Box.com api - "Does file exist" check - box-api

Why doesn't the box api have an "exists" method for files? Seems like a very common use case.
Because there is no direct method, how do you use the API to tell whether or not a file ID exists?

Using the API you can simply request the metadata for the file with that ID. If the file exists and you have access to it, then a full file object will be returned.
Request:
curl https://api.box.com/2.0/files/FILE_ID
-H "Authorization: Bearer ACCESS_TOKEN"
Response:
200 OK
{
"type": "file",
"id": "5000948880",
"etag": "3",
"sha1": "134b65991ed521fcfe4724b7d814ab8ded5185dc",
"name": "tigers.jpeg",
...
}

Related

I want to convert my rvt file to svf format and keep it in my local

good day everyone. I need to view my rvt file in forge. I want to convert my rvt file to svf format and keep it in my local. Which API will I use exactly for this and the converted svf folder will be downloaded to my local?
Where can I get my user token for Authorization?
Is this the api I should use?
curl -X POST 'https://developer.api.autodesk.com/modelderivative/v2/designdata/job' -H 'Content-Type: application/json' -H 'Authorization: Bearer <YOUR_ACCESS_TOKEN>' -H 'x-ads-force: true' -d '{
"input": {
"urn": "<BASE64_ENCODED_URN_OF_SOURCE_FILE>"
},
"output": {
"destination": {
"region": "us"
},
"formats": [
{
"type": "svf2",
"views": [
"2d",
"3d"
]
}
]
}
}'
Good day to you,
You are looking forward to use the model derivative APIs, https://forge.autodesk.com/en/docs/model-derivative/v2/developers_guide/overview/
So if you want the access token, you will have to go through 2legged Authentication
https://forge.autodesk.com/en/docs/oauth/v1/tutorials/get-2-legged-token/
As you know Forge is a cloud development platform , a set of web service APIs you can use to build innovative, cloud-powered applications. So the extraction of SVF in local system is not officially supported by Autodesk. You might want to go through this extractor at your own risk https://github.com/cyrillef/extract.autodesk.io , https://forge.autodesk.com/blog/forge-svf-extractor-nodejs

Is there an autodesk forge API available to lock files in BIM 360 or ACC?

I want to be able to lock files on Autodesk BIM360 or ACC projects. I can't find any forge API for this purpose available on the official documentation. Is there an exposed endpoint for this purpose ?
This is actually a good question, unfortunately, there is no endpoint to provide this feature at this moment, but I will talk to our engineering team about your request, and will let you know if any new update.
[Updated on Aug 17th]:
With the information from engineering team, this behavior could be achieved via patching "reserved" attribute of the items. For example:
curl -v 'https://developer.api.autodesk.com/data/v1/projects/:project_id/items/:item_id'
-X 'PATCH'
-H 'Authorization: Bearer AuIPTf4KYLTYGVnOHQ0cuolwCW2a'
-H 'Content-Type: application/vnd.api+json'
-d '{
"jsonapi": {
"version": "1.0"
},
"data": {
"type": "items",
"id": "urn:adsk.wipprod:dm.lineage:AeYgDtcTSuqYoyMweWFhhQ",
"attributes": {
"reserved": true
}
}
}'

Can we used google drive's 'watch' API for polling data? How can we use 'watch' API to track changes?

I am using changes API to track my G-Drive changes, but it's not giving the complete resource data. Can I use 'watch' API to poll my resources?
Below is my request for changes API:
curl -X GET \
'https://www.googleapis.com/drive/v3/changes?pageToken=46' \
-H 'Accept: */*' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'Authorization: Bearer <Token>' \
Here's the response:
"changes": [
{
"kind": "drive#change",
"type": "file",
"changeType": "file",
"time": "2019-10-10T09:15:12.313Z",
"removed": false,
"fileId": "<File_ID>",
"file": {
"kind": "drive#file",
"id": "<File_ID>",
"name": "shared",
"mimeType": "application/vnd.google-apps.folder"
}
}
]
But using this, I cannot decide the file is created or updated..
When you get a Changes resource, the response has a specific format.
You can see that the Changes has the property file that is of type Files.
What you want to do is inspect the Files resource returned by the change to monitor the state of the file between changes.
Hope this helps!

Method Not Allowed when patching registration

Recently some registrations of commands expired so I am trying to patch their "expires" attribute. However, I receive a 405 method not allowed message error.
Retrieving info about the registration:
curl -X GET \
http://localhost:1026/v2/registrations/5d3ff3e2ab1e270d7775a7bf \
-H 'Accept: application/json'
{
"id": "5d3ff3e2ab1e270d7775a7bf",
"expires": "2019-08-29T07:38:10.00Z",
"dataProvided": {
"entities": [
{
"id": "urn:ngsi-ld:ActuatorScreenshot:001",
"type": "Actuator"
}
],
"attrs": [
"Screen"
]
},
"provider": {
"http": {
"url": "http://localhost:4041"
},
"supportedForwardingMode": "all",
"legacyForwarding": true
},
"status": "active"
}
I attempted following the example from http://telefonicaid.github.io/fiware-orion/api/v2/stable/:
curl -X PATCH \
http://localhost:1026/v2/registrations/5d3ff3e2ab1e270d7775a7bf \
-d '{
"expires":"2040-10-04T00:00:00"
}'
But as I said I got the error message:
405 Method Not Allowed
Feel free to ask for more info.
The operation to modify registrations has not been yet implemented in Orion 2.2.0 (last version in the moment of writing this). As mentioned in Orion documentation:
Orion implements registration management as described in the NGSIv2
specification, except for the following aspects:
List item PATCH /v2/registration/<id> is not implemented. Thus, registrations cannot be updated directly. I.e., updates must be done
deleting and re-creating the registration. Please see this
issue about
this.
However, the workaround is pretty simple: delete the old registration and create a new one with the modified parameters.

Why Google Translate API doesn't accept API-Key in JSON request body?

I'm new to use Google Could Platform.
I tried Translation API's tutorial. By some reason I want to use API-Key for its authentication. but API doesn't accept key in JSON Request, though it accepts same key in HTTP query parameter.
Is this a restriction of Google Translation API? or do I have any mistake?
Following is what I tried:
Worked when API-key is passed as a query parameter
$ curl -H 'Content-Type: application/json' 'https://translation.googleapis.com/language/translate/v2?key=xxxxxxxxxx' --data-binary #test.json
with my test.json is:
{
"q": "The quick brown fox jumped over the lazy dog.",
"source": "en",
"target": "es",
"format": "text"
}
result was:
{
"data": {
"translations": [
{
"translatedText": "El rpido zorro marrn salt sobre el perro perezoso."
}
]
}
}
But for some security reason, I don't want to pass this API-key by query string.
Why I don't want to use query-string
An URI with sensitive parameter is not safe, for it is often logged or is shown in some situation, while HTTP Header or HTTP body aren't.
Of course using stronger authentication method (Service Account) is better for security, but API-key is also a good solution for some use cases like embedding in legacy-system, or so.
Didn't work when Api-key is passed in JSON request
I set "key" item in my request JSON, and it didn't work. It caused authorization error.
curl -H 'Content-Type: application/json' 'https://translation.googleapis.com/language/translate/v2' --data-binary #test.json
with test.json:
{
"key": "xxxxxxxxxx",
"q": "The quick brown fox jumped over the lazy dog.",
"source": "en",
"target": "es",
"format": "text"
}
result:
{
"error": {
"code": 403,
"message": "The request is missing a valid API key.",
"errors": [
{
"message": "The request is missing a valid API key.",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED"
}
}
The only working example I could find was:
Append the key in the URL, e.g.:
https://translation.googleapis.com/language/translate/v2?key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Do the rest in POST.