Unable to update a testrun state to completed via API - api

We have been using curl with the VSTS / Azure API v5.1 to create testruns, post test results and set testruns with a state of 'completed' for a good while.
For the past few weeks, our requests to patch the testrun state to 'completed' from 'inProgress' are not committed.
(Yet we can use the same request to update other testrun attributes like the value for 'comment')
Documentation still mentions acceptable values to supply for state:
https://learn.microsoft.com/en-us/rest/api/azure/devops/test/runs/update?view=azure-devops-rest-5.1#updating-started-date
Are you able to complete your testruns via the API? Thanks
curl -k -H "Content-Type: application/json" -H "Authorization: Basic {token}" --request PATCH -d "{'state':'Completed','build':{'id': 0},'comment':'an updated comment'}" https://dev.azure.com/etc/etc/_apis/test/runs/{testrunID}?api-version=5.1

I can update the state to Completedsuccessfully via REST API:
PATCH https://dev.azure.com/{organizaion}/{project}/_apis/test/runs/{runid}?api-version=5.1
Request Body:
{
"state": "Completed"
}
But it only updated the test run state, if the result is not Passed, then there will be a triangular exclamation mark near the Completed state.
So, to completely update the state we have to update the test result outcome to Passed :
PATCH https://dev.azure.com/{organization}/{project}/_apis/test/runs/{runid}/Results?api-version=5.1
Request body:
[
{
"id": 100000,
"outcome": "Passed"
}
]

I test with the following script in the PowerShell task of azure devops and can successfully modify the any state of the testrun to Completed .
$connectionToken="your token"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
curl.exe -k -H "Content-Type: application/json" -H "Authorization: Basic $base64AuthInfo" --request PATCH -d "{'state':'Completed','comment':'an updated comment'}" https://dev.azure.com/{org}/{pro}/_apis/test/runs/{runId}?api-version=5.1

Thank you all for your help. I can confirm that our curl command run in CMD is now successfully setting the testrun state to 'completed'. As mentioned earlier, it was able to change other aspects of the testrun record, (eg comment) but for the last few weeks did not affect the state. Now the state is updating too. This would suggest to me the issue probably wasn't our side, as our curl api request hasn't changed. Glad to see it's resolved though.

Related

Unexpected behaviour when posting a webhook into an app. Still sending All data despite reducing the trigger fields and payload fields

I sent a webhook into open solar via post as below see the api https://developers.opensolar.com/#webhooks. The webhook is in an airtable automation. The issue is when reducing the payload and trigger fields it does not appear to make a to the data recieved in the webhook. I am still receiving data from Models "Project", "Contact" & "Event" despite having removed these from the webhooks trigger fields and payload fields.
Here are the steps I took
First I posted the below webhook into open solar for testing and verified that was the case with GET.
curl "https://api.opensolar.com/api/orgs/:org_id/webhooks/" --request POST -H "Content-Type: application/json" -H "Authorization: Bearer " -d '{"endpoint": "https://somesolar.com/api/", "headers": "{"Authorization": "Token "}", "enabled": true, "debug": false, "trigger_fields":["contact.", "event.", "project."], "payload_fields":["contact.", "event.", "project."]}'
Since there were cases where different payloads were being received by one webhook this caused me errors in the airtable automation using a webhook as a trigger because there were some instances when the payload did not have the fields I was using to update fields in a create new record action.
So I decided to setup 3 webhooks one for each payload type, "contact", "event" and "project". So I updated (and I also deleted and re uploaded the webhook) and sent a new webhook in as below.
curl "https://api.opensolar.com/api/orgs/:org_id/webhooks/" --request POST -H "Content-Type: application/json" -H "Authorization: Bearer " -d '{"endpoint": "https://somesolar.com/api/", "headers": "{"Authorization": "Token "}", "enabled": true, "debug": false, "trigger_fields":["contact."], "payload_fields":["contact."}'
However I am still receiving all 3 payloads triggered by all 3 trigger fields. Does anyone know why or any other steps to troubleshoot? thanks v much!

Hitting the GitHub api for listing PR comments returns no result

