Skip to main content
Question

JSON files in Powershell


Forum|alt.badge.img+1

Hi,

We use a separate asset management system for adminstrating all of our assets. This includes assets like, windows laptops, monitors and our apple devices. To make things a bit easier for my colleagues, we have build a tool that helps them register the assets in our tool. Besides registering the assets in our asset tool, we generate a csv that we send to one of the colleagues so he can import that one for preloading the devices into JAMF. He now asked me to, if it is possible to stop sending the CSV and immediately insert the devices into JAMF. Using the API this should not be a problem. If you use curl, it works like a charm.

However, The tool we use is based on powershell and powershell uses invoke-restmethod instead of curl. And somehow i don't manage to get it working. I keep getting a 400 - bad request, that looks like the json file is not right. But when i use the json in the JAMF API reference and test is (which uses curl), there is no problem. I'm getting a little desperate right now. Is there someone who can show me what's wrong?

I'm using the following script (I left out the authentication, for obvious reasons :) )

$inputdata = @"
{
  "serialNumber" : "CXXXXXXXXX",
  "deviceType" : "Computer",
  "poNumber" : "123456789",
  "poDate": "2018-06-06",
  "warrantyExpiration" : "2019-06-06",
  "lifeExpectancy" : "4 years",
  "purchasePrice" : "399",
  "assetTag" : "999999X",
  "vendor" : "Apple",
  "extensionAttributes" : [
    {
      "name" : "Hardware Expiration Date",
      "value" : "2022-06-05"
    }
   ]
  }
"@

$uri = "https://ourjssurl:8443/api/v2/inventory-preload/records"
$headers = @{Authorization = "Bearer $bearertoken";Accept = 'application/json'}
$body = @{input_data=$inputData;format='json'}
$jamfresponse = Invoke-RestMethod -Method POST -Uri $uri -ContentType 'application/json' -Headers $headers -Body $body -UseBasicParsing

0 replies

Be the first to reply!

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings