I need to post some values to a REST service. I'm using POSTMAN rest client for my test and i can post string, integer, boolean values to rest service there is no problem. But i could not post array values ;
I am using this parameter, this parameter is working except Array values ;
{
"parameters": [
{
"type": "string",
"name": "nameandsurname",
"value": {"string":{ "value": "myname"}}
},
{
"type": "Array/string",
"name": "arrayvariable",
**"value": {"string":{ "value": "value1"}}** This line is not working...
}
]
}
In Postman you can post JSON this way:
Select method POST
In section Body choose raw and content-type JSON(application/json)
Paster your JSON into Body
You can download this export from Postman and try it
https://www.dropbox.com/s/ulmoc8n8gmgb076/tests.postman_collection.json?dl=0
Related
I'm trying to send a custom JSON payload from my pipeline on Jenkins after the last successful stage, like this:
post {
success {
script {
def payload = """
{
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": "SonarQube report from Jenkins Pipeline"
},
{
"type": "TextBlock",
"text": "Code was analyzed was successfully.",
"wrap": true,
"color": "Good",
"weight": "Bolder"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.3"
}"""
httpRequest httpMode: 'POST',
acceptType: 'APPLICATION_JSON',
contentType: 'APPLICATION_JSON',
url: "URL",
requestBody: payload
}
}
}
}
But I get an error
Error when executing success post condition:
groovy.lang.MissingPropertyException: No such property: schema for class: groovy.lang.Binding
at groovy.lang.Binding.getVariable(Binding.java:63)
I'm using the HTTP Request plugin available for Jenkins and the format of the JSON payload is correct for MS Teams.
The issue is actually a groovy syntax error. You can easily check this in something like https://groovy-playground.appspot.com/ by adding your def payload = ... statement.
There are multiple ways to get multiline strings in groovy:
triple single quoted string
triple double quoted string
slashy string
dollary slashy string
Apart from the single quoted string, they also have a secondary property which is interpolation
Notice how in the initial JSON payload, there's a "$schema" key? Using triple double quoted strings makes groovy want to find a schema variable and use it's value to construct that payload variable.
You have two separate solutions:
Use triple single quoted string - just update """ to '''
Escape the variable - just update "$schema" to "\$schema" (making $ a literal $ instead of it being used as an interpolation prefix)
Im using the following JSON and query to calculate the array length in the JMeter json extractor.
{
"data": {
"modal": "HJ",
"technicalid": "e492fc62-a886-67a461b76de8",
"viewModel": {
"series": [
{
"name": "H_0_G_0_R_0",
"UID": "J_0_G_0_R_0",
"description": "Test1",
"type": "series",
"groups": [
{
"name": "H_0_G_0",
"UID": "G_0_G_0",
"description": "Group 1",
"type": "group"
}
],
"postProcessing": null
}
]
},
"status": "success"
},
"success": true,
"statusCode": 200,
"errorMessage": ""
}
Here is the query.
data.Model.series[0].groups.length
This is working fine in the online jsonquerytool. When I use this query in the JMeter json extractor, it is returning null. I assume this is because it is returning an integer because other similar queries which are returning strings are working fine with json extractor . How to find the array length in JMeter json extractor?
Why JSON extractor to calculate the length? You could use a post processer. Like JSR223 post processer using groovy script.
import groovy.json.*
def response = prev.responseDataAsString ;
def json = new JsonSlurper().parseText(response) ;
def sizeResultPractitioners = json.data.viewModel.series[0].groups.size();
log.info("---------->"+sizeResultPractitioners);
I tried with your JSON response payload and also tried with modified response payload,
With modified response payload,
With JSON Extractor you can provide "Match No." as -1:
and the number of matches will be available as foo_matchNr JMeter Variable:
Alternative option is going for JSON JMESPath Extractor which provides length() function so you can get the size of the array as:
length(data.viewModel.series[0].groups)
or if you prefer pipe expressions
data.viewModel.series[0].groups | length(#)
I am trying to send the emails via Sendgrid using v3 API using postman, I have created 3 separate variables in 3 different requests, I want to pass all those 3 variables in a single mail, for that I have used below sendgrid
https://api.sendgrid.com/v3/mail/send
with below body
{
"personalizations": [
{
"to": [
{
"email": "testing#test.com",
"name": "API Testing"
}
],
"subject": "API testing successful"
}
],
"from": {
"email": "noreply#testApi.com",
"name": "API Testing"
},
"content": [
{
"type": "text/plain",
"value": "{{variable1}}" //In variable1 has a dynamic values
}
]
}
but the above format sending the mail body as {{Variable1}}, can someone help me on this?
For handlebar {{ variable_value }} substitutions in dynamic HTML templates, u need to pass the variable value as JSON structure with the key as "dynamic_template_data" as part of personalizations.
U also need to pass the (API Key) Authorization as "Authorization: and Value as "Bearer ".
In the Request Body pass the personalizations object.
{
"personalizations": [
{
"to": [
{
"email": "ron#***",
}
],
"dynamic_template_data": {
"<variable_name>": <variable_value>
}
}
],
"from": {
"email": "development#crosspaymt.com",
"name": "Development Team"
},
"content": [
{
"type": "text/html",
"value": "replace body with template content"
}
],
"template_id": "******"
}
From what I understand of the question you want to send multiple requests with different values.
Say, GET to https://google.com/q={{search}} and you have multiple search queries, (dog, chess, marvel, stackoverflow)
Create a collection in postman
Add a GET request to https://google.com/q={{search}} with necessary headers and hit Save
Create a CSV file with the header search and all search values under it
Hit the run button for the newly created collection
Set the Iterations field to the number of queries you have. In this example it is 4
Look for the field Data, select the created CSV file
Ensure the data is correctly being picked up by hitting the Preview button
Hit Run test
You can view the output in the Postman Console
To open Postman Console Head to View in the application menu, and click on "Show Postman Console" or use the keyboard shortcut (CMD/CTRL + ALT + C) to open.
We are sending messages to a service bus using a logic app. These messages will later be consumed by another service, the service expects the message content to be a string - essentially a stringified JSON object, with escape characters.
We are not able to find a method to stringify a JSON object in Logic Apps. Even if we explicitly provide a escaped string the logic app itself detects that it's stringified JSON and unescapes it and then sends it as a JSON object. We don't want that, we simply want it to send the string as it is. We have already tried changing the content type to text/plain, it does not work. The logic app always sends the unescaped string as JSON.
This post on MSDN: https://social.msdn.microsoft.com/Forums/office/en-US/e5dee958-09a7-4784-b1bf-facdd6b8a568/post-json-from-logic-app-how-to-escape-data?forum=azurelogicapps is of no help because doing this will violate the request contract of the message consuming service
Do you need the stringified message to include opening and closing double quotes?
I've tried this and it worked for me.
I have my JSON object as an output of a compose
Then, I initialised a variable with the Base64 encoded value of the escaped stringified JSON (you need to add ALL the proper escaping required,
mine was just a PoC)
Then, you send the variable already in Base64 to Service Bus. (You need to remove the encoding on that action).
"actions": {
"Compose_JSON_Object": {
"inputs": {
"message": "I want this as a string"
},
"runAfter": {},
"type": "Compose"
},
"Initialise_Variable_with_Stringified_JSON_Base64_Encoded": {
"inputs": {
"variables": [
{
"name": "jsonAsStringBase64",
"type": "String",
"value": "#base64(concat('\"', replace(string(outputs('Compose_JSON_Object')), '\"', '\\\"'), '\"'))"
}
]
},
"runAfter": {
"Compose_JSON_Object": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Send_message": {
"inputs": {
"body": {
"ContentData": "#variables('jsonAsStringBase64')",
"ContentType": "text/plain"
},
"host": {
"connection": {
"name": "#parameters('$connections')['servicebus']['connectionId']"
}
},
"method": "post",
"path": "/#{encodeURIComponent(encodeURIComponent('temp'))}/messages",
"queries": {
"systemProperties": "None"
}
},
"runAfter": {
"Initialise_Variable_with_Stringified_JSON_Base64_Encoded": [
"Succeeded"
]
},
"type": "ApiConnection"
}
},
This way, I got the message stringified.
HTH
I am using JSONAPI Specification http://jsonapi.org/format/#status
And I have data like below,
{
"data":
{
"type": "tag",
"id": "1",
"attributes": {
"name": "Test"
}
}
}
How do I make a post request to the end point using postman chrome extension ?
I am trying to make a call but I cannot get the params.
Obs. I already set my Content-Type as application/vnd.api+json
Thanks !
Select
METHOD POST
Then under Body chose raw
here is a screenshot
on/json