I want to list (count actually) the comments made on a GitHub pull request.
As per the documentation, I am using the following curl command to hit the GitHub API
curl -H "Accept: application/vnd.github+json" -H "Authorization: token abcdefg123457" https://api.github.com/repos/MyOrg/MyRepo/pulls/2/comments
The result is the following:
[
]
despite me seeing comments on #PR2.
What am I missing?

How do I use the REST API to update an Apex Trigger?

curl --location --request PUT 'https://ap17.salesforce.com/services/data/v48.0/sobjects/ApexTrigger/01q2x000000YiNcAAK' \
--header 'Authorization: Bearer 00D2....' \
--header 'Content-Type: application/json' \
--data-raw '{
"Name": "ContactCreateUpdateDeleteApexTrigger",
"TableEnumOrId": "Contact",
"Body":"trigger ContactCreateUpdateDeleteApexTrigger on Contact (after update,after insert, after delete) { String url = '\''https:endpoint.com'\''; String content = WebhookClass.jsonContent(Trigger.new, Trigger.old,'\''Contact'\''); WebhookClass.callout(url, content); }"
}'
I am getting 200 Response but my triggers are not updated.
Apex class, Apex trigger tables are visible just for reference purposes and backups. What you do is not a simple data manipulation operation, it has to be a proper deployment with compilation, running unit tests, min 75% code coverage... Especially that your endpoint looks like a production.
Check the Tooling API, it's also RESTful. This should be a nice start: https://salesforce.stackexchange.com/q/156221

Getting "You don't have a required scope to access the endpoint" when inserting script

I'm developing an app, for store fronts and want to get some analytics in checkout. So I want to inject a script in that scope of checkout. When I try to insert it I'm getting "You don't have a required scope to access the endpoint" but I have updated the scopes to checkoutcontent to modify. Not sure what else is wrong
Trying to insert script via an app, getting 403 even though I updated the OAuth scopes to include, Check out content and Checkout
curl --request POST \
--url https://api.bigcommerce.com/stores/{store_hash}/v3/content/scripts \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'x-auth-client: XXXXX' \
--header 'x-auth-token: XXXXX' \
--data '{"name":"Test Scripts Tag","description":"Test Scripts Tag","html":"<script src=\\\"https://Somedestination/Test.js\\\"></script>","src":"https://Somedestination/Test.js","auto_uninstall":true,"load_method":"default","location":"footer","visibility":"checkout","kind":"src"}'
Getting below error, while expecting a status=200
status: 403,You don't have a required scope to access the endpoint
The html field shouldn't be included when using src, could you try removing it?
The only errors I was receiving in testing were due to malformed HTML in the html field with the error code 422. It may also be worth trying to create a new API account to rule out scoping causing this.

Pushbullet API from cURL - invalid request

I'm working on an app using Pushbullet's API, but I'm running into odd errors when running through the sample code at https://docs.pushbullet.com/v2/pushes/.
I'm executing the following cURL command (in Windows):
curl -k -u <MY_API_KEY>: -X POST https://api.pushbullet.com/v2/pushes --header 'Content-Type: application/json' --data-binary '{"type": "note", "title": "Note Title", "body": "Note Body"}'
...but it keeps generating the following error:
{"error": {"type":"invalid_request","message":"The param 'type' has an invalid value.","param":"type","cat":"\u003e:3"}}
It also produces this error:
The other commands for the other endpoints in the documentation work fine...it's just this one.
Got any suggestions? Thanks for the help! :)
It looks like windows doesn't support those kinds of quotes on the command line. Here's an example that works:
curl https://api.pushbullet.com/v2/pushes -X POST -u <access token>: --header "Content-Type: application/json" --data-binary "{\"type\": \"note\", \"title\":\"Note Title\", \"body\": \"Note Body\"}"
I think I'm going to try to replace the curl examples with something that has less confusing behavior.
I figured it out - I don't really know why, but the cURL command wasn't working through the DOS prompt, and also wasn't working using the Postman REST client for Chrome, but I got it working in the DHC extension for Chrome. The trick was setting the Authorization header to "Basic", which resolves the Pushbullet access token to some other form, and makes a successful the HTTP request.
Hope this helps someone down the road if they run into this on Windows!