Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Introduction

Now it is possible for 3rd party apps to can get and edit lookup tables with the newly added REST endpoints

...

Expand
titleAdd a new table (POST)

METHOD

URL

Data

Sample Code

POST

/rest/lookuprestresource/1.0/lookup/table

The data should be a valid JSON string containing the following information:

  • Name of the new table

  • Columns name of the new table

Example

Code Block
{
   "name":"New_Table",
   "columns": ["Column_1, Column_2"]
}
Code Block
def bodyData = 'data={"name":"New_Table","columns":["Column_1","Column_2"]}'
def responseData = sendPostRequest("/rest/lookuprestresource/1.0/lookup/table",bodyData)
//{columns=[{id=22, name=Column_1}, {id=23, name=Column_2}], name=New_Table, id=11}

Return the an array of rows information for a table

Example

Expand
titleUpdate an existing table (PUT)
Expand
titleGet rows information for a table (GET)

METHOD

URL

Data

Sample Code

GET

/rest/lookuprestresource/1.0/lookup/table/{TABLE_ID}/entries

Code Block
[
   {
      "4":"Confuence",
      "5":"Leon",
      "id":7,
      "tableid":2
   },
   {
      "4":"Jira",
      "5":"admin",
      "id":15,
      "tableid":2
   }
]
Code Block//Get the rows information

METHOD

URL

Data

Sample Code

PUT

/rest/lookuprestresource/1.0/lookup/table/{TABLE_NAME}

Expand
titleDelete an existing table (DELETE)

METHOD

URL

Data

Sample Code

DELETE

/rest/lookuprestresource/1.0/lookup/table/{TABLE_ID}

Code Block
//Delete the data for table id 2
sendDeleteRequest("/rest/lookuprestresource/1.0/lookup/table/2")

Table row

The data should be a valid JSON string containing the following information:

  • Name of the table

  • Columns name of the table

  • Mode of the action

    • append: Add the entries to the existing table. New table will be created if no existing table is found

    • overwrite: Remove the existing table and add the entries

  • Entries of the table

    • The first entry must be the column names

Example

Code Block
{
   "name":"New_Table",
   "columns": ["Column_1, Column_2"],
   "mode": "overwrite",
   "result":[["Column_1","Column_2"],["admin","This is a message"]]
}
Code Block
def bodyData = '{"name":"New_Table","columns":["Column_1","Column_2"],"mode":"overwrite","result":[["Column_1","Column_2"],["admin","This is a message"]]}';
def responseData = sendPutRequest("/rest/lookuprestresource/1.0/lookup/table/New_Table",bodyData)
Expand
titleDelete an existing table (DELETE)

METHOD

URL

Data

Sample Code

DELETE

/rest/lookuprestresource/1.0/lookup/table/{TABLE_ID}

-

