Downloading a file with the version in the name Autodesk Forge - autodesk-forge

I'm using CURL to download a file from BIM360 document management, works fine, and I can give the file a name as well.
But we also require it to download the file and automatically add the version name to the file. Is something like this possible to do with CURL and Forge?

Commonly, we can find the filename in the request header Content-Disposition when calling GET buckets/:bucketKey/objects/:objectName, but BIM360 objects are a little different. The filename is stored in the version tip.
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Authorization, Accept-Encoding, Range, Content-Type
Access-Control-Allow-Methods: GET
Access-Control-Allow-Origin: *
Content-Disposition: attachment; filename="test.txt"
Content-Type: application/x-www-form-urlencoded
Date: Sat, 21 May 2016 00:24:25 GMT
ETag: "33a16388013ce310564af70b0ef5320d8fd85444"
Server: Apigee Router
Content-Length: 618
Connection: keep-alive
Therefore, you need to get the filename from the display name of the version first, then call GET buckets/:bucketKey/objects/:objectName with the display name you got from its version tip.
With curl, we can give the name by adding the -o option, see https://stackoverflow.com/a/69520470/7745569
curl -o rst_house.rvt --location --request GET 'https://developer.api.autodesk.com/oss/v2/buckets/wip.dm.prod/objects/a755b110-3d32-567b-871c-cb555e6087c1.rvt' \
--header 'Authorization: Bearer ' \
--header 'Content-Type: application/octet-stream'
Cheers,

Related

CURL does not work with URLs with curly braces in parameters

