0

I need to notify Sentry about new build version when CI made it. I am using runs-on: windows-latest for builds and sending requests with a code below:

- name: Notify Sentry
run: |
  $VERSION_NAME = "${{  github.ref_name }}"
  $REQUEST = "{`"version`": `"$VERSION_NAME`"}"
  echo $REQUEST
  curl -X POST -H "Content-Type:application/json" -d "$REQUEST" "https://sentry.io/api/hooks/release/builtin/...id.../...token.../"

Request looks correct, but it always returns error Expecting property name enclosed in double quotes:

Run $VERSION_NAME = "${{  github.ref_name }}"
  $VERSION_NAME = "${{  github.ref_name }}"
  $REQUEST = "{`"version`": `"$VERSION_NAME`"}"
  echo $REQUEST
  curl -X POST -H "Content-Type:application/json" -d "$REQUEST" "https://sentry.io/api/hooks/release/builtin/...id.../...token.../"
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
  
{"version": "v1.1.1"}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   104  100    87  100    17    313     61 --:--:-- --:--:-- --:--:--   375
100   104  100    87  100    17    313     61 --:--:-- --:--:-- --:--:--   375
{"error":"Expecting property name enclosed in double quotes: line 1 column 2 (char 1)"}

In Postman it works well. How to fix this error?

BArtWell
  • 4,176
  • 10
  • 63
  • 106
  • 1
    Try: `$REQUEST = "{\"version\": \"$VERSION_NAME\"}"` See: https://stackoverflow.com/questions/60819537/expecting-property-name-enclosed-in-double-quotes-when-passing-json-string-to-az – Azeem Apr 13 '23 at 10:15

1 Answers1

1

Use backslash instead of backtick to escape nested double quotes.

Change this:

$REQUEST = "{`"version`": `"$VERSION_NAME`"}"

to:

$REQUEST = "{\"version\": \"$VERSION_NAME\"}"

You may use single quotes instead of nested double ones and then use Replace function to bulk escape those like this:

$REQUEST = "{'version': '$VERSION_NAME'}".Replace("'",'\"')

See: Expecting property name enclosed in double quotes when passing JSON string to Azure CLI (from PowerShell)

Azeem
  • 11,148
  • 4
  • 27
  • 40