Failed conversion from dwg to svf with the Autocad api TranslationWorker - autodesk-forge

I am failing to upload a simple dwg and convert it to svf using the TranslationWorker from the forge API. I am using autocad 2014 and creating a simple drawing with a circle and saving it as a .dwg.
I am using the commandline in windows and the following curl commands:
curl -v "https://developer.api.autodesk.com/oss/v2/buckets/kumkortbucket/objects/sirkel.dwg" -X "PUT" -H "Authorization: Bearer OAUTH_TOKEN" -H "Content-Type: application/octet-stream" -T "‪C:\Users\DAN\Documents\Testfiler\sirkel.dwg"
which produces the following result:
HTTP/1.1 100 Continue
* We are completely uploaded and fine
< 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-Type: application/json; charset=utf-8
< Date: Tue, 14 Feb 2017 12:56:38 GMT
< Server: Apigee Router
< Content-Length: 355
< Connection: keep-alive
<
{
"bucketKey" : "kumkortbucket",
"objectId" : "urn:adsk.objects:os.object:kumkortbucket/sirkel.dwg",
"objectKey" : "sirkel.dwg",
"sha1" : "78f92dc0a364814756cfa9392d7fa95aecf0916b",
"size" : 31548,
"contentType" : "application/octet-stream",
"location" : "https://developer.api.autodesk.com/oss/v2/buckets/kumkortbucket/objects/sirkel.dwg"
}* Connection #0 to host developer.api.autodesk.com left intact
I then convert it using the POST job command
curl -X "POST" -H "Authorization: Bearer OAUTH_TOKEN" -H "Content-Type: application/json" -v "https://developer.api.autodesk.com/modelderivative/v2/designdata/job" -d "{\"input\": {\"urn\": \"dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6a3Vta29ydGJ1Y2tldC9zaXJrZWwuZHdn\"},\"output\": {\"formats\": [{\"type\": \"svf\",\"views\": [\"2d\",\"3d\"]}]}}"
Using the GET command to check the result i get the following result:
{"type":"manifest","hasThumbnail":"false","status":"failed","progress":"complete","region":"US","urn":"dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6a3Vta29ydGJ1Y2tldC9zaXJrZWwuZHdn","version":"1.0","derivatives":[{"name":"sirkel.dwg","hasThumbnail":"false","status":"failed","progress":"complete","messages":[{"type":"error","code":"AutoCAD-InvalidFile","message":"Sorry, the drawing file is invalid and cannot be viewed. \n- Please try to recover the file in AutoCAD, and upload it again to view."},{"type":"error","message":"Unrecoverable exit code from extractor: -1073741831","code":"TranslationWorker-InternalFailure"}],"outputType":"svf"}]}* Connection #0 to host developer.api.autodesk.com left intact
I cannot figure out what i am doing wrong. I can view the file in autocad and the online viewer.
Cheers.
EDIT:
here is a file that is problematic to upload
http://www.filedropper.com/ekbsroplain

Here is what I did (entire process):
curl -v 'https://developer.api.autodesk.com/authentication/v1/authenticate' -X 'POST' -H 'Content-Type: application/x-www-form-urlencoded' -d 'client_id=****&client_secret=****&grant_type=client_credentials&scope=data:read data:write data:create bucket:create bucket:read'
curl -v 'https://developer.api.autodesk.com/oss/v2/buckets' -X 'POST' -H 'Content-Type: application/json' -H 'Authorization: Bearer TOKEN' -d '{"bucketKey":"kumkortbucket170214","policyKey":"transient"}'
Note I'm uploading without content-type and content-length, not need actually:
curl -v 'https://developer.api.autodesk.com/oss/v2/buckets/kumkortbucket170214/objects/drawing1.dwg' -X 'PUT' -H 'Authorization: Bearer TOKEN' -T '/Users/augustogoncalves/Desktop/Drawing1.dwg'
And finally the POST JOB:
curl -X 'POST' -H 'Authorization: Bearer TOKEN' -H 'Content-Type: application/json' -v 'https://developer.api.autodesk.com/modelderivative/v2/designdata/job' -d '{"input":{"urn":"dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6a3Vta29ydGJ1Y2tldDE3MDIxNC9kcmF3aW5nMS5kd2c="},"output":{"formats":[{"type": "svf","views": ["2d","3d"]}]}}'
And worked fine
{
"result":"success",
"urn":"dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6a3Vta29ydGJ1Y2tldDE3MDIxNC9kcmF3aW5nMS5kd2c",
"acceptedJobs":{
"output":{
"formats":[
{
"type":"svf",
"views":[
"2d",
"3d"
]
}
]
}
}
}