Code Block
//Delete the data for table id 2
def data = sendGetRequest("
sendDeleteRequest("/rest/lookuprestresource/1.0/lookup/table/2
/entries") data.each{val -> //TODO }
")

Table row

/rest/lookuprestresource/1
Expand
titleAdd a new row in Get rows information for a table (POSTGET)

METHOD

URL

Data

Sample Code

POST

GET

/rest/lookuprestresource/1.0/lookup/table/{TABLE_ID}/entries

The row data should be a valid JSON string containing the following information:

  • KEY: column id

  • VALUE: cell data

Return the an array of rows information for a table

Example

Code Block
[
   {
      "4":"
Jira 8
Confuence",
      "5":"
admin
Leon"
}
Code Block
def bodyData = '{"4":"Jira 8","5":"admin"}'
def responseData = sendPostRequest("/rest/lookuprestresource/1.0/lookup/table/2/entries", bodyData)
//Sample responseData: {4=Jira, 5=admin, id=20, tableid=2}
Expand
titleUpdate an existing row in a table (PUT)

METHOD

URL

Data

Sample Code

PUT

,
      "id":7,
      "tableid":2
   },
   {
      "4":"Jira",
      "5":"admin",
      "id":15,
      "tableid":2
   }
]

Code Block
//Get the rows information for table id 2
def data = sendGetRequest("/rest/lookuprestresource/1.0/lookup/table/2/
{TABLE_ID}/entries/{ROW_ID}The data should be a valid JSON
entries")
data.each{val -> 
  //TODO
}

Expand
titleAdd a new row in a table (POST)

METHOD

URL

Data

Sample Code

POST

/rest/lookuprestresource/1.0/lookup/table/{TABLE_ID}/entries

The row data should be a valid JSON string containing the following information:

  • KEY: column id

  • VALUE: cell data

Example

Code Block
{
   "4":"Jira 8",
   "5":"
admin1
admin"
}
Code Block
//Update the data for row id 20 def bodyData = '
def bodyData = 'data={"4":"Jira 8","5":"
admin1
admin"}'
def responseData = 
sendPutRequest
sendPostRequest("/rest/lookuprestresource/1.0/lookup/table/2/entries
/20
", bodyData)
//Sample responseData: {4=Jira, 5=
admin1
admin, id=20, tableid=2}
Expand
titleDelete Update an existing row in a table (DELETEPUT)

METHOD

URL

Data

Sample Code

DELETE

PUT

/rest/lookuprestresource/1.0/lookup/table/{TABLE_ID}/entries/{ROW_ID}

The data should be a valid JSON string containing the following information:

  • KEY: column id

  • VALUE: cell data

Example

Code Block
//Delete
{
the
 
data
 
for row id 20 sendDeleteRequest("/rest/lookuprestresource/1.0/lookup/table/2/entries/20")

Table Column

Expand
titleGet columns information for a table (GET)

METHOD

URL

Data

Sample Code

GET

 "4":"Jira",
   "5":"admin1"
}
Code Block
//Update the data for row id 20
def bodyData = 'data={"4":"Jira","5":"admin1"}'
def responseData = sendPutRequest("/rest/lookuprestresource/1.0/lookup/table
/{TABLE_ID}/columns

Return the columns information for a table

Example

Code Block{ "columns":[ { "id":4, "name":"Application" }, { "id":5, "name":"App Owner" } ],
/2/entries/20",bodyData)
//Sample responseData: {4=Jira, 5=admin1, id=20, tableid=2}
Expand
titleDelete an existing row in a table (DELETE)

METHOD

URL

Data

Sample Code

DELETE

/rest/lookuprestresource/1.0/lookup/table/{TABLE_ID}/entries/{ROW_ID}

Code Block
//Delete the data for row id 20
sendDeleteRequest("/rest/lookuprestresource/1.0/lookup/table/2/entries/20")

Table Column

Expand
titleGet columns information for a table (GET)

METHOD

URL

Data

Sample Code

GET

/rest/lookuprestresource/1.0/lookup/table/{TABLE_ID}/columns

Return the columns information for a table

Example

Code Block
{
   "columns":[
      {
         "id":4,
         "name":"App Mapping",
   "id":2
}
Code Block
//Get the columns information for table id 2
def data = sendGetRequest"Application"
      },
      {
         "id":5,
         "name":"App Owner"
      }
   ],
   "name":"App Mapping",
   "id":2
}

Code Block
//Get the columns information for table id 2
def data = sendGetRequest("/rest/lookuprestresource/1.0/lookup/table/2/columns")
data.each{val -> 
  //TODO
}

Expand
titleAdd a new column in a table (POST)

METHOD

URL

Data

Sample Code

POST

/rest/lookuprestresource/1.0/lookup/table/{TABLE_ID}/column

The column name

Example:

Code Block
COLUMN_NAME
Code Block
def bodyData = 'columnName=COLUMN_NAME'
def responseData = sendPostRequest("/rest/lookuprestresource/1.0/lookup/table/2/column",bodyData)
Expand
titleUpdate an existing column in a table (PUT)

METHOD

URL

Data

Sample Code

PUT

/rest/lookuprestresource/1.0/lookup/table/{TABLE_ID}/column/{COLUMN_ID}

The new column name

Example:

Code Block
NEW_COLUMN_NAME
Code Block
def bodyData = 'newColumnName=NEW_COLUMN_NAME'
def responseData = sendPutRequest("/rest/lookuprestresource/1.0/lookup/table/2/column/6",bodyData)
Expand
titleDelete an existing column in a table (DELETE)

METHOD

URL

Data

Sample Code

DELETE

/rest/lookuprestresource/1.0/lookup/table/{TABLE_ID}/column/{COLUMN_ID}

-

Code Block
def responseData = sendDeleteRequest("/rest/lookuprestresource/1.0/lookup/table/2/column/
columns
6")
data.each{val -> //TODO }

Useful Methods

Expand
titleSend GET request
Code Block
def sendGetRequest(url) {
    def log = Logger.getLogger("LookupManager")
    log.setLevel(Level.DEBUG)

    //Step 1: Set base URL, E.g. http://localhost:2990/jira
    def baseUrl = "http://localhost:2990/jira";

    //Step 2: Set username and password
    def userName = "admin"
    def password = "admin"

    def http = new HTTPBuilder(baseUrl + url)
    http.request(GET) {
        headers.
        'Authorization' = "Basic " + ((userName + ":" + password).bytes.encodeBase64().toString())
        headers.
        'X-Atlassian-Token' = 'no-check';
        requestContentType = URLENC

        response.success = {resp, data ->
            log.debug("SUCCESS: " + resp.status)
            log.debug(data)
        }

        response.failure = { resp,data ->
            log.error("ERROR: " + resp.status)
            log.error(data)
        }
    }
}

...

Expand
titleSend PUT request with data
Code Block
def sendPostRequest(url, bodyData) {
    def log = Logger.getLogger("LookupManager")
    log.setLevel(Level.DEBUG)
    
    def json = new groovy.json.JsonBuilder()

    //Step 1: Set base URL, E.g. http://localhost:2990/jira
    def baseUrl = "http://localhost:2990/jira";

    //Step 2: Set username and password
    def userName = "admin"
    def password = "admin"

    def http = new HTTPBuilder(baseUrl + url)
    http.request(PUT) {
        headers.
        'Authorization' = "Basic " + ((userName + ":" + password).bytes.encodeBase64().toString())
        headers.
        'X-Atlassian-Token' = 'no-check';
        requestContentType = URLENC
        body = "data=" + bodyData


        response.success = {resp, data ->
            log.debug("SUCCESS: " + resp.status)
            log.debug(data)
            return data
        }

        response.failure = { resp,data ->
            log.error("ERROR: " + resp.status)
            log.error(data)
            return null
        }
    }
}

...