I am trying to use AWS API and its API-key in POST/PUT call in Cypress, couldn't find enough details, can someone please help?
There are few options you can try, Here is one :
cy.intercept('POST', '/users*', (req) => {
req.headers['x-api-key'] = 'bearer my-bearer-auth-token'
}).as('addAuthHeader')
Refer Offical Link here:
https://docs.cypress.io/guides/guides/network-requests#Assertions
I was able to resovle it syntax is: authorization : key + value no quotes –
You can use cy.request. Although not outlined in the docs, it accepts an object:
cy.request({
method: 'POST',
url: 'https://jsonplaceholder.cypress.io/',
headers: { 'x-api-key': 'APIKEY' },
}).then((res) => {
// use the response with response.body
});
Related
Ruby aws-sdk v3 is having presigned_request method in Aws::S3::Presigner class. It is used for signing a request. But in aws-sdk v2, the presign_request is not available. I am trying to sign additional headers for the presigned URLs. Is there a way?
#Samtoddler
The main purpose of this problem to additionally sign 'x-amz-tagging' for a :put request presigned url, I tried to modify your code by adding additional header
class Aws::Signers::V4
def presigned_url(request, options = {})
now = Time.now.utc.strftime("%Y%m%dT%H%M%SZ")
body_digest = options[:body_digest] || hexdigest(request.body)
request.headers.delete('User-Agent')
request.headers['Host'] = request.endpoint.host
params = Aws::Query::ParamList.new
params.set("X-Amz-Algorithm", "AWS4-HMAC-SHA256")
params.set("X-Amz-Credential", credential(now))
params.set("X-Amz-Date", now)
params.set("X-Amz-Expires", options[:expires_in].to_s)
params.set("X-Amz-SignedHeaders", signed_headers(request))
params.set("X-Amz-Tagging", 'param=value')
params.set('X-Amz-Security-Token', credentials.session_token) if
credentials.session_token
endpoint = request.endpoint
if endpoint.query
endpoint.query += '&' + params.to_s
else
endpoint.query = params.to_s
end
endpoint.to_s + '&X-Amz-Signature=' + signature(request, now, body_digest)
end
end
When i tried this, the url which i obtained is having "X-Amz-tagging" header:
https://xxxxxxxxxxx.s3.amazonaws.com/mypath/myfile.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJILKMM53N2D4HKKA%2F20210114%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210114T154613Z&X-Amz-Expires=900&X-Amz-SignedHeaders=host%3Bx-amz-server-side-encryption-customer-algorithm%3Bx-amz-server-side-encryption-customer-key%3Bx-amz-server-side-encryption-customer-key-md5&X-Amz-Tagging=param%3Dvalue&X-Amz-Signature=f7f4c5752cb181bf0d8d1134b4a9add9ecad15116f26dd5979b992db87060498
But when i tried to make a request from my client, i am getting an saying:
There were headers present in the request which were not signed
<HeadersNotSigned>x-amz-tagging</HeadersNotSigned>
#samtoddler
This is how am setting in the client side
ObjectiveService.postFilesToAWS = function (presigned_url, file, headers={}) {
return $http({
method: 'PUT',
url: presigned_url,
ignoreLoadingBar: true,
data: file,
headers: {
'Content-Type': file.type,
'X-Amz-Tagging': 'param=value'
}
})
.then(function (response) {
return response;
}, function (error) {
return error;
});
}
The same client code is working for aws-sdk v3 in #presigned_request method.
So far what I read is that the header in the error message might not be the problem, it could be with any other header as well missing or not having the appropriate values set.
Are you using Specifying server-side encryption with AWS KMS (SSE-KMS)
or server-side encryption with customer-provided encryption keys because things are different, I see headers being present for SSE-C but the values are not specified.
for example this header x-amz-server-side-encryption-customer-algorithm in the URL is present
https://xxxxxxxxxxx.s3.amazonaws.com/mypath/myfile.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJILKMM53N2D4HKKA/20210114/us-east-1/s3/aws4_request&X-Amz-Date=20210114T154613Z&X-Amz-Expires=900&X-Amz-SignedHeaders=host;x-amz-server-side-encryption-customer-algorithm;x-amz-server-side-encryption-customer-key;x-amz-server-side-encryption-customer-key-md5&X-Amz-Tagging=param=value&X-Amz-Signature=f7f4c5752cb181bf0d8d1134b4a9add9ecad15116f26dd5979b992db87060498
the value should be AES256 as the documentation.
Your generated URL should be something like this
"https://.s3.amazonaws.com/?X-Amz-Security-Token=&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20180718T013339Z&X-Amz-SignedHeaders=content-type%253Bhost&X-Amz-Expires=1799&X-Amz-Credential=&X-Amz-Signature=
I would suggest giving AWS Signature Version 4 Signature Calculation a read to get the idea and which headers should be present.
I am unable to concatenate state in URL. Have searched but I could not find the solution, and i'm a beginner sorry for asking such a basic question. State has the value before it is sent as a parameter in URL(i have seen it in console), API returns the expected result if I hard code the value, but if a state or even a variable is passed as a parameter it returns error: "NO records found". What am I doing wrong?
this.state.secid = this.props.navigation.state.params.secid
console.log(this.state.secid)
this.state.classid = this.props.navigation.state.params.clasid
console.log(this.state.classid)
// Sending Request
fetch('exampleapi/parameter?
class=${this.state.classid}§ion=${this.state.secid}',{
headers: {
'Content-Type':'application/json',
'credentials': 'same-origin',
'Accept': 'application/json',
'Authorization': 'Bearer ' + tokenval
}
})
.then((response) => response.json())
.then((responseJson) => {
this.setState({ allstudents : responseJson })
console.log(this.state.allstudents)
})
You need to make following changes in your code
var url = 'exampleapi/parameter?class='+this.state.classid+'§ion='this.state.secid;
fetch(url,{
headers: {
'Content-Type':'application/json',
'credentials': 'same-origin',
'Accept': 'application/json',
'Authorization': 'Bearer ' + tokenval
}
})
Concatenation in react native is done by (+) operator. As URL also a string.
Hope it works for you.
I solved this issue by using backtick notation. Replacing ' '(single quote) in URL by ``(back ticks).
If anybody wants to read more about backtick notation this is an amazing answer : What is the usage of the backtick symbol (`) in JavaScript?
From what I can see in the code added the string concatenation is not done correctly.
It should be done as explained below:
this.state.secid = this.props.navigation.state.params.secid
this.state.classid = this.props.navigation.state.params.clasid
const requestURL = `exampleapi/parameterclass=${this.state.classid}§ion=${this.state.secid}`
Then, I would recommend to log and check if you are getting the URL as expected. Also I would suggest to stick to do this es6 way rather than using + for concatenation (As using + is more error prone, you might miss a space place where required - In your case the place you are setting Authorization header ).
Moreover why not use the good stuff when its supported out of the box by react native
Some references:
https://developers.google.com/web/updates/2015/01/ES6-Template-Strings#string_substitution
https://facebook.github.io/react-native/docs/javascript-environment.html
(search for text Template Literals in the page).
I'm wondering how to use the Asana APIs to send the command to complete a task.
I was trying something like:
https://app.asana.com/api/1.0/tasks/417207316735809/?opt_pretty&completed=true
but it doesn't work like that, I've checked the documentation, but couldn't find an answer.
Asana doc (someone requested it in comments): https://asana.com/developers/documentation/getting-started/input-output-options
Since I want to use it in my chrome extension I can't use curl so I treid ajax:
$.ajax({
type : "GET",
url : "https://app.asana.com/api/1.0/tasks/417207316174232/?opt_pretty",
data: {
completed: true,
},
success : function(result) {
result = JSON.stringify(result);
alert(result);
},
error : function(result) {
alert('xxx');
}
});
Any idea how to pass "completed=true" from doc in js?
If you are updating a resource you need to make a PUT request, not a GET request.
When I made this change, your AJAX request worked.
I need oAuth2 on google drive . But i cant get token. Which parameters is wrong ? Google documentation API cant help me for understanding what is wrong .
I do fetch request.
const options = {
method: 'post',
client_id: '{EXAMPLE}deajshot.apps.googleusercontent.com',
redirect_uri: 'https://drive.google.com/open?id={EXAMPLE}',
scope: 'https://www.googleapis.com/auth/drive.metadata',
prompt: 'none',
mode: 'no-cors',
response_type: 'token'
};
fetch('https://accounts.google.com/o/oauth2/auth',options)
.then(function (response) {
console.log(response);
})
Now i have error - 400. That’s an error.
Error: invalid_request
Required parameter is missing: response_type;
By your code example , you first need to get a code and then request a access token.try to follow this tutorial: https://developers.google.com/identity/protocols/OpenIDConnect#authenticatingtheuser
You have there a request for example:
https://accounts.google.com/o/oauth2/v2/auth?
client_id=424911365001.apps.googleusercontent.com&
response_type=code&
scope=openid%20email&
redirect_uri=https://oauth2-login-demo.example.com/code&
state=security_token%3D138r5719ru3e1%26url%3Dhttps://oauth2-login-demo.example.com/myHome&
login_hint=jsmith#example.com&
openid.realm=example.com&
hd=example.com
After this , with your 'code' parameter you get you could make request to get a access token (you have there also a example of this request )
Good luck
I'm trying to call the Prosperworks API through Code by Zapier. I can do this easy through curl, but for the life of me cannot get this POST call to work using fetch. Below is what I've got...any help appreciated. Thanks
fetch('https://api.prosperworks.com/developer_api/v1/people/fetch_by_email', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-PW-AccessToken': 'API_TOKEN',
'X-PW-Application': 'developer_api',
'X-PW-UserEmail': 'EMAIL'
},
body: JSON.stringify({'email': input.email})
}).then(function(res) {
var people_id = res.id;
return res.json();
}).then(function(body) {
callback(null, {id: 1234, rawHTML: body});
}).catch(function(error) {
callback("error");
});
I'm the lead engineer on the ProsperWorks developer API. sideshowbarker is correct; we do not accept cross-origin requests from Zapier. Given that we offer Zapier integration, though, perhaps we should. I'll bring it up with the dev team and see if we can get that onto an upcoming release :)