Related

How to Parse Data into a POST request for MRPeasy

TLDR
For my API project I require to send a POST request to MRP to update some of the fields.
What I am currently struggling with is the ability to parse in the parameters as data, every time I send the request I get a code 400.
Full Explanation
MRPeasy has a documentation page which I am using heavily for this project as that is the only source of info.
In that article they give 2 examples, 1 for GET and 1 for POST, I have no issues whatsoever with the get request, it works perfectly fine. However, the POST does not, they are as follows:
curl -X "GET" "https://app.mrpeasy.com/rest/v1/items" \
-H 'Content-Type: application/json' \
-H 'api_key: xxxxxxxxxxxxx' \
-H 'access_key: xxxxxxxxxxxxx'
curl -X "PUT" "https://app.mrpeasy.com/rest/v1/items/5" \
-H 'Content-Type: application/json' \
-H 'api_key: xxxxxxxxxxxxx' \
-H 'access_key: xxxxxxxxxxxxx' \
-d '{"selling_price": "2.54"}'
Below is my representation of the above code in python:
```python
url = "https://app.mrpeasy.com/rest/v1/manufacturing-orders/69"
headers = {
"Content-Type": "application/json",
"api_key": my_api_key,
"access_key": my_access_key
}
print(requests.get(url, headers=headers).json()["custom_3338"])
url = "https://app.mrpeasy.com/rest/v1/manufacturing-orders/69"
headers = {
"Content-Type": "application/json",
"api_key": my_api_key,
"access_key": my_access_key
}
data = json.dumps({"custom_3338": "1654642800.0000000000"})
print(requests.post(url, headers=headers, data=data).status_code)
```
Regarding the data variable, I have tried all of the below:
'{"custom_3338": "1654642800.0000000000"}'
{"custom_3338": "1654642800.0000000000"}
{"due_date": "1654642800.0000000000"}
{"quantity": 3}
'{"quantity": 3}'
I hope that is sufficient information. If you need anything else from me, please let me know, I'll be more than happy to provide.
Many Thanks,
Greg
P.S. This is my first post so I apologise if I didn't follow some rules or best practices.
You can create a json File contains the data you want to send as data and send the request with the JSON file itself.
JSON
{"custom_3338": "1654642800.0000000000"}
curl
curl -X POST \
-H 'Content-Type: application/json' \
-H 'api_key: xxxxxxxxxxxxx' \
-H 'access_key: xxxxxxxxxxxxx'
--data "#./processGroup.json" \
https://app.mrpeasy.com/....
Or easier actually, pass the data directly in the body :
curl -X POST \
-H 'Content-Type: application/json' \
-H 'api_key: xxxxxxxxxxxxx' \
-H 'access_key: xxxxxxxxxxxxx'
--data '{"custom_3338": "1654642800.0000000000"}' \
https://app.mrpeasy.com/....

How to get Curl header response?

