1

I have an existing package registry in GitLab called my_package_registry_2.0.4.0. Now using a curl command i am trying to created a new Release and at the same time adding that package registry as an asset. My tag 1.0.0.0 also exists and it is already created in my repo.

Below is the curl command (with no milestone dates, i am not interested in it):

curl --header 'Content-Type: application/json' --header "PRIVATE-TOKEN: myTokenHere" --data '{ "name": "2.0.0.0", "tag_name": "1.0.0.0", "description": "Release manually created from API", "assets": { "links": [{ "name": "Release_1.2.0.0", "url": "https://my.gitlab.space/api/v4/projects/197/packages/generic/my_package_registry_2.0.4.0/1.0.0.0/myZipFile.zip", "link_type":"package" }] } }' --request POST "https://my.gitlab.space/api/v4/projects/197/releases"

When I execute it, it is failing. Below the error:

curl: (6) Could not resolve host: application
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) unmatched brace in URL position 1:
{
 ^

What am i doing wrong?

ATTEMPT #2: If I use double quotes instead of single quotes, i mean, replace:

'Content-Type : application/json'

by

"Content-Type : application/json"

Then I get below error:

curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) unmatched brace in URL position 1:
{
 ^
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
Willy
  • 9,848
  • 22
  • 141
  • 284
  • If I run `curl --header 'Content-Type: application/json' --header "PRIVATE-TOKEN: myTokenHere" --data '{ "name": "2.0.0.0", "tag_name": "1.0.0.0", "description": "Release manually created from API", "assets": { "links": [{ "name": "Release_1.2.0.0", "url": "https://my.gitlab.space/api/v4/projects/197/packages/generic/my_package_registry_2.0.4.0/1.0.0.0/myZipFile.zip", "link_type":"package" }] } }' --request POST "https://my.gitlab.space/api/v4/projects/197/releases"` I have ssl errors, but not an issue with curly brackets. Which OS do you use? – Gilles Quénot May 04 '23 at 20:27
  • @GillesQuénot i am using Windows 11 64-bit and running the curl command on a cmd with elevated privileges (administrator) – Willy May 04 '23 at 20:32
  • Do you run the code in PowerShell or cmd.exe? – Gilles Quénot May 04 '23 at 20:33
  • @GillesQuénot from cmd.exe – Willy May 04 '23 at 20:33
  • Do it in PowerShell, it will be good. Quoting style in cmd.exe is awkward. – Gilles Quénot May 04 '23 at 20:34
  • 1
    @GillesQuénot running the curl command in powershell says below error: Invoke-WebRequest : A positional parameter cannot be found that accepts argument 'Content-Type: application/json'. At line:1 char:1 + curl --header 'Content-Type: application/json' --header "PRIVATE-TOKE ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand – Willy May 04 '23 at 20:36
  • You need to run `Remove-item alias:curl ` – Gilles Quénot May 04 '23 at 20:42
  • 1
    No you don't @GillesQuénot. You need to use `curl.exe` not `curl`. – Compo May 05 '23 at 00:47

2 Answers2

3

Finally I resolved it, executing it from cmd.exe needs to put all things within double quotes and escape double quotes within other double quotes, like this:

curl --header "Content-Type: application/json" --header "PRIVATE-TOKEN: myTokenHere" --data "{ \"name\": \"2.0.0.0\", \"tag_name\": \"1.0.0.0\", \"description\": \"Release manually created from API\", \"assets\": { \"links\": [{ \"name\": \"Release_1.2.0.0\", \"url\": \"https://my.gitlab.space/api/v4/projects/197/packages/generic/my_package_registry_2.0.4.0/1.0.0.0/myZipFile.zip\", \"link_type\":\"package\" }] } }" --request POST "https://my.gitlab.space/api/v4/projects/197/releases"
Willy
  • 9,848
  • 22
  • 141
  • 284
0

It seems like you are using cmd.exe. The quoting style is not the same as Unix* tools. For this, you need to run the same command in PowerShell.

You can shorten the command and split it like this:

curl.exe --header 'Content-Type: application/json' \
     --header "PRIVATE-TOKEN: myTokenHere" \
     --data '{ "name": "2.0.0.0", "tag_name": "1.0.0.0", "description": "Release manually created from API", "assets": { "links": [{ "name": "Release_1.2.0.0", "url": "https://my.gitlab.space/api/v4/projects/197/packages/generic/my_package_registry_2.0.4.0/1.0.0.0/myZipFile.zip", "link_type":"package" }] } }' \
    "https://my.gitlab.space/api/v4/projects/197/releases"

--data implies already a POST request.

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223