Creating new maniphest task with javascript

After many trial and errors, I came down to this and still getting an error “transactions” is not a list of transactions. What is wrong with this payload?

var payload = {
    "api.token": PHAB_TOKEN,
    transactions: [{"type": "title", "value": "test"}],
    output: 'json'
  };
  
  var options = {
    method: 'post',
    payload: payload,
  };
  
  var resp = UrlFetchApp.fetch("https://xxxxxxx/api/maniphest.edit", options);

did you try putting “transactions” ? (quotes?)

You mean like this right?

{
    "api.token": PHAB_TOKEN,
    "transactions": [{"type": "title", "value": "test"}],
    output: 'json'
  }

I did. But same error.

And I’ve tried this too

{ "0": {"type": "title", "value": "test"} }

maybe try to JSON.stringify() the transactions value before making the call?

Can you link to the documentation you’re referencing which suggests this is the right way to build a Conduit API request?

Thanks for your answer. I’ve tried that but also getting the same error. :frowning:

I was referring to these two pages mainly, plus some trial an error to weed out errors such as 500, missing token and unknown key names.

https://secure.phabricator.com/book/phabricator/article/conduit_edit/
https://secure.phabricator.com/conduit/method/maniphest.edit/

And the second link has a form that I could test out. And therefore I inspected the request and found that the payload is actually params[transactions]: [{"type": "title", "value": "test"}] as form data.

And the code I have is submitting form data according to google’s documentation.

And also, I learned that, from trying out with the form on the second link, “transactions” is the correct key name and an JSON stringify array is the expected payload format – I’ve got this same ‘“transactions” is not a list of transactions’ error from the form too when I didn’t use the array format.

Unfortunately, I didn’t find any reference to the javascript implementation.

Instead of reverse engineering the wire protocol from the web UI, use the web UI to make a call, then scroll down to “Examples” to see exactly how to format that call.

The three supported callers today are arc call-conduit, cURL (which is “form-encoded”), and PHP. Reverse-engineering blobs of JSON is not supported.

See also https://secure.phabricator.com/T12447.

Thanks for the help.

I actually would need to do this in javascript. And as I mentioned, I followed the Google doc and this call is supposed to submit as form data instead of a JSON blob, which should be the equivalent to the documentation you screenshot above.

Do you know why submitting form data isn’t working?

Is there any javascript example you can point to me?

https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app

It may not be supported but there are 3rd party code out there that can help you form the correct json to talk to phabricator for those of us who are connecting from other languages. two good examples are here.


The both libraries in a round about fashion create json the following form.

params.__conduit__ = { token: this.token };

var req = request.post(this.api + route, {
    json: true,
    form: {
      output: 'json',
      params: JSON.stringify(params)
    }
  }, cb);

You need to put the api parameters into the params structure from what I remember.

I’d start with a simpler request first (conduit.ping) until you get the correct payload structure

I guess at any time the format could be changed as its not supported.

1 Like

Thanks for the reply. With your hint, I was able to find the solution. Sharing it here.

  var payload = {
    "params": JSON.stringify({
      "__conduit__": { token: PHAB_TOKEN },
      "transactions": [{"type": "title", "value": "test"}],
    }),
    output: 'json'
  };

Hope this helps anyone that stumble upon this. And honestly, this is probably one of the more painful api integration due to the lack of documentation which imho should be such a low hanging fruit as an improvement…

I mean seriously examples in php and curl? @epriestley