I am trying to get the below response from my curl command. My command inserts data into a list and that works perfectly. However, I cannot seem to figure out how to get the below response.
curl -d "{"""name""":"""ME""","""id""":1}" -H "Content-Type: application/json" -X PUT http://localhost:8081/api/users
I have tried all of the following.
curl --trace, curl -v, curl -i, curl -w '%{response_code}'
DEBUG 2018-11-26 16:15:24,853 [http.listener.06 SelectorRunner] [event: ]
org.mule.service.http.impl.service.HttpMessageLogger.HTTP_Listener_config: LISTENER
PUT /api/users HTTP/1.1
Host: localhost:8081
User-Agent: curl/7.54.0
Accept: */*
Content-type:application/json
Content-Length: 18
{"name":"ME","id":1}
DEBUG 2018-11-26 16:15:24,861 [[MuleRuntime].cpuLight.03:
[troubleshooting_myapi].troubleshooting_myapiFlow2.CPU_LITE #541c15d] [event:
0-a0773d60-f1af-11e8-9c18-70886b824af4]
org.mule.service.http.impl.service.HttpMessageLogger.HTTP_Listener_config: LISTENER
HTTP/1.1 200
Content-Type: application/json; charset=UTF-8
Transfer-Encoding: chunked
Date: Mon, 26 Nov 2018 19:15:24 GMT
a9
[
{
"name": "ME",
"id": 1
}
]
Try with -D -.
This is what curl -h says about header options
-D, --dump-header <filename> Write the received headers to <filename>
The - instead of filename indicates the stdout.
curl -D - -d "{"""name""":"""ME""","""id""":1}" -H "Content-Type: application/json" -X PUT http://localhost:8081/api/users

Curl API request value in body always null

I have the following controller I am trying to use Curl to test it. The problem is that fiscalId is always null its not reading my post body from curl.
Controler:
[Route("api/token")]
public class TokenController : Controller
{
[HttpPost("changefiscal")]
[Authorize]
public async Task<ActionResult> ChangeFiscal([FromBody] long fiscalId)
{
//fiscalId is always 0
}
}
I have checked the documentation here which says to use the -d parameter and post it as a json object. Unfortunately thats not working
curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://localhost:3000/data
I have tried
curl -d "fiscalId=21875" -H "Content-Type: application/json" -H "Authorization: Bearer XXX" -X POST -i http://localhost:5000/api/token/changefiscal
and
curl -d "{"fiscalId":"21875"}" -H "Content-Type: application/json" -H "Authorization: Bearer XXX" -X POST -i http://localhost:5000/api/token/changefiscal
and
curl -d "{"fiscalId":"21875"}" -H "Content-Type: application/json" -H "Authorization: Bearer XXX" -X POST -i http://localhost:5000/api/token/changefiscal
and
curl -d "{\"fiscalId\":\"21875\"}" -H "Content-Type: application/json" -H "Authorization: Bearer XXX" -X POST -i http://localhost:5000/api/token/changefiscal
and everything else i can think of
I can see in the log that it appears to be sending it
Rebuilt URL to: POST/
timeout on name lookup is not supported
getaddrinfo(3) failed for POST:80
Couldn't resolve host 'POST'
Closing connection 0 curl: (6) Couldn't resolve host 'POST'
timeout on name lookup is not supported
Trying ::1...
TCP_NODELAY set
Trying 127.0.0.1...
TCP_NODELAY set
Connected to localhost (127.0.0.1) port 5000 (#1)
POST /api/token/changefiscal HTTP/1.1
Host: localhost:5000
User-Agent: curl/7.53.1
Accept: /
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IjI2OTAzNzc0NjYyNzc4RDM1MzE2QUUwQUU1MjIyQUU1REIzM0M0NUEiLCJ0eXAiOiJKV1QiLCJ4NXQiOiJKcEEzZEdZbmVOTlRGcTRLNVNJcTVkc3p4Rm8ifQ.eyJuYmYiOjE1MTA1NjcxNzMsImV4cCI6MTUxMDU3MDc3MywiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo1MDAwIiwiYXVkIjpbImh0dHA6Ly9sb2NhbGhvc3Q6NTAwMC9yZXNvdXJjZXMiLCJ0ZXN0YXBpIl0sImNsaWVudF9pZCI6IlNlcnZpY2VBY2NvdW50QWNjZXNzIiwic3ViIjoiMjEyNDg1ODIiLCJhdXRoX3RpbWUiOjE1MTA1NjcxNzMsImlkcCI6ImxvY2FsIiwibmFtZSI6ImxpbGF3IiwiZS1tYWlsIjoibGlsYXdAZWcuZGsiLCJzY29wZSI6WyJvcGVuaWQiLCJwcm9maWxlIiwidGVzdGFwaSJdLCJhbXIiOlsicGFzc3dvcmQiXX0.Q_oJ-xOIKdTtGoRqJbtNjwLV82cQQLhJUVl2Ey-4riZdp45rPIrmfOw9VdknUOLpm8RYZ0iLFC31gCpn1vKb4zLiTmBuTuzYsKxnAvf-UkCj1L8soH4W2lCvx560bZeS7B67tJ4nK9t36OiMLQY4m-_NRTSRBs5QtsXBd5VQGPsTpxf_MxVbQm6Hj6Ot3FGRIa08gmwD3iEr9vsCU6732InbGzU26wtm-WLWp_A_k66Z29G8ms_U8x6gg-aOlQG9_0v_DEjTXCkKNcgWoL0IvaCC0psiYkdIjQxaOwz-e_fcqXpKEFmuoSqmGd1l-eMl3HimOomdOHwqploWGxnJ4Q
Content-Length: 7
upload completely sent off: 7 out of 7 bytes
However when i check fiscalId its always 0 i even tried to change fiscalId to a string and its just null.
When you POST data as JSON object, like -d '{"fiscalId": 21875}', your action method should expect some simple class with corresponding properties. In your case:
public class Dto
{
public long fiscalId {get; set;}
}
and
public async Task<ActionResult> ChangeFiscal([FromBody] Dto data)
Finally after more then an hour of playing with this I got it even though the content-Type is json its just sent as a string "'21875'" even though all the documentation shows sending it as JSon. For some reason the API isnt able to read it as a JSon Object but expects it just to be sent as a string.
curl POST -v -d "'21875'" -H "Content-Type: application/json" -H "Authorization: Bearer XXX" http://localhost:5000/api/token/changefiscal

CURL to POST to JIRA

I am using curl command in powershell in my Windows machine. I am trying to create an issue in JIRA which I have installed in my local. I tried following but it throws me error. Can someone let me know what am I missing and how to fix it?
PS C:\Users\raji> **curl -D- -u raji:raji -X POST --data $parse.json -H
"Content-Type: application/json" http://localhost:8080/rest/api/2/issue**
*curl: (6) Could not resolve host: Content-Type
HTTP/1.1 415 Unsupported Media Type
Server: Apache-Coyote/1.1
X-AREQUESTID: 770x749x1
X-ASEN: SEN-L8183526
Set-Cookie: JSESSIONID=D0B4391C94413FDDB1291C419F3E1360; Path=/; HttpOnly
X-Seraph-LoginReason: OK
Set-Cookie: atlassian.xsrf.token=B3EL-GHY4-P1TP-IMD0|d3d735e0a6566f8a97f99c96e80042551def3192|lin; Path=/
X-ASESSIONID: 1v4terf
X-AUSERNAME: raji
X-Content-Type-Options: nosniff
Content-Type: text/html;charset=UTF-8
Content-Length: 0
Date: Sun, 10 Jul 2016 07:20:36 GMT
*
When I try following I get this error:
PS C:\Users\raji> **curl -D- -u raji:raji -X POST --data #parse.json -H
"Content-Type: application/json" http://localhost:8080/rest/api/2/issue**
*At line:1 char:38
+ curl -D- -u raji:raji -X POST --data #parse.json -H "Content-Type: ap ...
+ ~~~~~~
The splatting operator '#' cannot be used to reference variables in an expression. '#parse' can be used only as an argument to a command. To reference variables in an expression use '$parse'.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : SplattingNotPermitted*
And hence I tried $ instaed of # in file name.
"parse.json" File has following content:
{
"fields": {
"project":
{
"key": "Demo"
},
"summary": "REST ye merry gentlemen",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Bug"
}
}
}
As this is windows machine, I also tried using slash (/) in parse.json file (saw in few posts that / will remove the error) but that also did not help. Please can someone let me know how to fix this?
In the first case
curl -D- -u raji:raji -X POST --data $parse.json -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue
$parse is interpreted by powershell as variable, $parse.json as attribute json of the variable $parse, which does not exist, so the command executed would be
curl -D- -u raji:raji -X POST --data -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue
data is -H, and the content type header is interpreted as url to access.
In the second case the # in powershell is interpreted as splat operator, if you want a literal # (which is interperted by curl and not by powershell), simply quote the string:
curl -D- -u raji:raji -X POST --data "#parse.json" -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue
Now it should use the contents of the file parse.json as data.

How to pass payload via JSON file for curl?

I can successfully create a place via curl executing the following command:
$ curl -vX POST https://server/api/v1/places.json -d "
auth_token=B8dsbz4HExMskqUa6Qhn& \
place[name]=Fuelstation Central& \
place[city]=Grossbeeren& \
place[address]=Buschweg 1& \
place[latitude]=52.3601& \
place[longitude]=13.3332& \
place[washing]=true& \
place[founded_at_year]=2000& \
place[products][]=diesel& \
place[products][]=benzin \
"
The server returns HTTP/1.1 201 Created.
Now I want to store the payload in a JSON file which looks like this:
// testplace.json
{
"auth_token" : "B8dsbz4HExMskqUa6Qhn",
"name" : "Fuelstation Central",
"city" : "Grossbeeren",
"address" : "Buschweg 1",
"latitude" : 52.3601,
"longitude" : 13.3332,
"washing" : true,
"founded_at_year" : 2000,
"products" : ["diesel","benzin"]
}
So I modify the command to be executed like this:
$ curl -vX POST http://server/api/v1/places.json -d #testplace.json
This fails returning HTTP/1.1 401 Unauthorized. Why?
curl sends POST requests with the default content type of application/x-www-form-urlencoded. If you want to send a JSON request, you will have to specify the correct content type header:
$ curl -vX POST http://server/api/v1/places.json -d #testplace.json \
--header "Content-Type: application/json"
But that will only work if the server accepts json input. The .json at the end of the url may only indicate that the output is json, it doesn't necessarily mean that it also will handle json input. The API documentation should give you a hint on whether it does or not.
The reason you get a 401 and not some other error is probably because the server can't extract the auth_token from your request.
To clarify how to actually specify a file that contains the JSON to post, note that it's with the # sign as shown in the OP
e.g. a typical post to a local .NET Core API:
curl -X POST https://localhost:5001/api -H "Content-Type: application/json" -d #/some/directory/some.json
You can cat the contents of a json file to curl via the --data-raw parameter
curl https://api.com/route -H 'Content-Type: application/json' --data-raw "$(cat ~/.json/payload-2022-03-03.json | grep -v '^\s*//')"
curl https://api.com/route -H 'Content-Type: application/json' -d #<(jq . ~/.json/payload-2022-03-03.json)
curl https://api.com/route -H 'Content-Type: application/json' -d #<(jq '{"payload": .}' < ~/.json/payload-2022-03-03.json)
Note: comments in the json file are filtered out via grep -v '^\s*//'
You can also pass the data to curl via stdin using grep or cat or jq
grep -v '^\s*//' ~/.json/payload-2022-03-03.json | curl https://api.com/route -H 'Content-Type: application/json' -d #-
cat ~/.json/payload-2022-03-03.json | grep -v '^\s*//' | curl https://api.com/route -H 'Content-Type: application/json' -d #-
jq . ~/.json/payload-2022-03-03.json | curl https://api.com/route -H 'Content-Type: application/json' -d #-
jq '{"payload": .}' < ~/.json/payload-2022-03-03.json | curl https://api.com/route -H 'Content-Type: application/json' -d #-