Jira Assets API - Cannot Create Object

Hi there. I’m having quite a bit of trouble with the following endpoint within the Jira Assets API.

https://api.atlassian.com/jsm/assets/workspace/{workspaceId}/v1/object/create

I’m writing a PowerShell script that would create an object within my specified object type, and I keep getting back a strange character: â.

By default, my PowerShell instance uses OEM encoding, and I added [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 at the top to force to use WTF - still didn’t work.

This is my try/catch. Let me know if there’s any additional information needed or if you can help me out.

$Body = @{
        "objectTypeId" = $ObjectTypeID
        "attributes" = @(
            @{
                "objectTypeAttributeId" = "310" 
                "objectAttributeValues" = @(@{ "value" = "Hello" }) # Server name/ID - type: String
            },
            @{
                "objectTypeAttributeId" = "348"
                "objectAttributeValues" = @(@{ "value" = ${OS} }) # OS - type: Object
            },
            @{
                "objectTypeAttributeId" = "344"
                "objectAttributeValues" = @(@{ "value" = "[Description]" }) # Description - type: String
            },
            @{
                "objectTypeAttributeId" = "345"
                "objectAttributeValues" = @(@{ "value" = ${OwnerID} }) # Owner (can have multiple owners by re-copying the attribute { }) - type: Object
            },
            @{
                "objectTypeAttributeId" = "400"
                "objectAttributeValues" = @(@{ "value" = "[Subnet]" }) # Subnet - type: String
            },
            @{
                "objectTypeAttributeId" = "401"
                "objectAttributeValues" = @(@{ "value" = ${NetworkID} }) # Vnet - type: Object
            },
            @{
                "objectTypeAttributeId" = "402"
                "objectAttributeValues" = @(@{ "value" = "[Subscription]" }) # Subscription - type: String
            },
            @{
                "objectTypeAttributeId" = "403"
                "objectAttributeValues" = @(@{ "value" = "[Resource Group]" }) # Resource Group - type: String
            }
        )
    } | ConvertTo-Json -Depth 10

    try {
        $Response = Invoke-RestMethod -Uri $JiraAssetsURL -Headers $Headers -Method Post -Body $Body
        Write-Host "Success! Object Updated:"
        $Response | ConvertTo-Json -Depth 10
    } catch {
        Write-Host "HTTP Status Code: $($_.Exception.Response.StatusCode)"
    }

Hello @SenaAdansi

Break the problem down into smaller, simpler pieces to isolate the place where it’s going wrong.

Instead of declaring $Body as a hash table and converting it to JSON, declare it as a string and use raw JSON. This allows you to:

  1. Do a visual like-for-like comparison with the JSON examples shown in the REST API documentation
  2. Copy and paste your JSON into an online linting tool to validate the syntax and format
  3. Copy and paste your JSON into your API test tool to validate the request outside your PS code

Also, start by setting attributes one asset object at a time to see if it’s just a single attribute that you are doing incorrectly.

Once you have isolated the fault in your JSON or your request, then build the complete request, then switch back to using a converted hash table and confirm you get the same results.

Start with a simple request that works, then add complexity.