Postman - How to pass a global variable into JSON body - json

I'm working with Postman right now and I have to do a lot of requests, and in the body I'm passing a JSON content. I would like to know if is there a way to pass the value of a global variable into JSON body. Thank you.

If using a raw JSON body:
{
"test key":"{{global variable}}"
}
On sending the request, the curly braces will be replaced with the value of the variable.

I think what you want to do is described here.
To use a variable you need to enclose the variable name with double curly braces – {{my_variable_name}}.

Double curly bracket is working in header parameter, url or inside JSON body. Inside tests you should use globals example: {"url": globals.url} or {"url": globals["url"]}

You can pass
{
"productId": {{**ProductID**}},
"quantity": 1
}
Where ProductID is your global variable name
in raw format JSON (application/json)

Yep, double curly brackets is the way to go to achieve this - make sure you have the latest version of Postman (though if you are still running 2014 code when this feature was introduced, shame on you!)
eg:
{
"variable": "{{value}}"
}
See the second paragraph here in the Variables section of the documentation - it specifically mentions the request body.

Related

How I can use curly braces inside a div element in Angular?

<p>Pattern Format (All Parameters are Optional):</p>
<p>{Parameter: 1, Parameter 2}</p>
Above is my code. the second line throws an error because I'm using curly braces in Angular. The error goes away if I use '(' braces.
But I want the curly braces printed.
What can I do so that I get the following result in the web UI? -
Pattern Format (All Parameters are Optional):
{Parameter: 1, Parameter 2}
P.S: I want to print the curly braces. I'm not trying string interpolation.
Values inside tags must be interpolated, which means surrounded by double curly braces {{ YOUR_VALUE }}.
You can take a look at official documentation to see if it can help
your case, since it's not very clear what are you trying to do.
Guide to interpolation:
https://angular.io/guide/interpolation
If you are trying to write it down you can try with:
{{"{Parameter: 1, Parameter 2}"}}
Please check this solution, I hope it will solve your problem.
<span>{{'{'}} {{Parameter:1, Parameter 2}} {{'}'}}.</span>
Its output will be as:
{ParameterValue1, ParameterValue2}
If you want to display single bracess { only instead of variable, you can use ng-non-bindable.
The ngNonBindable directive tells AngularJS not to compile or bind the contents of the current DOM element, including directives on the element itself that have a lower priority than ngNonBindable. Example
<div>Normal: {{1 + 2}}</div>
<div ng-non-bindable>Ignored: {{1 + 2}}</div>
Output of above will be:
Normal: 3
Ignored: {{1 + 2}}
When use ngNonBindable it will ignore parentheses in DOM element.
See Documentation ngNonBindable
Just add the #ngNonBindable directive to the element.

How to send Json containing xml value from POSTMAN?

I am using postman to test api. The method is POST and JSON data is:
{ "page" : "<xml> <content xs="xyz">.......</xml>" }
In body I have selected 'raw' and selected 'JSON' which automatically adds 'application/json' to the header.
When I send this request, I get error due to the double quotes in the <content> tag. Does this need handling (escaping) at input or inside the api code?
You have to escape double quotes with \, e.g.
{"page":"<?xml version=\"1.0\"?>\n<page></page>"}
Also make sure you set HTTP header Content-Type: application/json.

What to Call Angular Markup In Html?

This is a question about semantics. What do I call the 'angular markup' here?
<h1>{{someScopeObject.someProperty}}</h1>
What's the proper way to refer to this and things like ng-model/ng-bind. Or do I go with specific names and say "the ng-model attribute / directive" and there isn't anything generic?
The double curly brackets are for data binding and what's inside the double curly brackets is an expression.
https://docs.angularjs.org/guide/expression

Polymer hostAttributes Error

I have been following along the Polymer 1.0 Developer guide and I stumbled when getting up to the specific part about hostAttributes.
When I take the example code from the docs:
hostAttributes: {
string-attribute: 'Value',
boolean-attribute: true
tabindex: 0
}
and add it to my prototype, the browser keeps throwing the error:
Uncaught SyntaxError: Unexpected token -
on the lines where there are dashes. Strangely, when I put quotes around string-attribute and boolean-attribute, it renders fine.
Is this an error on my part or is it an error in the docs somehow?
In The way that this example represented string-attribute, string-attribute refers to a string as an attribute that should be set on the label of your element declaration. Also, as you may have noticed by the way you are declaring string-attribute in the example, Javascript assumes that string-attribute is a variable, and variables can not be declared as "my-variable" are declared "myvariable", all strings together.
I think that's the reason why you should declared as follows:
hostAttributes: {
"my-var": 'Value',// Javascript assumes that my-bar is an string
my-var-two: 'value'// Javascript assumes that my-bar-two is a variable (this will fail)
tabindex: 0
}
I hope you have understood me, my English is very bad.
Edit
If a custom elements needs HTML attributes set on it at create-time, these may be declared in a hostAttributes property on the prototype, where keys are the attribute name and values are the values to be assigned. Values should typically be provided as strings, as HTML attributes can only be strings;
hostAttributes: {
string-attribute: 'Value', //string-attribute is a key, should be inside "" because javascript's keys doesn't accepts "-"
boolean-attribute: true//will fail because is not a key
tabindex: 0//this works because for javascript this is a correct key
}
...however, the standard serialize method is used to convert values to
strings, so true will serialize to an empty attribute, and false will
result in no attribute set, and so forth
As you can realize, only serialized string values, never mentioned that the keys are serialized as string as well. As I mentioned before, my English is bad and I understood that.

string interpreted incorrectly in angularjs

I have a string in golang as follows.
discount = "("+discount+"% off)"
when passed to html via angularjs it is displayed as follows
(10 %o(MISSING)ff)
Any idea why it is happening?
Thanks in advance.
Something in your HTML rendering process is passing the string through go's fmt.Sprintf or similar. Try escaping the % by doubling it:
discount = "("+discount+"%% off)"
See http://play.golang.org/p/S_GEJXSfnD for a live example.
Looks like you need to escape the string. Try to use this module: http://golang.org/pkg/html/