Search code examples
attaskworkfront-api

How can I attach a custom form to a Workfront project using the API?


I am working on writing a script to recover deleted custom form data that was stored in our sandbox. I have figured out how to migrate the data itself using the API, but if I try and PUT one of the custom fields on a project which does not have the custom form already attached, it fails.

I need a way to associate a project with a specific custom form. I thought it would be easy to just PUT the GUID of the new form, but when I query a project it seems that custom forms are nested. The form itself is a category within an object code. When I query a project to see its custom forms, I will get a response like this:

{"data":
{"ID":"57461cac0034cad00d494767d4cc2dec",
 "name":"<redacted name>",
 "objCode":"PROJ",
 "objectCategories":
   [{"ID":"57461d790035302a611356a45f8db397",
     "objCode":"OBJCAT","category":
      {"ID":"573c78320153aad411b5730f300d1e5d"
       "name":"Portfolio Planning | Evaluate Project",
       "objCode":"CTGY"
       }
     }]
}
}

The name of the custom form I want to attach is "Portfolio Planning | Evaluate Project" and I have mapped that GUID and the one a level higher (though I don't know what it is). However, I do not know how to pass these values to Workfront and actually tell it to set the objectCategories attribute to the specified array.

I am trying something like the following:

https://<url>/attask/api-internal/project/57bb2d9f02592b41b2c4921c178527e3?apiKey=<key>&objectCategories=[{"ID":"57bc5c8601bbcdaafda4bf11defa4605","objCode":"OBJCAT","category":{"ID":"57bc5b2901ba50a110ca11ee230ac7b5","name":"Portfolio Planning | Evaluate Project","objCode":"CTGY"}}]&method=put"

However, it's failing to run. I'm actually getting an error that 'put' is not a valid HTTP type, but I suspect that's the least of my problems.


Solution

  • Hi Your sytax is a little wrong the object categories is a collection. The propper way to send this would be

    https://<url>/attask/api-internal/project/57bb2d9f02592b41b2c4921c178527e3?apiKey=<key>&updates={"objectCategories":[{"categoryID":"5605787500193fbee202ba3b6d8c12b4","categoryOrder":0,"objCode":"CTGY"}]}&method=put
    

    and if you wanted to add 2 forms you would do this

    https://<url>/attask/api-internal/project/57bb2d9f02592b41b2c4921c178527e3?apiKey=<key>&updates={"objectCategories":[{"categoryID":"5605787500193fbee202ba3b6d8c12b4","categoryOrder":0,"objCode":"CTGY"},"categoryID":"XXXXXX","categoryOrder":1,"objCode":"CTGY"}]}&method=put