REST API Search

Is it possible to issue a REST API call with DEVONagent Pro? I’d love to setup scheduled searches against the company Jira database, and Atlassian supports a REST API, but I don’t see a way to currently do this inside the app.

Atlassian gives this example with curl:



curl --user email@example.com:<api_token> \
  --header 'Accept: application/json' \
  --url 'https://your-domain.atlassian.net/rest/api/2/search'


I imagine the ability to configure REST searches combined with the intelligence of DEVONagent would be incredibly useful in many other circumstances. Is there currently any way to do this, perhaps with AppleScript or something?

DEVONagent can handle JSON which seems to be returned by this server and can also send both GET and POST requests, therefore this should be at least theoretically possible. But it’s hard to tell without any real-world example.

Ok, thanks. I’m afraid I can’t give real-world examples in a public forum, since this is our private company wiki. I can say that I’m almost there. In the DA browser I can submit the URL:


https://companyname.atlassian.net/wiki/rest/api/search?cql=type=page++and+title+~+test

And get back JSON with results in the browser, but when I add that URL to the plugin I’m trying to build, I get back zero results.



	<key>EngineUrl</key>
	<string>https://companyname.atlassian.net/wiki/rest/api/search?cql=type=page++and+title+~+_agentQuery_</string>


I think I might be getting back a 401 unauthorized code, but I’m not sure. If I double-click the Address in the DA log the URL opens in the DA browser and I get back the correct JSON results.

The site supports basic auth, but I don’t see a way to enter my username and password into DA. I’ll try encoding it into the URL.

Anyway, long story short, it’d be cool to search Confluence and maybe even Jira with DEVONagent.

Could you at least post the JSON output? Because the plugin needs additional information to retrieve the results (e.g. their title, description and link).

Sure, here’s some screenshots as well.


{
  "results": [
    {
      "content": {
        "id": "45809666",
        "type": "page",
        "status": "current",
        "title": "Promoting companyname CloudFormation/CodeDeploy System to Production",
        "childTypes": {},
        "restrictions": {},
        "_expandable": {
          "container": "",
          "metadata": "",
          "extensions": "",
          "operations": "",
          "children": "",
          "history": "/rest/api/content/45809666/history",
          "ancestors": "",
          "body": "",
          "version": "",
          "descendants": "",
          "space": "/rest/api/space/RED"
        },
        "_links": {
          "webui": "/spaces/RED/pages/45809666",
          "self": "https://companyname.atlassian.net/wiki/rest/api/content/45809666",
          "tinyui": "/x/AgC7Ag"
        }
      },
      "title": "Promoting @@@hl@@@companynameapp@@@endhl@@@ CloudFormation/CodeDeploy System to Production",
      "excerpt": "2016-12-15_system-architecture.jpg\n\n\nOverview\n\nThe goal of this project is to mirror the current QA system in production and replace the single instance that currently hosts both application and the daemon, and to do the replacement with as little down time as possible for either application",
      "url": "/spaces/RED/pages/45809666",
      "resultGlobalContainer": {
        "title": "SysAdmin",
        "displayUrl": "/spaces/RED"
      },
      "breadcrumbs": [],
      "entityType": "content",
      "iconCssClass": "aui-iconfont-page-default",
      "lastModified": "2016-12-20T19:24:33.201Z",
      "friendlyLastModified": "Dec 20, 2016",
      "score": 9.472269
    }
  ],
  "start": 0,
  "limit": 25,
  "size": 1,
  "totalSize": 1,
  "cqlQuery": "type=page  and title ~ application",
  "searchDuration": 40,
  "_links": {
    "base": "https://companyname.atlassian.net/wiki",
    "context": "/wiki"
  }
}

Eh, sorry, I don’t know how to resize those appropriately.

JSON/XML results require the definition of key paths (see ResultsKeyPath, TitlesKeyPath, DescriptionsKeyPath, DatesKeyPath and LinksKeyPath), here’s a simple template which might or might not work.

You still have to change the EngineUrl value (and maybe the OffsetPerPage, ResultsPerPage and Start values but these are not critical):


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Description</key>
	<string></string>
	<key>DatesKeyPath</key>
	<string>lastModified</string>
	<key>DescriptionsKeyPath</key>
	<string>excerpt</string>
	<key>EngineUrl</key>
	<string>Insert URL here</string>
	<key>Identifier</key>
	<string>atlassian.net</string>
	<key>Info</key>
	<string>atlassian.net Plugin</string>
	<key>LinksKeyPath</key>
	<string>url</string>
	<key>Name</key>
	<string>atlassian.net</string>
	<key>OffsetPerPage</key>
	<integer>1</integer>
	<key>Operators</key>
	<integer>59</integer>
	<key>ParseLinks</key>
	<false/>
	<key>PostScan</key>
	<false/>
	<key>ResultsKeyPath</key>
	<string>results</string>
	<key>ResultsPerPage</key>
	<integer>50</integer>
	<key>Start</key>
	<integer>1</integer>
	<key>TitlesKeyPath</key>
	<string>title</string>
	<key>Version</key>
	<string>1.0</string>
</dict>
</plist>

Thanks! Not quite there yet, but I’m starting to get the feeling that this isn’t DEVONagent’s fault. I’ll keep plugging away at it and see if I can get anywhere. Thanks again, I appreciate the help.

I have a related question to this. What if a key is nested, for example like this?


"data": [
  {
    "content": { "excerpt": "foo" },
  }
]

Do I need to tell DEVONagent that the description/content is under content.excerpt or is it able to find the correct nested key by itself?
I am trying to get a similar JSON-based search engine to play with DEVONagent and have some problems with nested keys

Assuming that ResultsKeyPath is “data”, then “content.excerpt” should work.