Azure DevOps problem to create project via REST call containing german umlauts - rest

I have an admin script that creates Azure DevOps projects via calls to the REST API. This works fine as long as the name or description arguments contain no special characters. If for example german umlauts are in the description, the call fails.
This works:
curl -k -D- -X POST -d '{"name":"Phantom","capabilities":{"processTemplate":{"templateTypeId":"6b724908-ef14-45cf-84f8-768b5384da45"},"versioncontrol":{"sourceControlType":"Git"}},"visibility":"private","description":"Innocent description without umlauts"}' -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'Authorization: Basic secretauthorizationtoken=' https://dev.azure.com/AdminPlayground/_apis/projects?api-version=6.0-preview.4
this one throws an exception:
curl -k -D- -X POST -d '{"name":"Phantom","capabilities":{"processTemplate":{"templateTypeId":"6b724908-ef14-45cf-84f8-768b5384da45"},"versioncontrol":{"sourceControlType":"Git"}},"visibility":"private","description":"Funny description with strange äöüß chars"}' -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'Authorization: Basic secretauthorizationtoken=' https://dev.azure.com/AdminPlayground/_apis/projects?api-version=6.0-preview.4
The exception is:
{"$id":"1","innerException":null,"message":"Value cannot be null.\r\nParameter name: projectToCreate","typeName":"System.ArgumentNullException, mscorlib","typeKey":"ArgumentNullException","errorCode":0,"eventId":0}
Has anybody experienced similar behavior, and could perhaps suggest a solution?
Thanks!

This problem is due to the data format problem caused by the special characters in description.
Kindly check if it can be solved by adding the correct encoding format into the -ContentType,
For example -ContentType 'application/json;charset=utf -8'

Related

ADO Linking requirement & test case work items with Rest API issue

I'm trying to link a ADO Requirement work item to a ADO Test Case work item. I'm making this call:
curl -u :********** -X PATCH -H "Content-Type: application/json-patch+json" -H "Accept: application/json-patch+json" -d "[{{\"op\": \"test\", \"path\": \"/rev\",\"value\": 3 },{\"op\": \"add\", \"path\": \"/relations/-\", \"value\":\"{\"rel\": \"System.LinkTypes.Dependency-forward\",\"url\": \"https://***.***.com/{Organisation}/_apis/wit/workItems/{ID}\",\"attributes\": {\"comment\": \"Making a new link for the dependency\"}}}}]" https://***.***.com/{Organisation}/{Project}/_apis/wit/workItems/{ID}?api-version=6.0
as per: https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/work-items/update?view=azure-devops-rest-7.1#add-a-link
But I'm having this error:
{"$id":"1","innerException":null,"message":"You must pass a valid patch document in the body of the request.","typeName":"Microsoft.VisualStudio.Services.Common.VssPropertyValidationException, Microsoft.VisualStudio.Services.Common","typeKey":"VssPropertyValidationException","errorCode":0,"eventId":3000}
I found my answer, the JSON was badly parse. I used a online JSON linter to fix it. https://jsonlint.com/
curl -u :********** -X PATCH -H "Content-Type: application/json-patch+json" -H "Accept: application/json-patch+json" -d "[{\"op\": \"add\", \"path\": \"/relations/-\", \"value\":{\"rel\": \"Microsoft.VSTS.Common.TestedBy-Forward\",\"url\": \"https://***.***.com/{Organisation}/_apis/wit/workItems/{ID}\",\"attributes\": {\"comment\": \"Making a new link for the dependency\"}}}]" https://***.***.com/{Organisation}/{Project}/_apis/wit/workItems/{ID}?api-version=6.0

What permissions is my github PAT missing?

I'm triggering a github action using a webhook. Until recently this worked perfectly but I got a request from Github to refresh my PAT to the new format and now I get a permission denied error. Am I missing a permission or has the authorization syntax changed?
This is the webhook I'm calling:
curl -d '{"ref":"v2.0","inputs":{"oga_no":"1369"}}' -H 'Accept: application/vnd.github.v3+json' -H 'Authorization: Basic ghp_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' -H 'Content-Type: application/json;charset=utf-8' -X POST 'https://api.github.com/repos/ogauk/boatregister/actions/workflows/publish.yml/dispatches'
And this is the response:
{
"message": "Must have admin rights to Repository.",
"documentation_url": "https://docs.github.com/rest/reference/actions#create-a-workflow-dispatch-event"
}
Something must have changed with the new token format. I spotted a post with a slightly different syntax and tried it.
curl -d '{"ref":"v2.0","inputs":{"oga_no":"1369"}}' -H 'Accept: application/vnd.github.v3+json' -H 'Authorization: token ghp_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' -H 'Content-Type: application/json;charset=utf-8' -X POST 'https://api.github.com/repos/ogauk/boatregister/actions/workflows/publish.yml/dispatches'
So changing Basic to token fixed my problem.

