Convert HTTP request to Powershell and cURL

Viewed 25

I'm trying to convert a HTTP request (which I've never dealt with before) into a cURL and Powershell command, but I'm not getting anywhere....can someone help me fill in the blanks?

POST /api/users.profile.set
Host: slack.com
Content-type: application/json; charset=utf-8
Authorization: bearer_token
{
    "profile": {
        "status_text": "Eating some french fries from the frituur",
        "status_emoji": ":fries:"
    }
}
curl 'https://slack.com/api/users.profile.set' `
--header 'Authorization: bearer_token' `
--header 'Content-Type: application/json' `
--data-raw "{
   \"profile\": {
        \"status_text\": \"On Lunch\",
        \"status_emoji\": \":hamburger:\"
    }
}"

and

Invoke-WebRequest -Headers @{"Authorization" = "bearer_token"} `
                  -Method POST `
                  -Uri https://slack.com/api/users.profile.set `
                  -ContentType application/json


1 Answers

Fixed it myself.

curl -X POST 'https://slack.com/api/users.profile.set' `
-H 'Authorization: Bearer xoxp-xxxxxxxxxxxxxxxxx' `
-H 'Content-Type: application/json; charset=utf-8' `
-d '{
   \"profile\": {
        \"status_text\": \"Sick\",
        \"status_emoji\": \":sickpepe:\",
        \"status_expiration\": \"480\"
    }
}'
$body = @{
    profile = @{
        status_text  = "Eating some french fries from the frituur"
        status_emoji = ":fries:"
        status_expiration = 60
    }
}

Invoke-WebRequest -Headers @{"Authorization" = "Bearer xoxp-xxxxxxxxxxxxxxxxxxxx"} `
                  -Method POST `
                  -Uri https://slack.com/api/users.profile.set `
                  -ContentType 'application/json; charset=utf-8' `
                  -Body ($body|ConvertTo-Json) 
    ```
Related