It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Automation of Object schema export

Is it possible to automate export of some object type tables in csv, for example - after updating information in one object?

 

Or is it possible to make export of some object type in csv, for example, once per hour?

2 comments

Hi Artem,

Object Type

It's not possible to schedule an export in Insight, but we have an open API that could be used so that you can create something on your own, as there is a an end-point to do Bulk Export for object types. 

Method is GET, the endpoint is 

/rest/insight/1.0/objecttype/{id}/export and the returned type is a binary type i.e. a csv file named export.csv. The query parameters are:

  • searchParams: "{"iqlSearch":true,"iqlParams":{"objectTypeId":"{

id}","attributesToDisplay":{"attributesToDisplayIds":["12", "34"]},"page":1,"asc":1,"resultsPerPage":25,"includeAttributes":false,"objectSchemaId":"{

id}","iql":""},"objectSchemaId":"{

id}"}"

  • delimiterValue COLON or other allowed delimiters
  • charEncoder UTF-8 or other supported encoding
  • importable 0 for User Friendly and 1 for Data Consistent.

Also be aware that the parameters in searchParams needs to replaved with your own parameters and if you have more that 25 objects just place that number.

Schema

There isn't any built in support to do this, but I can give you the information about the REST-API call used to create an Export, and that way you could trigger this manually on a scheduled basis.

URL: rest/insight/1.0/objectschema/export/server

Method: Post

Parameters:

The provided JSON needs the following parameters:

  • String fileName (ie schema.zip) (MANDATORY)
  • Integer objectSchemaId (MANDATORY)
  • String objectSchemaName (MANDATORY )
  • String password (OPTIONAL)
  • Boolean includeObjects (OPTIONAL)
  • Integer totalObjectsInExport (Shouldn't be needed)

This will export it to the server at export/insight in the home directory. You could then optionally copy this export and move it somewhere else.

If you need help on creating such a script, you could get in contact with one of out partners. Riada Partners extends the value of our products. If you need a plugin on top of Insight, a migration done, product training, support with a license purchase or help with setup and config, we’ve got the partner for the job. For more information, take a look at https://riada.se/partners/

 

If you feel like this answered your question, please mark it as accepted :)

 

Cheers!
Alexander

Hi, Alexander!

I tried to use GET Method: http://sd.dev.fxclub.org:8080/rest/insight/1.0/objecttype/798/export , where 798 is ID of objecttype PC/Laptop in my ObjectSchema, but i have received error(500 Internal Server Error). Code of error can be seen here: https://pastebin.com/gASM5fzn.

Can you help me?

Hi Artem,

You are missing parameters on the URL,

I have attached an example from using restlet client that you can use to build up the query parameters. They are mentioned earlier in this questions.

Screen Shot 2018-04-10 at 14.39.22.png

Basically you are missing the following section  after 798/export in the URL (which of course needs adjustment to your instance:

?searchParams={"iqlSearch":true,"iqlParams":{"objectTypeId":"{1} ","attributesToDisplay":{"attributesToDisplayIds":[ 3587,3593,3594,3598,3603]},"page":1,"asc":1,"resultsPerPage":25,"includeAttributes":false,"objectSchemaId":"{9}","iql":""},"objectSchemaId":"{9}"}&delimiterValue=COLON&charEncoder=UTF8&importable=1

Hello!
My script for backup:

https://github.com/TerAnYu/jira/blob/master/insight_backup.sh

need command-line JSON processor: https://stedolan.github.io/jq/

 

#!/bin/sh
# version: 20190611
# Writer: TerAnYu
# need: command-line JSON processor
# wget https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 -O jq && chmod +x jq
# curl with libssl

url=http://127.0.0.1:8080
listreq=/rest/insight/1.0/objectschema/list
exportreq=/rest/insight/1.0/objectschema/export/server
username="localuser"
password="localpassword"
archpwd=123456
date=`date +"%Y%m%d_%H%M%S"`


data=`curl -s \
--connect-timeout 5 \
-u "${username}":"${password}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-X GET ${url}${listreq}`
    ids=`echo ${data} | ./jq -r '.objectschemas[].id'`
    cnt=0

for i in $ids; do
    name=`echo ${data} | ./jq -r ".objectschemas[${cnt}].name"`
    countobj=`echo ${data} | ./jq -r ".objectschemas[${cnt}].objectCount"`
# echo output: "${cnt}; ${date}; ${i}; ${name}; ${countobj}"
   cnt=$((cnt+1))


param(){
  cat <<EOF
{
"fileName":"${date}_${name}.zip",
"objectSchemaId":"${i}",
"includeObjects":"true",
"password":"${archpwd}",
"objectSchemaName":"${name}",
"totalObjectsInExport":"${countobj}"
}
EOF
}

status_code=$(
curl -s -u ${username}:${password} \
        -H "Content-Type: application/json" \
        --write-out %{http_code} \
        --silent \
        --connect-timeout 5 \
        -X POST \
        --output "/dev/null" \
        --data "$(param)" \
        "${url}${exportreq}"
)

if [ $status_code -ne 200 ] ; then
    echo "Site bad status (${date}_${name}.zip): $status_code"
else
    echo "Site good status (${date}_${name}.zip): $status_code"
fi

done
exit

 

 

Comment

Log in or Sign up to comment
TAGS
Community showcase
Posted in Jira Service Desk

How has Jira Service Desk increased productivity in your org?

Hi Jira Service Desk community, Atlassian is on a mission to unleash the potential of all teams, and we know that tools are just one piece of that puzzle. With Jira Service Desk, we have productiv...

165 views 0 3
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you