Callback response for Things?

I’m trying to create a script that sends the selected line to Things as a task, then grabs the callback response from things (supposedly this: “x-things-id // Comma separated string. The IDs of the to-dos created” so that I can create a URL that links back to that task.

However, the context.callbackResponse is coming back “undefined”. I’ve also used context. callbackResponses and still get nothing. Just want to make sure I’m doing it right in Drafts before asking the Things folks if the x-success still works.

let [loc, len] = editor.getSelectedLineRange(),
  str = editor.getTextInRange(loc, len),
  icon = '🔘',
  listTitle = draft.processTemplate("[[title]]"),
  regex = /# /,
  regex2 = /- /;

let todoList = listTitle.replace(regex,"");
let todoTitle = str.trim(); 
todoTitle = todoTitle.replace(regex2,"");


var cb = CallbackURL.create();
const baseURL = "things://x-callback-url/add?"
  cb.baseURL = baseURL;
  cb.addParameter("title",todoTitle);
  cb.addParameter("notes",draft.permalink);
  cb.addParameter("list",todoList);
  cb.waitForResponse = true;
  var success = cb.open();
  if (success) {
    console.log("Task created in Things" + cb.url);
    var response = context.callbackResponse;
  }
  else {
    context.fail();
  }


alert(response);

newStr = icon + ' ' + str;
editor.setTextInRange(loc, len, newStr);
// move the cursor to the end of the edited line
editor.setSelectedRange(loc + newStr.trim().length, 0);
editor.setSelectedText('');
// activate is not required if the action is launched via a keyboard button
editor.activate();

If you are scripting a callbackURL, the CallbackURL object will hold it’s responses, not the context. See: CallbackURL.callbackResponse.

So in this script, you want to look in:

var response = context.callbackResponse;

awesome! This fixed it:

var cb = CallbackURL.create();
const baseURL = "things:///add?"
  cb.baseURL = baseURL;
  cb.addParameter("title",todoTitle);
  cb.addParameter("notes",draft.permalink);
  cb.addParameter("list",todoList);
  cb.waitForResponse = true;
  var success = cb.open();
  if (success) {
    console.log("Task created in Things" + cb.url);
    var response = cb.callbackResponse;
  }
  else {
    context.fail();
  }


alert(response["x-things-id"]);