translate Postman post Request with Basic Auth to mingw64 curl and powershell On Windows 10

I would like to translate a POST Request test from Postman to curl on Windows!
note: ip, username, password are illustrative for this question!
Consuming from Postman, I get 200 OK Code fine!
But, Trying to use curl from cmd is not working!
Checking on Postman the curl code
I was trying on Powershell
curl --location --request POST 'http://10.31.7.52/BdN_SMS_CXP/api/SendSMS' --header 'Authorization: Basic bWFyaWVsYTpZMFMkaSRfViZTLjQwNio=' --header 'Content-Type: application/json' --data-raw '{"ANI" : 3007209820}'
curl --location --request POST 'http://10.31.7.52/BdN_SMS_CXP/api/SendSMS' --header 'Authorization: Basic bWFyaWVsYTpZMFMkaSRfViZTLjQwNio=' --header 'Content-Type: application/json' --data-raw '{\"ANI\" : 3007209820}'
checking codification/decodification is fine.
Now directly with user and password, according to https://stackoverflow.com/a/27442239/811293
curl --location --request POST 'http://10.31.7.52/BdN_SMS_CXP/api/SendSMS' --user 'mariela:Y0S$i$_V&S.406*' --header 'Content-Type: application/json' --data-raw '{"ANI" : 3007209820}'
Here my results.
When I use curl of mingw64 7.71.1 version, the command is misinterpreted, because I get a 407 error, Authentication required. It's not just a powershell problem solved with Remove-item alias:curl.
I suspect you should escape some characters, and use double commas " instead of single commas '.
What considerations should I have with $, _, &, . and * characters (if I should have it with any)?
How should I write the request in powershell (or mingw64 curl) for it to work?
The generated command is not powershell curl but cmd curl :
you can just use it in cmd as it is,
or if you want to use powershel use it as:
$command= "curl --location --request POST 'http://10.31.7.52/BdN_SMS_CXP/api/SendSMS' --header 'Authorization: Basic bWFyaWVsYTpZMFMkaSRfViZTLjQwNio=' --header 'Content-Type: application/json' --data-raw '{""ANI"" : 3007209820}'"
cmd /c $command

Request to VSTS REST API only works on Postman

I'm trying to run this request
curl -X POST \
'https://*****.visualstudio.com/DefaultCollection/_apis/wit/wiql?=&api-version=1.0' \
-H 'authorization: Basic *****' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'postman-token: *****' \
-d '{
"query": "SELECT [System.Id] FROM WorkItems"
}'
but I keep getting this error
{"count":1,"value":{"Message":"A value is required but was not present in the request.\r\n"}}
It works as expected on Postman, so I think the request and the server are OK.
I'm trying to follow the first example shown here: https://www.visualstudio.com/en-us/docs/integrate/api/wit/wiql
Am I missing something?
The URL is wrong, remove =& from the REST API url and the url will be like this:
https://*****.visualstudio.com/DefaultCollection/_apis/wit/wiql?api-version=1.

IBM Watson text-to-speech curl example not working

Here is the command I am using to test the text-to-speech API:
/usr/bin/curl -k -u 'USERNAME':'PASSWORD' -X POST \
--header 'Content-Type: application/json' \
--header 'Accept: audio/wav' \
--data '{"text":"hellow world","voice":"en-US_AllisonVoice"}' \
'https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize' > ./public/138106.wav
The command above doesn't seem to generate the desired audio file. I have a bluemix account and the right credentials. An audio file is generated, but it's corrupt.
voice is a URL parameter. The correct curl command looks like this:
/usr/bin/curl -k -u 'USERNAME':'PASSWORD' -X POST \
--header 'Content-Type: application/json' \
--header 'Accept: audio/wav' \
--data '{"text":"hellow world"}' \
'https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?voice=en-US_AllisonVoice'
Disclosure: I am an evangelist for IBM Watson.
--data '{"text":"hellow world","voice":"en-US_AllisonVoice"}'
Try this:
--data "{\"text\":\"hello world\", \"voice\":\"en-US_AllisonVoice\"}"
I took this syntax from the API documentation found here: https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/text-to-speech/quick-curl.shtml
It seems they have built the syntax of the JSON differently than your command.
I solved it not using the cURL scripting recommendation.
But by going directly to the url: https://stream.watsonplatform.net/speech-to-text/api/v1/recognize
Then removing the following 2 lines:
"word_alternatives_threshold": null,
"keywords_threshold": null,
There are issues with these lines.