- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2024 11:40 PM - edited 10-02-2024 11:51 PM
Hi, i need to send info to third party APIGEE and here is the script include
//hashing the reqPayload to generate Signature
var r = new sn_ws.RESTMessageV2(apiname, apimethod);
r.setEndpoint(xxurlxx);
r.setHttpMethod("get");
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
Somehow, the Request string send is inverted, thus getting error 401 "invalid signature".
Request string that I sent: xxurlxx?file=test.xlsx&folder=WO123
Hash string that I used: ?folder=WO123&file=test.xlsx
To success, I should send the request string same as hashing : xxurlxx?folder=WO123&file=test.xlsx
Any one knows what is problem here or how to control the request string in REST Message or script include?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 05:00 AM
Try this once:
var queryParam = {
'folder': "WOT123",
'file': "test.xlsx"
};
// Construct the query string in the desired order
var reqPayload = '?folder=' + encodeURIComponent(queryParam['folder']) +
'&file=' + encodeURIComponent(queryParam['file']);
// Create the full endpoint URL
var fullUrl = xxurlxx + reqPayload; // Combine endpoint and query parameters
// Hashing the reqPayload to generate Signature
// Make sure to use reqPayload for generating the signature
var r = new sn_ws.RESTMessageV2(apiname, apimethod);
r.setEndpoint(fullUrl); // Use the full URL with query parameters
r.setHttpMethod("get");
r.setStringParameterNoEscape('Content-Type', "application/json");
r.setStringParameterNoEscape('oauth_sign', Signature);
r.setStringParameterNoEscape('oauth_client_key', oAuthClientKey);
// No need to set query parameters separately, as they are already in the URL
// Execute the request
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 01:48 AM
ok, got it. Try bellow updated script once and let me know its working or not:
var queryParam = {
'folder': "WOT123",
'file': "test.xlsx"
};
// Manually construct the reqPayload in the specified order
var reqPayload = '?folder=' + encodeURIComponent(queryParam['folder']) +
'&file=' + encodeURIComponent(queryParam['file']);
// Ensure that you use reqPayload in your hashing logic here
var r = new sn_ws.RESTMessageV2(apiname, apimethod);
r.setEndpoint(xxurlxx); // Do not append reqPayload here
r.setHttpMethod("get");
r.setStringParameterNoEscape('Content-Type', "application/json");
r.setStringParameterNoEscape('oauth_sign', Signature);
r.setStringParameterNoEscape('oauth_client_key', oAuthClientKey);
// Set the query parameters without changing their order
r.setQueryParameter('folder', queryParam['folder']);
r.setQueryParameter('file', queryParam['file']);
// Execute the request
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 02:04 AM
the request string still "xxurlxx?file=test.xlsx&folder=WO123"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 05:00 AM
Try this once:
var queryParam = {
'folder': "WOT123",
'file': "test.xlsx"
};
// Construct the query string in the desired order
var reqPayload = '?folder=' + encodeURIComponent(queryParam['folder']) +
'&file=' + encodeURIComponent(queryParam['file']);
// Create the full endpoint URL
var fullUrl = xxurlxx + reqPayload; // Combine endpoint and query parameters
// Hashing the reqPayload to generate Signature
// Make sure to use reqPayload for generating the signature
var r = new sn_ws.RESTMessageV2(apiname, apimethod);
r.setEndpoint(fullUrl); // Use the full URL with query parameters
r.setHttpMethod("get");
r.setStringParameterNoEscape('Content-Type', "application/json");
r.setStringParameterNoEscape('oauth_sign', Signature);
r.setStringParameterNoEscape('oauth_client_key', oAuthClientKey);
// No need to set query parameters separately, as they are already in the URL
// Execute the request
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 08:04 PM
Thanks. the signature is fixed, but i got another error "Received 405 Response without Allow Header" which i believe i didnt set proper query parameters. Meaning need to use setQueryParameter to send completed URL and not using payload string.