0

I am having trouble with creating POST JOB (new name for registration of file in OSS for translation). I have already uploaded ZIP file to the bucket (containing 2 revit files, first is root, second is a revitlink) using segment upload, have its URN and now I want to trigger translation to SVF. For this purpose I am using this piece of code (used Restharp, Newtonsoft.Json):

    public void CreatePostJOB(string serviceUrl, string urn, string rootFile, string token)
    {
        try
        {
            RestClient client = new RestClient(serviceUrl);
            RestRequest request = new RestRequest();

            request.Method = Method.POST;
            request.Resource = "modelderivative/v2/designdata/job";
            request.RequestFormat = DataFormat.Json;

            request.AddParameter("Authorization", "Bearer " + token, ParameterType.HttpHeader);
            request.AddParameter("x-ads-force", true);
            request.AddParameter("Content-Type", "application/json");

            JObject jsonbody = new JObject
                    (
                        new JProperty("input", new JObject
                            (
                                new JProperty("urn", urn),
                                new JProperty("compressedUrn", true),
                                new JProperty("rootFileName", rootFile)
                            )),
                        new JProperty("output", new JObject
                            (
                                new JProperty("formats", new JArray
                                    (
                                        new JObject
                                                (
                                                    new JProperty("type", "svf"),
                                                    new JProperty("views", new JArray("3d", "2d"))
                                                )
                                    ))
                            ))
                    );


            string post = jsonbody.ToString(Formatting.Indented);

            request.AddParameter("application/json", post, ParameterType.RequestBody);

            IRestResponse resp = client.Execute(request);

            if (resp.StatusCode == HttpStatusCode.OK)
            {
                //TODO
            }
        }
        catch (Exception ex)
        {
            //TODO
        }
    }

Code above will produce following JSON into post variable:

{
  "input": {
    "urn": "/*urn base64 string with no padding*/",
    "compressedUrn": true,
    "rootFileName": "MainModel_A.rvt"
  },
  "output": {
    "formats": [
      {
        "type": "svf",
        "views": [
          "3d",
          "2d"
        ]
      }
    ]
  }

No matter how I change this code result is always the same:

{"diagnostic":"Request body is not a valid json"}

I also tried to use ordinary C# WebRequest with same result. Maybe there is a bug, because other calls from the same API works with restsharp like a charm. Please how do I create a valid post job in C#?

2 Answers2

0

I am not sure if it is case sensitive, but it looks you wrote as 'rootFileName' while the help says 'rootFilename'

I happened to write a blog on such topic yesterday. I also provided a test harness which works well with demo Revit file (with linked file) . If your files are not large, could you give it a check with my test harness (Node.js) in that blog? I have not added resumable uploading, so it is better to test the relatively small files.
http://adndevblog.typepad.com/cloud_and_mobile/2016/07/translate-referenced-files-by-derivative-api.html

If this does not work, could you send me the URN (you can mail me at xiaodong.liang@autodesk.com). I can consult with our team at back-end.

Regards,

Xiaodong Liang

Forge Adovater

Developer Technical Services

Autodesk

Xiaodong Liang
  • 2,051
  • 2
  • 9
  • 14
  • I tried both actually, this is just a typo. Unfortunately,I have no possibility of testing anything running on Node.js since I have absolutely no experience with that and my question is related to C#, because this code is going to run on server windows service. – Jaroslav Daníček Jul 29 '16 at 12:32
  • Works fine on our node samples so at least it shows that there is no bug with the API at this point. What I would recommend you to do is first test with a simple non-compressed file, and also test with a REST client such as postman, the derivative POST endpoint, we have a post there describing how to do: http://adndevblog.typepad.com/cloud_and_mobile/2016/06/using-3-legged-oauth-for-forge-apis-with-postman.html. – Felipe Jul 29 '16 at 13:03
  • I tried non-compressed file with same result, I will look on postman and update soon – Jaroslav Daníček Jul 29 '16 at 13:08
  • I tried postman, got token but there seems to be a problem, because it only can do 3-legged authorization, when I wnat i get eg. bucket object details it shows "ACM check failed, user or calling service does not have access to perform this operation". Still do not understand how this is supposed to help me with my C# question.. – Jaroslav Daníček Jul 29 '16 at 14:37
0

As mentioned by @XiaodongLiang, use the rootFilename (exactly like this), otherwise will not recognize.

Now your C# code should be (worked on my end):

RestClient client = new RestClient(serviceUrl);
RestRequest request = new RestRequest();
request.Method = Method.POST;
request.Resource = "modelderivative/v2/designdata/job";
request.AddHeader("Accept", "application/json");
request.AddParameter("Authorization", "Bearer " + token, ParameterType.HttpHeader);
request.AddParameter("application/json", jsonbody.ToString(Formatting.None), ParameterType.RequestBody);

IRestResponse resp = client.Execute(request);

if (resp.StatusCode == HttpStatusCode.OK)
{
  //TODO
}

And I would suggest you change your app.config with this parameters, which should help you debug your requests (in this case, the headers).

Community
  • 1
  • 1
Augusto Goncalves
  • 8,493
  • 2
  • 17
  • 44
  • I changed AddParameter calls to AddHeader and the result error stayed 400 - BAD REQUEST, only error message changed to: "Failed to trigger translation for this file." Hard to say if fact that resumable upload was used can affect this. – Jaroslav Daníček Jul 29 '16 at 16:14
  • that means the translation is not working... the JSON request is ok. Are you using a .zip with all the .rvt on it? Can you add more info? – Augusto Goncalves Jul 29 '16 at 16:30
  • also note your original code uses compressedUrn=true, meaning it's a .zip with all the .rvt files on it. Is that the case? If you only have a .rvt, just pass the urn of it. – Augusto Goncalves Jul 29 '16 at 16:45
  • I finally make it working, there was a problem with missing extension which apparently is mandatory when choosing objectKey for the file. Documentation is a little bit confusing about that when says "Choose a name for your object. This can be the actual filename or something like a GUID generated by a data management system. There is not obvious if extension has to be preserved." (source: https://developer.autodesk.com/en/docs/data/v2/tutorials/app-managed-bucket/ ) – Jaroslav Daníček Jul 29 '16 at 16:57
  • thanks for sharing. if you just want to upload a file for storage then you can name it whatever you want - extension does not matter. But the Model Derivative API (where you post the translation JOB) will look at the extension to decide which translator to use. – Augusto Goncalves Jul 29 '16 at 17:04
  • @JardaDaníček thanks again for your feedback, just made a request to improve this piece of the documentation. – Augusto Goncalves Jul 29 '16 at 17:30