How to debug JMeter the error JsonToken EndArray is not valid - jmeter

Before hand will be some images as I don't know how to explain them better.
I have an HTTP Request POST that has the parameters below:
{"ShiftId":${Param_S02_ShiftId},"Date":null,"StartTime":"${Param_S02_Pick_Date}T00:00:00.000Z","EndTime":"${Param_S02_Pick_Date}T23:00:00.000Z","RouteTemplateId":${Param_S02_RouteTemplateId},"VehicleId":${Param_S02_VehicleId},"SelectedEmployees":[{"RouteTemplateRoleId":${Param_S02_RoleId_1_driver},"EmployeeId":${Param_S02_1_driver}},{"RouteTemplateRoleId":${Param_S02_RoleId_2_driver},"EmployeeId":${Param_S02_2_driver}],"TeamBoardId":${Param_S02_Teamboard}}
As you can see this is the same API sent by the browser
The problem is that I am getting this error message that I could not find the solution aroud.
{"message": "JsonToken EndArray is not valid for closing JsonType Object. Path 'SelectedEmployees1', line 1, position 237.","type":"Newtonsoft.Json.JsonReaderException","stackTrace":" at Newtonsoft.Json.JsonReader.ValidateEnd(JsonToken endToken)\r\n at Newtonsoft.Json.JsonTextReader.ParsePostValue(Boolean ignoreComments)\r\n at Newtonsoft.Json.JsonTextReader.Read()\r\n at Newtonsoft.Json.Linq.JContainer.ReadContentFrom(JsonReader r, JsonLoadSettings settings)\r\n at Newtonsoft.Json.Linq.JContainer.ReadTokenFrom(JsonReader reader, JsonLoadSettings options)\r\n at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)\r\n at ApiService.EntityObjectServiceController2.ParseSaveRequestAsync() in C:\\a\\1\\s\\API\\src\\Framework\\ApiService\\EntityObjectServiceController.NETStandard.cs:line 151\r\n at ApiService.EntityObjectServiceController2.Create() in C:\a\1\s\API\src\Framework\ApiService\EntityObjectServiceController.NETStandard.cs:line 123\r\n at lambda_method3708(Closure , Object )\r\n at g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)"}
Do I need to add something in the Header?
Maybe is something with this part of the call where I have 0 and 1

You're sending an invalid JSON, your SelectedEmployees array is missing closing bracked ], my expectation is that you need to amend your payload to something like:
{
"ShiftId": ${Param_S02_ShiftId},
"Date": null,
"StartTime": "${Param_S02_Pick_Date}T00:00:00.000Z",
"EndTime": "${Param_S02_Pick_Date}T23:00:00.000Z",
"RouteTemplateId": ${Param_S02_RouteTemplateId},
"VehicleId": ${Param_S02_VehicleId},
"SelectedEmployees": [
{
"RouteTemplateRoleId": ${Param_S02_RoleId_1_driver},
"EmployeeId": ${Param_S02_1_driver}
},
{
"RouteTemplateRoleId": ${Param_S02_RoleId_2_driver},
"EmployeeId": ${Param_S02_2_driver}
}
],
"TeamBoardId": ${Param_S02_Teamboard}
}
once you start sending syntactically correct JSON at least this error will go away, you can test it against i.e. online JSON validator
Going forward given you're capable of successfully execute the request using your browser you can just record it using JMeter's HTTP(S) Test Script Recorder or JMeter Chrome Extension

Related

Jmeter 5.3 + Taurus 1.16. Correctly insert property from YAML file to HTTP request

My current test suite requires me to send some HTTP POST requests to API, some of which require specific objects to be posted via HTTP Request. I encountered some problems when trying to fetch those object from my YAML file when running Jmeter in Taurus.
I will attach part of my YAML file here for context (had to delete of change some properties for confidentiality):
jmeter:
properties:
number.of.users: 1000
rampup.period: 300
loop.count: 1
client.id: "23id"
array.of.clients: ["id1","id2","id3"]
ids: [1,2,3]
rq:
- "number": "7312sa1"
"signed": "2020-06-08T00:00:00.000+0000"
"crmClientId": "1-32D1P"
The problem is: when I try to pass string properties to my HTTP Request like that:
{
"id": 1986,
"jsonrpc": "2.0",
"method": "method",
"params":
{
${__P(rq,)}
}
}
all properties are wrapped in single quotation marks which causes request to receive error 400 in return because request after acquiring property is looking like this:
{
"id": 1986,
"jsonrpc": "2.0",
"method": "method",
"params":
{
'rq':
'number': '7312sa1'
'signed': '2020-06-08T00:00:00.000+0000'
'crmClientId': '1-32D1P'
}
}
Is there a way to pass string properties to request with double quotation marks or structure my YAML file in a way, which will construct request according to this example:
{
"id": 1986,
"jsonrpc": "2.0",
"method": "method",
"params":
{
rq:
"number": "7312sa1"
"signed": "2020-06-08T00:00:00.000+0000"
"crmClientId": "1-32D1P"
}
}
I tried using groovy replaceAll() method but it doesn't work with complex objects. My only solution as of right now is running some sort of groovy script in setUp thread and then acquire them is HTTP request via groovy jmeter function
You're sending a string representation of Python's dictionary, you need to send it as a simple string.
Check out YAML Multiline Strings and choose the most convenient option for you.
Example usage:
modules:
jmeter:
properties:
rq: >
\n"number": "7312sa1"\n
"signed": "2020-06-08T00:00:00.000+0000"\n
"crmClientId": "1-32D1P"\n
Taurus is presumably built to make testers and/or devops lives easier, it doesn't seem that it's your case, perhaps you should consider switching to JMeter without any wrappers instead?

Which controller to use in Jmeter?

I want to create a controller that should run a till the condition fails. How it can be implemented in Jmeter.
The controller should contain a HTTP Request with a post body which is dynamic the request should continue till the condition fails,but i dont know where the should i apply that condition.
{
"access": {
"identifier": "9876f",
"Reproduce": "Right",
"possible": {
"id": "u7ur038",
"value": "Move"
}
}
}
If the response "Reproduce" contain "Right"then it should run again HTTP Request for new body and If the response "Reproduce" contain "Wrong"then it should stop executing.
You can use a While Controller which will contain your request.
Condition of While Controller will be:
${__jexl3("${response}" != "Wrong")}
Add as child of your HTTP Request a JSON Extractor:
Names of created variables: response
JSON Path Expressions: $..Reproduce
Match No.: 1
To reset variable for next thread loop iteration, add before While Controller a Flow Control Action and put inside it a preprocessor called User Parameters .
Click « Add Variable » and set :
Name: response
User_1: Right

Http call to the graph and asynchronous pattern does not seems to work

I'm triggering an HTTP call from a power automate workflow to the MS Graph.
The operation is a long operation (cloning a MS teams), and return HTTP 202, with the Location header.
The HTTP action has the Asynchronous Pattern option set to yes.
I'm expecting Power Automate to automatically handle the wait for long operation to be finished.
However, the http action returns the 202 code, and I have to do myself the plumbing (do until sleep pattern).
How to properly call MS graph long operation and properly wait for completion ?
FYI, here's a sample request I make:
Method : POST
URL : https://graph.microsoft.com/v1.0/teams/b78b07c8-9af3-4af9-b995-315c6b674da8/clone
Body :
{
"displayName": "Some new team",
"mailNickname": "somenewteam",
"partsToClone": "apps,tabs,settings,channels,members",
"visibility": "private"
}
Headers :
{
"ContentType": "application/json"
}
Plus all authentication headers (handled by the http action itself):
{
"authority": "https://login.microsoftonline.com",
"tenant": "some guid",
"audience": "https://graph.microsoft.com",
"clientId": "some guid",
"secret": "*sanitized*",
"type": "ActiveDirectoryOAuth"
}
In comparison, using the option to call other long workflows (with http trigger and final "http response" action) works as expected

Google Speech API: the requested URL was not found on this server

I am attempting some simple tests on the Google Speech API, and when my server makes a request to this url (below), I get the 404. that's an error response. Not sure why.
https://speech.googleapis.com/v1/speech:recognize?key=[MY_API_KEY]
The body of my request looks like this:
{
"config": {
"languageCode": "en-US",
"encoding": "LINEAR16",
"sampleRateHertz": 16000,
"enableWordTimeOffsets": true,
"speechContexts": [{
"phrases": ["Some", "Helpful", "Phrases"]
}]
},
"audio":{
"uri":"gs://mydomain.com/my_file.mp3"
}
}
And here is the response:
As you can see, that is a valid resource path, unless I'm totally mistaken about something (I'm sure I am): https://cloud.google.com/speech-to-text/docs/reference/rest/v1/speech/recognize
Update 1:, Whenever I try this with the Google API explorer tool, I get this quota exceeded message (even though I have not yet issued a successful request to the API).
{
"error": {
"code": 429,
"message": "Quota exceeded for quota metric 'speech.googleapis.com/default_requests' and limit 'DefaultRequestsPerMinutePerProject' of service 'speech.googleapis.com' for consumer '[MY_API_KEY]'.",
"status": "RESOURCE_EXHAUSTED",
"details": [
{
"#type": "type.googleapis.com/google.rpc.Help",
"links": [
{
"description": "Google developer console API key",
"url": "https://console.developers.google.com/project/[my_project_id]/apiui/credential"
}
]
}
]
}
}
Update 2: Interestingly, I was able to get some 200 ok's using the Restlet client, but even in those cases, the response body is empty (see screenshot below)
I have made a test by using the exact URL and Body content you added to the post, however, I was able to execute the API call correctly.
I noticed that if I add some extra character to the URL, it fails with the same 400 error since it doesn't exist. I would suggest you to verify that the URL of your request doesn't contain a typo and that the client you use is executing the API call correctly. Also, ensure that your calling code is not encoding the url, which could cause issues given the colon : that appears in the url.
I recommend you to perform this test by using the Try this API tool directly or Restlet client which are the ones that I used to replicate this scenario.

