Problem passing JSON to Gitea API

Probably a very simple problem that belies that I’m not that familiar with Unix commands. Trying to create a repository using the Gitea API. I’ve got it working to check if a repository exists but this is the curl I’m trying to execute to create a test repository:

curl.exe -k -H “content-type: application/json” -H “Authorization: token xxx” https://gitea.mydomain.co.uk:3000/api/v1/user/repos -d ‘{“name”: “test1”}’

And I get this result:

{“message”:“: invalid character ‘n’ looking for beginning of value”,“url”:“https://gitea.mydomain.co.uk:3000/api/swagger”}

It’s clearly a problem with the JSON I’m trying to pass, i.e. if I change “name” to “xame”, the invalid character is ‘x’.

Later… since posting the above in another topic (bad form), I’ve got it working using PowerShell Invoke-WebRequest. I’m executing curl from a PowerShell script anyway so this is perfectly fine and slightly cleaner.

Still intrigued what I’m doing wrong though with the curl command.

Answering my own question as I found a similar thread on StackOverlow. It’s something to do with the PowerShell parser. You have to quote the JSON like this:

-d '{\"name\": \"test1\"}'

It’s also important to use single quotes around the entire string and not double-quotes. I’m sure another hour of research would reveal the parser quirk that’s causing this.

1 Like