Skip to main content
added 399 characters in body
Source Link
MKANET
  • 683
  • 7
  • 32
  • 65

I am having trouble converting a working cURL command in Windows to an equivalent PowerShell InvokeRestMethod command. It looks like I am pretty close. I am getting a response. However, the API doesn't seem to understand the nested hash table element "domain" sent by InvokeRestMethod command. All other hash elements seem to be recognized by the API just fine.

cURL command (working)

curl "https://api.rebrandly.com/v1/links" -X POST -H "apikey: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -H "Content-Type: application/json" -d "{ \"destination\": \"http://longurl.com\", \"domain\": {\"fullName\": \"link.domain.com\"}}"

PowerShell:

$body = @{
 "destination"="longurl.com"
 "domain" = @("fullName", "link.domain.com")
} | ConvertTo-Json

$header = @{
 "apikey"="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
 "Content-Type"="application/json"
}

Invoke-RestMethod -Uri "https://api.rebrandly.com/v1/links" -Method 'Post' -Body $body -Headers $header

PS: I also tried using the below syntax. Unfortunately, I get the same result.. where the "domain" hash element is ignored.

$body = @{
 "destination"="longurl.com"
 "domain[0]" = "fullName"
 "domain[1]" = "link.domain.com"
} | ConvertTo-Json

I am having trouble converting a working cURL command in Windows to an equivalent PowerShell InvokeRestMethod command. It looks like I am pretty close. I am getting a response. However, the API doesn't seem to understand the nested hash table element "domain" sent by InvokeRestMethod command. All other hash elements seem to be recognized by the API just fine.

cURL command (working)

curl "https://api.rebrandly.com/v1/links" -X POST -H "apikey: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -H "Content-Type: application/json" -d "{ \"destination\": \"http://longurl.com\", \"domain\": {\"fullName\": \"link.domain.com\"}}"

PowerShell:

$body = @{
 "destination"="longurl.com"
 "domain" = @("fullName", "link.domain.com")
} | ConvertTo-Json

$header = @{
 "apikey"="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
 "Content-Type"="application/json"
}

Invoke-RestMethod -Uri "https://api.rebrandly.com/v1/links" -Method 'Post' -Body $body -Headers $header

I am having trouble converting a working cURL command in Windows to an equivalent PowerShell InvokeRestMethod command. It looks like I am pretty close. I am getting a response. However, the API doesn't seem to understand the nested hash table element "domain" sent by InvokeRestMethod command. All other hash elements seem to be recognized by the API just fine.

cURL command (working)

curl "https://api.rebrandly.com/v1/links" -X POST -H "apikey: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -H "Content-Type: application/json" -d "{ \"destination\": \"http://longurl.com\", \"domain\": {\"fullName\": \"link.domain.com\"}}"

PowerShell:

$body = @{
 "destination"="longurl.com"
 "domain" = @("fullName", "link.domain.com")
} | ConvertTo-Json

$header = @{
 "apikey"="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
 "Content-Type"="application/json"
}

Invoke-RestMethod -Uri "https://api.rebrandly.com/v1/links" -Method 'Post' -Body $body -Headers $header

PS: I also tried using the below syntax. Unfortunately, I get the same result.. where the "domain" hash element is ignored.

$body = @{
 "destination"="longurl.com"
 "domain[0]" = "fullName"
 "domain[1]" = "link.domain.com"
} | ConvertTo-Json
Source Link
MKANET
  • 683
  • 7
  • 32
  • 65

Converting Windows cURL syntax to an equivalent InvokeRestMethod command

I am having trouble converting a working cURL command in Windows to an equivalent PowerShell InvokeRestMethod command. It looks like I am pretty close. I am getting a response. However, the API doesn't seem to understand the nested hash table element "domain" sent by InvokeRestMethod command. All other hash elements seem to be recognized by the API just fine.

cURL command (working)

curl "https://api.rebrandly.com/v1/links" -X POST -H "apikey: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -H "Content-Type: application/json" -d "{ \"destination\": \"http://longurl.com\", \"domain\": {\"fullName\": \"link.domain.com\"}}"

PowerShell:

$body = @{
 "destination"="longurl.com"
 "domain" = @("fullName", "link.domain.com")
} | ConvertTo-Json

$header = @{
 "apikey"="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
 "Content-Type"="application/json"
}

Invoke-RestMethod -Uri "https://api.rebrandly.com/v1/links" -Method 'Post' -Body $body -Headers $header