gophabricator

Curl command for conduit API


I've been trying to invoke conduit api using curl to add member to specific project and wrote following command:

curl https://test-caxzj6a226zp.phacility.com/api/project.edit -d api.token=api-[token] -d transactions[0][type]=parent -d transactions[0][value]=[project-phid] -d transactions[0][type]=members.add -d transactions[0][value][]=[user-phid]

I've followed the instructions on https://secure.phabricator.com/conduit/method/project.edit/ and was able to query project.search and user.search. But project.edit is giving me trouble. Any help will be appreciated.

PS: I get the following error: {"result":null,"error_code":"ERR-CONDUIT-CORE","error_info":"Validation errors:\n - Projects must have a name."}


Solution

  • You have a few errors in your call. First one is that you're specifying two transactions to apply within the same index. Formatting your call a bit, we get:

    curl https://test-caxzj6a226zp.phacility.com/api/project.edit \
        -d api.token=api-[token] \
        -d transactions[0][type]=parent \
        -d transactions[0][value]=[project-phid] \
        -d transactions[0][type]=members.add \
        -d transactions[0][value][]=[user-phid]
    

    You have two definitions for transactions[0], if you want to apply multiple transformations, you need to increment your index:

    curl https://test-caxzj6a226zp.phacility.com/api/project.edit \
        -d api.token=api-[token] \
        -d transactions[0][type]=parent \
        -d transactions[0][value]=[project-phid] \
        -d transactions[1][type]=members.add \
        -d transactions[1][value][]=[user-phid]
    

    Now, you didn't actually mention wanting to change the parent project, so I'm going to remove that transaction.

    curl https://test-caxzj6a226zp.phacility.com/api/project.edit \
        -d api.token=api-[token] \
        -d transactions[0][type]=members.add \
        -d transactions[0][value][]=[user-phid]
    

    The users to add is also an array, so you need to specify an index for that argument:

    curl https://test-caxzj6a226zp.phacility.com/api/project.edit \
        -d api.token=api-[token] \
        -d transactions[0][type]=members.add \
        -d transactions[0][value][0]=[user-phid]
    

    You could add additional users using -d transactions[0][value][1]=[user-phid], -d transactions[0][value][2]=[user-phid] etc.

    Finally, you also need to specify which project you want to add the member to, since it's a required field. To do this, specify the project's numeric id (you can find this in its URL, /project/view/1/), its PHID, or its name/slug.

    curl https://test-caxzj6a226zp.phacility.com/api/project.edit \
        -d api.token=api-[token] \
        -d transactions[0][type]=members.add \
        -d transactions[0][value][0]=[user-phid] \
        -d objectIdentifier=[project-phid]
    

    You can actually submit a test call to conduit from within the conduit application, and after submitting it, one of the tabs in the example section will display the curl call required to perform that action via the API:

    https://secure.phabricator.com/conduit/method/project.edit/ Example curl call