Some URLs with brackets don't work with CURL but work on Chrome and Firefox.
For example this URL: https://rdtrkr.com/mg.php?voluum_id=d51b17bc-c537-4f3e-9879-2e373341ae5a&widget_id={widget_id}&campaign_id={campaign_id}&teaser_id={teaser_id}&geo={geo}&img=guy18.jpg&txt=german&lp=de&click_price={click_price}&click_id={click_id}&{click_id} does work in Chrome and firefox but when called with CURL, gives a 404 error.
curl \
-H "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36" \
-v "https://rdtrkr.com/mg.php?voluum_id=d51b17bc-c537-4f3e-9879-2e373341ae5a&widget_id={widget_id}&campaign_id={campaign_id}&teaser_id={teaser_id}&geo={geo}&img=guy18.jpg&txt=german&lp=de&click_price={click_price}&click_id={click_id}&{click_id}"
Produces the result:
< HTTP/2 404
< server: nginx
< date: Thu, 13 Dec 2018 16:53:45 GMT
< content-type: text/html; charset=UTF-8
< content-length: 0
But with chrome developper tools in "Preserve log" mode I have :
CURL receives 404 instead of a 302 redirect. Is it related to the fact that CURL might be URL encoding brackets? I don't know what is going wrong here.
ps: I am not the owner of the website I'm using in the example.
Curly brackets are unsafe in URLs. cURL (unlike Google Chrome) tries to do you a favor and automatically encodes the URL.
In other words, it transforms { to %7B and } to &7D.
To prevent that behavior, you can pass the query string parameters using -d instead. Since -d changes the request to a POST, you'll also need to use -G to force the request to be a GET.
So instead of doing
curl "http://example.com?param1=xxx&param2=yyy"
you can do
curl "http://example.com" -G -d "param1=xxx&param2=yyy"
In your particular case, for some reason the webserver you're targeting will still return 404 unless you supply an Accept-Language header:
curl -v "http://rdtrkr.com/mg.php" \
-G -d "voluum_id=d51b17bc-c537-4f3e-9879-2e373341ae5a&widget_id={widget_id}&campaign_id={campaign_id}&teaser_id={teaser_id}&geo={geo}&img=guy18.jpg&txt=german&lp=de&click_price={click_price}&click_id={click_id}&{click_id}" \
-H "Accept-Language: en-US,en;q=0.9,fr;q=0.8,ru;q=0.7,es;q=0.6"
gives
* Trying 34.192.193.118...
* Connected to rdtrkr.com (34.192.193.118) port 80 (#0)
> GET /mg.php?voluum_id=d51b17bc-c537-4f3e-9879-2e373341ae5a&widget_id={widget_id}&campaign_id={campaign_id}&teaser_id={teaser_id}&geo={geo}&img=guy18.jpg&txt=german&lp=de&click_price={click_price}&click_id={click_id}&{click_id} HTTP/1.1
> Host: rdtrkr.com
> User-Agent: curl/7.47.0
> Accept: */*
> Accept-Language: en-US,en;q=0.9,fr;q=0.8,ru;q=0.7,es;q=0.6
>
< HTTP/1.1 302 Found
< Server: nginx
< Date: Thu, 13 Dec 2018 17:39:18 GMT
< Content-Type: text/html; charset=UTF-8
< Content-Length: 0
< Connection: keep-alive
< Location: https://rotronica-premarity.com/d51b17bc-c537-4f3e-9879-2e373341ae5a?widget_id={widget_id}&campaign_id={campaign_id}&teaser_id={teaser_id}&geo={geo}&img=guy18.jpg&txt=german&lp=de&click_price={click_price}&click_id={click_id}
<
* Connection #0 to host rdtrkr.com left intact
Use this flag (from man curl):
-g/--globoff
This option switches off the "URL globbing parser". When you set this option, you can
specify URLs that contain the letters {}[] without having them being interpreted by curl
itself. Note that these letters are not normal legal URL contents but they should be
encoded according to the URI standard.

curl issue: How to post json format data to server using curl in windows cmd?

After posting json format data to server using curl in windows command prompt(cmd), I'm testing the response data now, got a 'Bad request' message.
I've checked the request format, too.
cmd:
curl -i -X POST -H "Content-Type: application/json" -d '{ "isbn":"123442123, 97885654453443","title":"Learn how to build modern web application with MEAN stack","author": "Didin J.","description":"The comprehensive step by step tutorial on how to build MEAN (MongoDB, Express.js, Angular 5 and Node.js) stack web application from scratch","published_year":"2017","publisher":"Djamware.com" }' localhost:3000/api
And then,
HTTP/1.1 400 Bad Request
X-Powered-By: Express
Content-Type: text/plain; charset=utf-8
Content-Length: 11
ETag: W/"b-EFiDB1U+dmqzx9Mo2UjcZ1SJPO8"
Date: Wed, 05 Sep 2018 01:41:55 GMT
Connection: keep-alive
Bad Request
What's wrong? please help me.
You wrote the title as 'curl issue...', but i think curl has never any issue, because it is very widely used.
And your request data have no fault.
As my experience, problem would be exist in DB connection.
please check and check the accuracy of MongoDB connection.

How do i invoke my api which is configured in Kong through web browser?

I have created a new API configuration through kong..(dummy API) as below.
curl -i -X POST \
--url http://localhost:8001/apis/ \
--data 'name=myRESTapi' \
--data 'hosts=myrestapi.com' \
--data 'upstream_url=http://demo1592110.mockable.io/hello'
HTTP/1.1 201 Created
Date: Fri, 08 Dec 2017 09:25:35 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.11.2
{"created_at":1512725135862,"strip_uri":true,"id":"d066b086-6d64-45b7-9908-f6411c456ce4","hosts":["myrestapi.com"],"name":"myRESTapi","http_if_terminated":false,"preserve_host":false,"upstream_url":"http://demo1592110.mockable.io/hello","upstream_connect_timeout":60000,"upstream_send_timeout":60000,"upstream_read_timeout":60000,"retries":5,"https_only":false}
[ec2-user#ip-172-31-10-102 ~]$
I am invoking that API through curl command in linux instance as below
curl -i -X GET \
--url http://localhost:8000/ \
--header 'Host: myrestapi.com'
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 49
Connection: keep-alive
access-control-allow-origin: *
X-Cloud-Trace-Context: 7806a9e612e31e610f9278b98371a60e
Date: Fri, 08 Dec 2017 09:26:55 GMT
Server: Google Frontend
X-Kong-Upstream-Latency: 227
X-Kong-Proxy-Latency: 46
Via: kong/0.11.2
{
"msg": "shruthi mock API"
}
i want to know how to invoke this api through web browser which should pass through kong in another machine.
i can directly execute through upstream url in browser : http://demo1592110.mockable.io/hello
but i want to hit kong and inturn want to invoke my api, but not using curl command, but directly want to achieve this through web browser.
i am new to kong, not sure if this is valid or not. Any help is appreciated.
With "hosts" approach you need to pass the host in the header value which you cannot replicate from browser directly. For hosts approach you need to use any rest client to pass header value or programatically achieve it.
But as you mentioned you need to try it using browser directly, then I suggest you to use the "uris" when adding api to kong.
curl -i -X POST \
--url http://localhost:8001/apis/ \
--data "name=myRESTapi" \
--data "uris=/hello" \
--data "upstream_url=http://demo1592110.mockable.io"
You can see 'uris' added and URI from upstream_url is removed. No need of hosts after that.
Now if you hit the url in browser as
http://localhost:8000/hello
You can achieve the same.

Autodesk API: The system does not support this file format [.nwd file]

I'm following an Autodesk tutorial on loading CAD files in the browser with WebGL, and am trying to convert an .nwd file I've uploaded to one of their buckets to an "OBJ".
When I run the POST request in step two of the tutorial above, however, I receive a 400 (full response below) that indicates x-ads-troubleshooting: The system does not support this file format, despite the fact that of the Autodesk documentation indicates .nwd files are supported.
Here's the full path to my file (requires Oauth token): https://developer.api.autodesk.com/oss/v2/buckets/gathering-a-bulding-bucket/objects/Yale_Residential_Colleges_Arch.nwd
When I added the item to the bucket, I was given the following objectId (which the docs also refer to as the source URN):
"objectId" : "urn:adsk.objects:os.object:gathering-a-bulding-bucket/Yale_Residential_Colleges_Arch.nwd"
I base64 encoded this string and removed the excess padding (the extra == characters at the end) per the documentation, which resulted in the following:
dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6Z2F0aGVyaW5nLWEtYnVsZGluZy1idWNrZXQvWWFsZV9SZXNpZGVudGlhbF9Db2xsZWdlc19BcmNoLm53ZA
I'm now trying to convert this nwd file to an OBJ with the following command:
curl -X 'POST' -H 'Authorization: Bearer OAUTHTOKENHERE' -H 'Content-Type: application/json' -v 'https://developer.api.autodesk.com/modelderivative/v2/designdata/job' -d '{"input":{"urn":"dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6Z2F0aGVyaW5nLWEtYnVsZGluZy1idWNrZXQvWWFsZV9SZXNpZGVudGlhbF9Db2xsZWdlc19BcmNoLm53ZA"},"output":{"formats":[{"type":"obj"}]}}'
This command yields the following response:
* Connected to developer.api.autodesk.com (52.7.124.118) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: developer.api.autodesk.com
* Server certificate: Symantec Class 3 Extended Validation SHA256 SSL CA
* Server certificate: VeriSign Universal Root Certification Authority
> POST /modelderivative/v2/designdata/job HTTP/1.1
> Host: developer.api.autodesk.com
> User-Agent: curl/7.43.0
> Accept: */*
> Authorization: Bearer OAUTHTOKENHERE
> Content-Type: application/json
> Content-Length: 181
>
* upload completely sent off: 181 out of 181 bytes
< HTTP/1.1 400 Bad Request
< Access-Control-Allow-Credentials: true
< Access-Control-Allow-Origin: *
< Content-Type: application/json; charset=utf-8
< Date: Fri, 09 Sep 2016 16:07:06 GMT
< Server: Apigee Router
< x-ads-app-identifier: platform-viewing-2016.08.01.1114.dbcc24a-production
< x-ads-duration: 525 ms
< x-ads-exception-id: c54954c5-dc74-4b09-961a-5eb7de82625b
< x-ads-startup-time: Wed Sep 07 01:40:23 UTC 2016
< x-ads-troubleshooting: The system does not support this file format.
< Content-Length: 61
< Connection: keep-alive
<
* Connection #0 to host developer.api.autodesk.com left intact
{"diagnostic":"Failed to trigger translation for this file."}
Does anyone have any leads on what I might be overlooking? I'd be grateful for any help others can offer!
Please take a look at this list of supported translations, you'll see that translation from .nwd to .obj is not supported, only to svf (which is used for Viewer).

Sending json files in curl requests with absolute or relative paths

Just wondering how I can send a curl command with the -d option specifying a file with its path and not a file in the current directory.
This is what I'm getting when I try to test my app with the json file in the local dir. Both the app and myself are happy:
curl -XPOST -H 'Content-Type:application/json' -d #all_fields.json http://testcomp.lab.net:8080/stats -v -s
* About to connect() to testcomp.lab.net port 8080
* Trying 10.93.2.197... connected
* Connected to testcomp.lab.net (10.93.2.197) port 8080
> POST /stats HTTP/1.1
> User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
> Host: testcomp.lab.net:8080
> Accept: */*
> Content-Type:application/json
> Content-Length: 2882
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
HTTP/1.1 200 OK
< Content-Length: 0
* Connection #0 to host testcomp.lab.net left intact
* Closing connection #0
This is what I'm getting when I specify a json file that's in another directory
curl -XPOST -H 'Content-Type:application/json' -d #json/all_fields.json http://testcomp.lab.net:8080/stats -v -s
"Invalid json for Java type interface java.util.List"
Warning: Couldn't read data from file "json/all_fields.json", this makes an
Warning: empty POST.
<snip snip>
<snip snip>
< HTTP/1.1 400 Bad Request
< Content-Type: application/json
< Transfer-Encoding: chunked
* Connection #0 to host testcomp.lab.net left intact
* Closing connection #0
I didn't see anything in the man page for curl for specifying directories for files passed in as data. Am I unfortunately limited to files in the local directory or is there a special way to specify files in different directories? Thanks in advance for your help.
The -d # command option accepts any resolvable file path, as long as the path actually exists. So you could use:
a path relative to the current directory
a fully qualified path
a path with soft-links in it
and so on
To wit, just the same as hundreds of other *Nix style commands. One quick note, the -d option will attempt to url encode your data, which from what you describe isn't actually what you want. You should use the --data-binary option instead. Something like this:
curl -XPOST
-H 'Content-Type:application/json'
-H 'Accept: application/json'
--data-binary #/full/path/to/test.json
http://localhost:8080/easy/eservices/echo -v -s