Using DBT Cloud API, I want to extract the run artifacts and here is what my get request looks like. The response is 200 (success), but how do I download the artifacts.
res = requests.get(
url=f"https://cloud.getdbt.com/api/v2/accounts/{ACCOUNT_ID}/runs/{JOB_RUN_ID}/artifacts/run_results.json",
headers={'Authorization': f"Token {API_KEY}", 'Content-Type': 'application/json'},
)
print('result:', res)
Your problem is you're not extracting the result from the response. You have to call the following line:
data: dict = res.json()
Then you can operate on the response data.
Related
I know there are many similar kinds of questions available but none of them worked.
Can someone tell me if there is any kind of syntax error for the Testcase below
Create Token
Create Session testsession ${baseUrl} verify=true
${body}= create dictionary clientId=unittest.cc.client clientSecret=RyDQ$xxxxxRtv
${header}= create dictionary Content-Type=application/json
${resp}= POST On Session testsession ${reqUri} json=${body} headers=${header} params=${ApiKeyParameter}
${source data}= Evaluate json.loads("""${resp.content}""") json
${token}= Set Variable ${source data['accessToken']}
#No errors Uptill this much - Bearer token creation was successful after that getting error while using it
${header}= create dictionary Authorization=${tpre} ${token} Content-Type=application/json cookies=ss-id=KF84fFy4txxxxxxxxx76i; ss-pid=StDTDxxxxxxxxxxxxn7r
${body}= get file API/data.txt
log to console ${header}
${resp}= post on session testsession /orders json=${body} headers=${header}
log to console ${resp.status_code}
The problem is every time I run the test I am getting a 400 error. Below is the Python code provided by POSTMAN and the screenshots of the headers used. Now I am not sure of how to get the HOST header in my python or maybe robot framework.
Please let me know if any additional details are needed. I am not sure of headers in the URL formation while get or post request is done
Is there any way to find that out?
import requests
import JSON
url = "https://domain:10001/orders?format=json"
payload = json.dumps({ Can ignore this part
})
headers = {
'Authorization': 'Bearer xxx',
'Content-Type': 'application/json',
'Cookie': 'ss-id=xxx; ss-pid=xxx'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
If you all ever come across this kind of issue don't forget to check the body of the JSON / XML you are sending.
Mine resolved as I was saving the dump JSON in a text file so while reading from the file my code was adding some extra spaces in front so I was getting a 400 error.
For further information try logging the Response Content it must show you the error message.
I try to get all results of a TestCase via API. In the UI I see a list of all results of a TC via the following url:
https://dev.azure.com/xxx/yyyy/_testPlans/_results?testCaseId=48587
How can I do this via API?
How can I do this via API?
I am afraid that you couldn't find this API in Official document.
But you could get the API in Browser console:
Here are the API and Request Body:
API URL:
POST https://dev.azure.com/{OrganizationName}/_apis/Contribution/HierarchyQuery?excludeUrls=true&enumsAsNumbers=true&msDateFormat=true&noArrayWrap=true&api-version=5.0-preview.1
Request Body:
{
"contributionIds":["ms.vss-test-web.testcase-results-data-provider"],
"dataProviderContext":
{"properties":
{
"testCaseId":testcaseid,
"sourcePage":{"url":"https://dev.azure.com/{OrganizationName}/{ProjectName}/_testPlans/execute?planId={TestPlanId}&suiteId={Test SuiteID}","routeId":"ms.vss-test-web.testplans-hub-refresh-route","routeValues":{"project":"{ProjectName}","pivots":"execute","controller":"ContributedPage","action":"Execute"}}
}
}
}
Result:
If you want to get detailed info, you could pass the Test Run id and test result ID to Rest API: Results - Get
I'm trying to upload images on specific slack channel using Karate but no luck, I tried multiple times with different steps but still have 200 response and the image is not displayed in the channel.
Tried to post text content and successfully found the text on the channel.
Bellow are 2 of my tries following the Karate documentation:
#post
Feature: Post images
Background:
* url 'https://slack.com/api/files.upload'
* def req_params= {token: 'xxxxxxx',channels:'team',filename:'from Karate',pretty:'1'}
Scenario: upload image
Given path 'api','files'
And params req_headers
And multipart file myFile = { read: 'thumb.jpg', filename:
'upload-name.jpg', contentType: 'image/jpg' }
And multipart field message = 'image upload test'
And request req_headers
When method post
Then status 200
OR
Given path 'files','binary'
And param req_params
And request read('thumb.jpg')
When method post
Then status 200
Am I missing something? Tried the same examples found in Karate demo GitHub repository of uploading pdf and jpg but no luck.
Note: worked using Slack API UI.
You seem to be mixing up things, there is no need for a request body when you are using multipart. Your headers / params look off. Also based on the doc here, the name of the file-upload field is file. Try this:
Scenario: upload image
Given url 'https://slack.com/api/files.upload'
And multipart file file = { read: 'thumb.jpg', filename:
'upload-name.jpg', contentType: 'image/jpg' }
And multipart field token = 'xxxx-xxxxxxxxx-xxxx'
When method post
Then status 200
If this doesn't work, take the help of someone who can understand how to interpret the Slack API doc. Or get a Postman test working, then you'll easily figure out what you missed.
Whenever I run following from command line
newman run https://www.getpostman.com/collections/abcd1234
I get output displaying the statistics of failed and execute.
But I am looking for the complete HTML or JSON response from the URL to be printed on terminal after executing the above Newman query.How can I achieve this?
You have to add some log output in your requests.
For the requests where you want to see the response output add the following in the Postman Tests tab:
console.log(responseBody); // full response body
If you want to log a specific part you have to parse the response body into a JSON object:
let response = JSON.parse(responseBody);
console.log(reponse.myprop); // part of the full response body
Now if you run this collection with newman the CLI reporter will print the console log parts as well.
You need to use Postman API.
So you need to run something like this
newman run https://api.getpostman.com/collections/myPostmanCollectionUid?apikey=myPostmanApiKey
(see http://blog.getpostman.com/2018/06/21/newman-run-and-test-your-collections-from-the-command-line/)
You can get ApiKey in your Postman Cloud. You need to go to the workspace -> Integrations -> Browse Integrations -> Postman API View details -> Detail Get API Key/Existing API Keys
If you also need to add environment (if you use Variables), what you need is to run the same command with -e parameter 'newman run https://api.getpostman.com/collections/myPostmanCollectionUid?apikey=myPostmanApiKey -e dev_environment.json'
But what if you have your environment in the cloud as well? According to this document https://www.getpostman.com/docs/v6/postman/collection_runs/command_line_integration_with_newman you can pass URL as value. So you may run something like this
newman run https://api.getpostman.com/collections/myPostmanCollectionUid?apikey=myPostmanApiKey -e environments/{{environment_uid}}?apikey=myPostmanApiKey
It worked for me, hope this will help
I am using newman for webservices and microservices testing. This works fine for me.
summary.run.executions[0].response.text().toString()
After done event you should be able to get the response.
d is the collection exported from Postman.
newman.run({
collection: d,
// reporters: 'cli',
iterationCount: 1,
timeoutRequest: 10000,
timeoutScript: 5000,
delayRequest: 0,
insecure: false,
}).on('done', (err, summary) => {
if (err || summary.error) {
console.error('\ncollection run encountered an error.');
reject(summary.error);
}
else {
var xml = summary.run.executions[0].response.text().toString();
console.log(xml)
}
})
})
I am trying to port a class I use to connect to Cryptsy's authenticated API to Python 3.3. I have managed to solve the data type issues, and am getting something that is at least getting a request from the website, but it is rejecting my authentication, this is the code, API keys are not included, for obvious reasons...:
req['method'] = method
req['nonce'] = int(time.time())
post_data = urllib.parse.urlencode(req)
sign = hmac.new(self.Secret, str.encode(post_data), hashlib.sha512).hexdigest()
headers = {
'Sign': sign,
'Key': self.APIKey
}
print('headers: ',headers)
print('post data: ',post_data)
b=urllib.parse.urlencode(headers)
print(b)
test=post_data + '&'+ b
print('test: ',test)
data=test.encode()
print('data: ',data)
ret = urllib.request.urlopen(urllib.request.Request('https://www.cryptsy.com/api', data))
q=ret.read()
w=q.decode()
e=json.loads(w)
return self.post_process(e)
And this is the response from the server:
{'error': 'Unable to Authorize Request - Check Your Post Data', 'success': '0'}
Thanks.
The original script had the DATA and HEADERS components for the Request, but was somehow formatted in a way that confused Python 3 into thinking the HEADERS part was a TIMEOUT argument, and throwing an error about it needing to be an INT. This sent me on a wild goose chase of trying to concatenate the DATA and HEADERS.