windows command prompt curl POST to run Azure DevOps pipeline - azure

I am trying to run an Azure DevOps pipeline from the windows command prompt using curl.
Based on Microsoft documentation ( Runs - Run Pipeline ) I should be able to run a pipeline by posting:
https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1
I am able to GET using the command:
curl -u :<PAT> https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1
However, I can't figure out how to do a POST for DevOps using curl to run the pipeline.
I have tried the following:
curl -s -X POST -L https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1 -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Basic <PAT>"
But this returns the error
HTTP Error 411. The request must be chunked or have a content length

I managed to solve my problem which consisted of numerous steps:
Log the API call from the DevOps website to get the correct format of the json-body ( See this question ).
Format the json-body with extra double quotation signs.
Use the {project}-id instead of the ascii-name since it included a special character which the command prompt misinterpret.
Hence the complete curl command was:
curl -X POST -u :<PAT> "https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1" -H "Content-Type: application/json" -d "{""stagesToSkip"": ""[]"", ""resources"": {""repositories"": {""self"": {""refName"": ""refs/heads/master""}}}}"

Related

Run query API in curl

I'm trying to explore the curl connect or retrieve the data with query API link but when I run my GET command in curl it runs without any error shown in -vv but the process stop. below the actual statement at the end of the posted process, may I know if this is normal or I need to add an additional arguments or parameters on my command for me to retrieve the data? If yes may I know how to do it?
Connection #1 to host myserver.com left intact
My command
curl -vv -k -X GET -H --user user123:password1 -H "Accept: application/json" https://myapplink/statement/EXE=sample

azure -command not found while running GET command

curl -X GET -H "Authorization: Bearer<token>" -H "Content-Type: application/json" https://management.azure.com/subscriptions/xxxx-xxx-xxxxxx-xxxxxxxxx/providers/microsoft.insights/eventtypes/management/values?api-version=2015-04-01&$filter=eventTimestamp ge '2019-03-21T00:00:00Z' and eventTimestamp le '2019-03-24T20:40:00Z' and resourceGroupName eq 'name'&$select=operationName,status,level
This command is used for collection azure activity log I am running this command in the CLI its giving error
bash: =,status,level: command not found...
bash: =eventTimestamp: command not found...
Hi I found the solution myself
the POST request that you are using copy and paste to Postman(software). Then click on "code". https://management.azure.com/subscriptions/xxxx-xxxxx-xxxxx-xxx/providers/microsoft.insights/eventtypes/management/values?api-version=2015-04-01&$filter=eventTimestamp%20ge%20%272019-03-21T00:00:00Z%27%20and%20eventTimestamp%20le%20%272019-03-24T20:40:00Z%27%20and%20resourceGroupName%20eq%20%27Ajay%27&$select=operationName,status,level'

Want to call batch file with node script, get garbled time

I want to create a cron job with a batch file which is using curl to login into a page saving the login token and then run a node script to do something. But when I call my batch file I get
batch: garbled time
My script:
#!/bin/bash
# A simple script to automate something
curl 'someurl' -H 'content-type: application/json' -H 'Accept: */*' -H 'Cache-Control: no-cache' -H 'Referer: someurl' --data-binary '{"some login data"}' -i -O
node doSomething.js
If you are trying to submit your script as a crontab file, then it's in the wrong format. You need to specify time-related fields at the start of the line. See https://en.wikipedia.org/wiki/Cron
The error message you got is typical of a bad time specification.

curl command in linux

How we can add JSON parameters in a curl command to fetch data ?
PS: I have tried to fetch data from some source using curl command but it requires passing JSON parameters in it. So how I will accomplish it ?
I think mentioning content type as json and passing data will do the things right
curl -H "Content-Type: application/json" -d '{"key1":"value1","key2":"value2"}' http://domain.com/rest/path/here
Above will work for GET Method, for POST method
curl -H "Content-Type: application/json" -X POST -d '{"key1":"value1","key2":"value2"}' http://domain.com/rest/path/here

Acquiring and changing basic data on the Nest thermostat

I've been having trouble acquiring and changing some of the basic data available from the Nest thermostat.
Using a command line, how can I get or change individual settings or values on my thermostat?
This is a compilation from several users explaining how to retrieve or change some basic information with some of my own experiences added in. Wherever I use <VALUE>, replace that with the applicable information in your setup. If you're using Windows, you'll need something like git-scm.
The following a part of the authentication process. You'll need to have a client already made on Nest's developer page and followed the provided authorization URL to get your auth code. Run this line to get an access token:
curl --data 'code=<AUTH CODE>&client_id=<CLIENT ID>&client_secret=<CLIENT SECRET>&grant_type=authorization_code' https://api.home.nest.com/oauth2/access_token
To fetch some information about the thermostats associated with the authorization code:
curl -v -L https://developer-api.nest.com/devices/thermostats?auth=<AUTH CODE>
To fetch some information about a specific thermostat:
curl -v -L https://developer-api.nest.com/devices/thermostats/<THERMOSTAT ID>?auth=<AUTH CODE>
To fetch the target temperature in F from the specified thermostat. You can replace target_temperature_f with any other value listed under thermostat on Nest's API reference:
curl -v -L https://developer-api.nest.com/devices/thermostats/<THERMOSTAT ID>/target_temperature_f?auth=<AUTH CODE>
To change the target_temperature_f:
curl -v -L -X PUT "https://developer-api.nest.com/devices/thermostats/<THERMOSTAT ID>/target_temperature_f?auth=<AUTH CODE>" -H "Content-Type: application/json" -d "65"
To change the specific structure to away. The value here is a string so be sure to include the single quotes:
curl -v -L -X PUT "https://developer-api.nest.com/structures/<STRUCTURE ID>/away?auth=<AUTH_TOKEN>" -H "Content-Type: application/json" -d '"away"'
Credit for this is primarily to the following users:
thesimm, mccv, Nagesh Susarla, and David W. Keith.

Resources