MailChimp API 3.0 batch request returns 400 Invalid Resource error

I've been trying to use the batch endpoint of MailChimp API (version 3.0) to subscribe new users to a list, but can't make it work.
Here is the request:
POST /3.0/batches
{
"operations": [
{
"method" : "POST",
"path" : "lists/c852ce5c86/members",
"body": "{\"email_address\":\"email#domain.tld\", \"status\":\"subscribed\"}"
}
]
}
The request seems ok cause I get a 200 response:
{
"id": "49abca6ef3",
"status": "finished",
"total_operations": 1,
"finished_operations": 1,
"errored_operations": 1,
"submitted_at": "2015-09-21T18:11:16+00:00",
"completed_at": "2015-09-21T18:11:23+00:00",
"response_body_url": "https://mailchimp-api-batch.s3.amazonaws.com/49abca6ef3-response.tar.gz?..."
}
However, as you can see, the only operation in my batch is errored.
Here is the response_body_url for this operation:
[{
"status_code":400,
"operation_id":null,
"response":"{
\"type\":\"http://kb.mailchimp.com/api/error-docs/400-invalid-resource\",
\"title\":\"Invalid Resource\",
\"status\":400,
\"detail\":\"The resource submitted could not be validated. For field-specific details, see the 'errors' array.\",
\"instance\":\"\",
\"errors\":[{
\"field\":\"\",
\"message\":\"Schema describes object, NULL found instead\"
}]
}"
}]
which is not very helpful :(
Note that if I directly hit POST lists/c852ce5c86/members with {"email_address":"email#domain.tld", "status":"subscribed"} payload, it's working properly.
That was actually a bug in the mailchimp API. After reaching them they quickly fixed it.

Resources