cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

UNKNOWN_METHOD_ERROR in HTTP monitor

kimberly_mirkes
Participant

In every http monitor, my first call is always to get an auth token. This step works fine. I pass it in the second step as the 'jwt' in the pre-execution step.

In two of my http monitors however, I also need to pass another  header in pre-execution called ###-Api-Key. I have to pass the request body to that call. That is my jsonData being stringified, then passed to const hash. That's then returned and added to the api.addHeader.

I'm always getting the error UNKNOWN_METHOD_ERROR so hoping someone can take a look at this pre-execution script I've written, and help me get past this issue.

(Certain items changed for secure reasons)

Pre-execution script:

const jsonData = [
{
"messageType": "welcome",
"context": "urn:com:33333",
"messageTypeCode": 62,
"sendSMS": true,
"sendEmail": false,
"smokeTest": true,
"bypassConsent": {
"countryCode": "+1",
"mainNumber": "3142083329"
},
"referenceDetails": {
"referenceType": "Agree",
"referenceNumber": "33333",
"driverDetails": {
"firstName": "B",
"lastName": "N",
"communicationPreference": {
"locale": "en_US",
"source": "Location"
}
},
"dateTime": "2023-01-17T04:29:00Z",
"brandCode": "##",
"brandName": "### ### ###"
},
"locationDetails": {
"group": "0000",
"groupnumber": "00000",
"groupemail": "",
"timeZone": "America/Chicago",
"locationPrettyName": "City",
"preferredLanguage": "en",
"phone": {
"countryCode": "+1",
"mainNumber": "2444444444"
}
}
}
];
 
api.setVariable("requestData", JSON.stringify(jsonData));
 
const TEST = 'LLLL';
const callingAppHeader = api.getHeader('###-Calling-Application');
 
let apiKey;
if (callingAppHeader && callingAppHeader.toLowerCase() === TEST.toLowerCase()) {
  const key = 'kdjflkadiowejfjkldfjs;kdlfj'; 
  const hash = CryptoJS.HmacSHA256(api.getValue("requestData"), key);
  apiKey = CryptoJS.enc.Base64.stringify(hash);
} else {
  apiKey = "Bearer " + api.getValue("jwt"); //jwt token from first step of this http monitor
}
 
api.addHeader('###-Api-Key', apiKey);
request.addHeader("Authorization", apiKey);

 

When looking at the execution details for more info on this error, I only get this:

//request

[
{
"requestId": "HTTP_CHECK_STEP-alpha-numericInfo",
"requestName": "send welcome message",
"sequenceNumber": 2,
"url": "",
"method": "",
"requestBody": "",
"requestHeaders": []
}
]

//response

[
{
"responseHeaders": [],
"responseBody": "",
"responseMessage": "",
"responseStatusCode": 0,
"responseSizeInBytes": 0,
"responseBodySizeLimitExceeded": false,
"failureMessage": ""
}
]

//execution

[
{
"visitId": "numericInfo",
"resolvedIps": [],
"healthStatusCode": 18,
"healthStatus": "UNKNOWN_METHOD_ERROR",
"peerCertificateDetails": "",
"redirectsCount": 0,
"peerCertificateExpiryDate": 0,
"processingMode": "STANDARD"
}
]

2 REPLIES 2

HannahM
Dynatrace Leader
Dynatrace Leader

It looks like you are using CryptoJS.HmacSHA256 but haven' added this method to the pre-execution script. You can find information on adding this here

Synthetic SME and community advocate.

kimberly_mirkes
Participant

This I did find a solution to, with the help of my Dynatrace team

In the pre-execution:

const jsonData=[{your data here}]

const stringData = JSON.stringify(jsonData);
request.setBody(stringData);

var CryptoJS=CryptoJS - HmacSHA256 code here

var CryptoJS=CryptoJS - Base64 code here

const key = "your key here";

const hash = CryptoJS.HmacSHA256(stringData, key);
const b64Hash = CryptoJS.enc.Base64.stringify(hash);

request.addHeader('Api-Key', b64Hash);
request.addHeader("Authorization", "Bearer " + api.getValue("jwt"));

 

Featured Posts