Convert Curl to invoke-restMethod

BlackCat 106 Reputation points
2025-03-11T22:29:56.37+00:00

I am trying to use this Curl example and make it work with Powershell. I am stuck at multiple data for "Identifier". this section will create report in CSV format

"report_metadata": {
    "report_type": "orders",
    "columns": [
      {
        "identifier": "order_id"
      },
      {
        "identifier": "order_status"
      },
      {
        "identifier": "serial_number"
      },
      {
        "identifier": "account_id"
      },
      {
        "identifier": "request_state"
      },
      {
        "identifier": "product_name"
      },
      {
        "identifier": "order_created_date"
      },
      {
        "identifier": "additional_email"

How can I create JSON body in Powershell?
I try 
$body = @{identifier = "order_id";"common_name";"sans"};

but it wont like it.

Thanks
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,859 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ian Xue-MSFT 40,591 Reputation points Microsoft External Staff
    2025-03-12T03:30:59.92+00:00

    Hi,

    The ConvertTo-Json cmdlet converts an object to a JSON-formatted string. https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/convertto-json?view=powershell-7.5

    Please note that duplicate keys are not allowed in hash tables.

    $body = @{identifier1 = "order_id"; identifier2 = "common_name"; identifier3 = "sans"}
    $jsonstring= $body | ConvertTo-Json
    

    Best Regards,

    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.