# UNKNOWN\_METHOD\_ERROR in HTTP monitor

**URL:** <https://community.dynatrace.com/t/unknown-method-error-in-http-monitor/45652>\
**Category:** Synthetic Monitoring\
**Tags:** http-monitor, synthetic-monitoring, private-synthetic-locations\
**Created:** [May 17, 2024, 2:31pm UTC](https://community.dynatrace.com/t/unknown-method-error-in-http-monitor/45652 "2024-05-17T14:31:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kimberly\_mirkes](https://avatars.discourse-cdn.com/v4/letter/k/edb3f5/32.png) [@kimberly\_mirkes](https://community.dynatrace.com/u/kimberly_mirkes)\
**Post date:** [May 17, 2024, 2:31pm UTC](https://community.dynatrace.com/t/unknown-method-error-in-http-monitor/45652/1 "2024-05-17T14:31:17Z")

</div>

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&nbsp; 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()) {&nbsp; const key = ‘kdjflkadiowejfjkldfjs;kdlfj’;&nbsp;&nbsp; const hash = CryptoJS.HmacSHA256(api.getValue(“requestData”), key);&nbsp; apiKey = CryptoJS.enc.Base64.stringify(hash);} else {&nbsp; 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”  
}  
]

---

<div class="post-metadata">

**Author:** ![hannahmac](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/hannahmac/32/41823_2.png) [@hannahmac](https://community.dynatrace.com/u/hannahmac)\
**Post date:** [July 1, 2024, 11:17am UTC](https://community.dynatrace.com/t/unknown-method-error-in-http-monitor/45652/2 "2024-07-01T11:17:51Z")

</div>

It looks like you are using CryptoJS.HmacSHA256&nbsp;but haven’ added this method to the pre-execution script. You can find information on adding this [here](https://community.dynatrace.com/topic/209462)

---

<div class="post-metadata">

**Author:** ![kimberly\_mirkes](https://avatars.discourse-cdn.com/v4/letter/k/edb3f5/32.png) [@kimberly\_mirkes](https://community.dynatrace.com/u/kimberly_mirkes)\
**Post date:** [July 1, 2024, 12:31pm UTC](https://community.dynatrace.com/t/unknown-method-error-in-http-monitor/45652/3 "2024-07-01T12:31:27Z")

</div>

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 -&nbsp;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”));
