Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Assets Import Error for Name (label attribute) when there are spaces

Ste404
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 2, 2023

Hi there,

If I manually create a record in Assets I can use a space when entering a name.

Using the API I am getting an error due to the space.

Is there some sort of encoding that needs to happen for the 'Name' attribute which is the main Label attribute when creating a record via the API.

"Invoke-RestMethod : {"errorMessages":["AQL \"Name = Bowen Hills\" has invalid syntax at position 13 with error message \"mismatched input 'H' expecting {, ' '}\""],"errors":{}}"

 

Is the error, if I remove the space then there is no issue.

2 answers

0 votes
Ste404
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 2, 2023

Here is an example of the body

 

 "objectTypeId": 13,
"attributes": [
{
"objectTypeAttributeId": 120,
"objectAttributeValues": [
{
"value": "Barrow Island"
}
]
},
{
"objectTypeAttributeId": 146,
"objectAttributeValues": [
{
"value": "Gorgon Project - LNG Construction Site"
}
]

 

Attribute 120 is the label...  fails.   146 is just a normal text field, imports fine full of spaces.  it is specific to the attribute set as the label?! 

0 votes
Suzi Firth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 2, 2023

Hi Steven,

This is interesting. I have hundreds of assets with spaces in the Label Attribute and never seen an error like that.

In the attributes of your object schema, what is the Type and Type Value set to?

Suzi

Ste404
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 2, 2023

Just the normal Default Text.

I can import manually from a CSV, manually create in Assets all with spaces..

 

just the API fails to create when there is a space.

Suzi Firth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 2, 2023

Only other thing I can think of is have you put a regular expression in validation for the attribute?

Otherwise, I'd probably recommend logged a ticket with Jira Support.

Suzi

Ste404
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 2, 2023

Do you have a suggestion for the validation.  I can encode the text but it comes over with a " " around it.

I was trying to also see if I could parse it away after the data appears?  do you know if that is possible?

Suzi Firth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 2, 2023

Hmm that's a bother. I think I might be out of the depth on this one. Not sure what's causing the issue. I can't see anywhere in the Jira documentation that says you can't use spaces in labels either. 

Ste404
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 2, 2023

yeh you can use spaces in labels normally (manual csv import or manually creating an object).

It just seems that when it is coming over via the API the AQL is missing the fact it's a string.

I can import them if they have " " around them but then I need to get rid of that AFTER it is in Assets.

I have flung this over to Atlassian.

Like Suzi Firth likes this
Ste404
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 5, 2023

ah such a dope...  I was mucking up my iql call.

I have a function which builds up a key to go look into Assets to find a match or not to either create or update and Object.

I had this;

$iql = $key.name + ' = ' + $key.value

Which for names with spaces was building this Name = First Last

Obviously with that being added to the iql, it was failing.

I changed it to this

$iql = $key.name + ' = ' + '"' + $key.value + '"'
$url = "https://api.atlassian.com/jsm/insight/workspace/$workspaceId/v1/object/navlist/iql"

Now it comes out as Name = "First Last" and what do you know, no error!

Like Suzi Firth likes this
Suzi Firth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 5, 2023

That's great news Steven!

Like Ste404 likes this
Vaishali Patil February 8, 2023

On a related question: what field is used for JSM to figure out an asset is duplicate while importing

Ste404
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 12, 2023

I set a variable in Powershell as part of a mapping function that builds a PSCustomObject;

 $mappings = [PSCustomObject]@{
Imp_Name = [PSCustomObject]@{name="Name"; id=164; value=$user.Name}

 

in another function I set that as the Key

 $key = $data.Imp_Name
$found = Insight-FindObject $key

 

Then in the FindObject function I build up an IQL statement using the key and pass $found back as yes or no basically.  

function Insight-FindObject ($key) {

$iql = $key.name + ' = ' + '"' + $key.value + '"'
$url = "https://api.atlassian.com/jsm/insight/workspace/$workspaceId/v1/object/navlist/iql"

$headers = @{

 

If it finds it, then it will update, if it doesn't find it then a new Object will be created.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events