I am trying to make a POST request to Azure DevOps API using curl code within a terraform script.
resource "null_resource" "AzDo_API_request" {
provisioner "local-exec" {
command = <<EOT
curl -L -X POST "https://dev.azure.com/altabhussain0027/_apis/hooks/subscriptions?api-version=7.1-preview.1"
-H "Authorization: Basic OnBobHdxcm1sb2Fvb3ZwZDZmbHZobjdiMnNoYXJ2aTRqdWNsYjJqNnpyemQ3dG9jYWh0eGE="
-H "Content-Type: application/json"
--data-raw "{
\"consumerActionId\": \"httpRequest\",
\"consumerId\": \"webHooks\",
\"consumerInputs\": {
\"url\": \"https://pulse-xxx.com/webhook/c29ac65b-xxxx-xxxx-xxxx-f4dc16d3114e\"
},
\"eventType\": \"workitem.updated\",
\"publisherId\": \"tfs\",
\"publisherInputs\": {
\"areaPath\": \"any\",
\"workItemType\": \"Feature\",
\"projectId\": \"b0eb9e33-xxxx-xxx-xxxx-68866d0dd821\"
},
\"resourceVersion\": \"1.0\",
\"scope\": \"all\"
}"
EOT
}
}
The above curl code is generated from Postman wherein the POST request are successfull without giving error.
However, when executing the same using terraform, I am getting the below error:
null_resource.AzDo_API_request (local-exec): curl: (3) URL using bad/illegal format or missing URL
│ Error: local-exec provisioner error
│
│ with null_resource.AzDo_API_request,
│ on servicehook.tf line 2, in resource "null_resource" "AzDo_API_request":
I am running the above in Windows 11 machine, it might have to do with the double quotes. Any help is appreciated.
Related
I am trying around with the Rundeck API. I was able to get a simple Job running. But now I am trying to run a job, that has a job option. The job option for this job is an IP, so Rundeck starts the Job only on this machine.
When I use the API, I don't know how to set the parameter. I am using the tool Postman, where I only receive the message "Job options were not valid: Option 'IP' is required".
I looked it up on the rundeck documentation and I found this for postman
In the rundeck documentation is this example:
argString: argument string to pass to the job, of the form: -opt value -opt2 value ....
How can I use it for my IP?
Using this Rundeck Job Definition:
- defaultTab: nodes
description: ''
executionEnabled: true
id: 9f04657a-eaab-4e79-a5f3-00d3053f6cb0
loglevel: INFO
name: HelloWorld
nodeFilterEditable: false
options:
- name: opt1
plugins:
ExecutionLifecycle: null
scheduleEnabled: true
sequence:
commands:
- exec: echo "hello ${option.opt1}"
keepgoing: false
strategy: node-first
uuid: 9f04657a-eaab-4e79-a5f3-00d3053f6cb0
And based on this, you can do it by putting the options in JSON format (json body) on Postman:
{
"options": {
"opt1":"world"
}
}
This is the code snipped in cURL format:
curl --location --request POST 'pop-os:4440/api/38/job/9f04657a-eaab-4e79-a5f3-00d3053f6cb0/run' \
--header 'X-Rundeck-Auth-Token: GuaoD6PtH5BhobhE3bAPo4mGyfByjNya' \
--header 'Content-Type: application/json' \
--header 'Cookie: JSESSIONID=node01tz8yvp4gjkly8kpj18h8u5x42.node0' \
--data-raw '{
"options": {
"opt1":"world"
}
}'
Check how looks on Postman.
I've been trying to run a pipeline for a particular branch of the repository I'm using.
In the UI, there is a convenient option, but I don't understand what to try in the request.
No matter what I do I always run from master.
How do I change that? I tried filling out the repository parameters but to no avail: https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run%20pipeline?view=azure-devops-rest-6.0#repositoryresourceparameters
Here is an example request:
curl --location --request POST 'https://dev.azure.com/<redacted>/<redacted>/_apis/pipelines/<redacted>/runs?api-version=6.0-preview.1' \
--header 'Authorization: Basic <redacted>' \
--header 'Content-Type: application/json' \
--header 'Cookie: VstsSession=<redacted>' \
--data-raw '{
"previewRun": true,
"resources": {
"repositories": {
"refName": "refs/heads/<redacted>"
}
},
"runParameters":
{
"namespace" : "<redacted>",
"image" : "<redacted>",
"tag" : "<redacted>",
"package" : "<redacted>",
"version" : "8.4.4"
}
}'
From your screenshot, it seems that you are using the YAML pipeline.
I have tested your example , and the root cause of this issue is that the request body(data-raw) has some issues.
You could try my sample
curl --location --request POST 'https://dev.azure.com/<redacted>/<redacted>/_apis/pipelines/<redacted>/runs?api-version=6.0-preview.1' \
--header 'Authorization: Basic <redacted>' \
--header 'Content-Type: application/json' \
--header 'Cookie: VstsSession=<redacted>' \
--data-raw '{
"stagesToSkip":[],
"resources":
{
"repositories":
{
"self":{"refName":"refs/heads/{Branchname}"}
}
},
"templateParameters":
{
"namespace":"{value}",
"image":"{value}",
"tag":"{value}",
"package":"{value}",
"version":"{value}"
},
"variables":{}
}'
Result:
For Http Request (you can test it with Postman)
1. Get pipeline api url like this
https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=7.1-preview.1
Source: https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run-pipeline?view=azure-devops-rest-7.1
Fill in your organization, project and pipelineId.
(all of this can be found in the link when you open your pipeline definition in Azure DevOps)
2. Add Basic Auth headers
key: Authorization, value:"Basic [your azure Person Access Token from Azure Dev Ops with Access to Pipeline goes here]"
Should look like this
"Basic OndzNWdz43FKfjdi98hjKDJFH8kkg9854HJKHF9D8RFEHui4387lkNXE="
And set content type to application/json
like this
key: Content-Type, value: application/json
3. Put this JSON Into Raw Body
{
"templateParameters":{
"inputName":"johnsmith"
},
"resources":{
"repositories":{
"self":{
"refName":"refs/heads/feature/#JIRATask01_Blabla"
}
}
},
"variables":{
}
}
Replace refName value with branch you want to run the pipeline for.
If you have multiple repo pipeline look into this topic (but i haven't tested that solution):
Azure DevOps API to Trigger Multi Repo changing branches
probably a basic question, but I'm new to this:
I am trying to link to the Fidel test API environment. They give examples (https://reference.fidel.uk/reference#get-transaction) of how to do this via cURL. In this case the example is:
curl -X GET \
https://api.fidel.uk/v1/transactions/84782884-6ab8-4885-820f-4cd081dd658f \
-H 'Content-Type: application/json' \
-H 'Fidel-Key: sk_test_50ea90b6-2a3b-4a56-814d-1bc592ba4d63'
If I run this in my terminal it works perfectly. But I can't get anything back if I try to run the same in my browser, or if I try to run it via the http.dart package in Flutter, which is where I need it to run eventually.
In Flutter I am writing it as:
void getData() async {
Response response = await get(
"https://api.fidel.uk/v1/transactions/84782884-6ab8-4885-820f-4cd081dd658f \'Content-Type: application/json' \'Fidel-Key: sk_test_50ea90b6-2a3b-4a56-814d-1bc592ba4d63'");
print(response.body);
}
I am sure it's a syntax thing that I don't understand. Any help would be appreciated.
It was just syntax! I solved by saying
Response response = await get(
'https://api.fidel.uk/v1/transactions/84782884-6ab8-4885-820f-4cd081dd658f',
headers: {
'Content-Type': 'application/json',
'Fidel-Key': 'sk_test_50ea90b6-2a3b-4a56-814d-1bc592ba4d63',
});
Will leave here in case anyone else, like me, gets stuck on the basics.
Trying to pull financial reports from apple connect api and getting a 403 for CREATE operation, this is not documented :/. anyone know how I use a GET_COLLECTIONS operations here with cURL?
exec("curl -v -X POST -H 'Authorization: Bearer {$token}' \"https://api.appstoreconnect.apple.com/v1/financeReports\" -d 'regionCode=Americas&reportDate=2020-01&reportType=FINANCIAL&vendorNumber=xxx&' -o output");
Response:
{
"errors" : [ {
"id" : "bb9e260c-c3d4-4df9-b78e-f34dfd42c449",
"status" : "403",
"code" : "FORBIDDEN_ERROR",
"title" : "The given operation is not allowed",
"detail" : "The resource 'financeReports' does not allow 'CREATE'. Allowed operations are: GET_COLLECTION"
} ]
}
response
You need to use GET, Not POST
exec("curl -v X GET -H 'Authorization: Bearer {$token}' \"https://api.appstoreconnect.apple.com/v1/financeReports?regionCode=Americas&reportDate=2020-01&reportType=FINANCIAL&vendorNumber=xxx\" -o output");
should do the trick!
I encounter an issue when I try to use the Paypal sandbox API.
I've created my 2 sandbox accounts (the facilitator and the buyer), and I've created my app to get the credentials.
Then, I use the curl example provided by Paypal to get a token :
curl -v https://api.sandbox.paypal.com/v1/oauth2/token \
-H "Accept: application/json" \
-H "Accept-Language: en_US" \
-u "my-client-id:my-secret" \
-d "grant_type=client_credentials"
I get a 200 response, with an "access_token".
Then, I use this access token to get another resource, for example :
curl -v -X GET https://api.sandbox.paypal.com/v1/invoicing/invoices?page=3&page_size=4&total_count_required=true \
-H "Content-Type: application/json" \
-H "Authorization: Bearer the-token-received-above"
Then, I get a 401 error :
{
"name":"AUTHENTICATION_FAILURE",
"message":"Authentication failed due to invalid authentication credentials or a missing Authorization header.",
"links":[{
"href":"https://developer.paypal.com/docs/api/overview/#error",
"rel":"information_link"
}]
}
I don't understand what I'm doing wrong, since I've followed every step decribed in the Paypal doc (at least, I think I have... probably not)
Thanks for your help
curl -v -X GET "https://api.sandbox.paypal.com/v1/invoicing/invoices?page=3&page_size=4&total_count_required=true" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer the-token-received-above"
Actually had this exact same issue but didn't know what was wrong with my curl. For me, the issue was I forgot to put "Bearer" in the Authorization section.
For this, you are required to wrap the URL with quotation marks.
After get access_token. Please try this
try {
$params = array('access_token' => $jsonResponse->access_token);
$userInfo = OpenIdUserinfo::getUserinfo($params, $this->_api_context);
} catch (Exception $ex) {
ResultPrinter::printError("User Information", "User Info", null, $params, $ex);
exit(1);
}
ResultPrinter::printResult("User Information", "User Info", $userInfo->getUserId(), $params, $userInfo);
Don't forget to add
use PayPal\Api\OpenIdTokeninfo;
use PayPal\Api\OpenIdUserinfo;
That's worked for me.