Problem with API requirement Ethereum API: Using variables in parameters
As an ethereum developer, you are probably familiar with the importance of using the correct names of the parameters and types of data in your requirements. However, one of the common problems occurs when working with variables that need to be transferred as parameters. In this article, we will examine why your variable {{SELLPRICE}}} Rejected API and will provide a solution.
Error “Signature for this application is not valid”
When sending the API request in a postman or other tool, you must enter the parameter name (without quotation marks) followed by the data type (eg {{{SELLPRICE} ). The exact syntax may vary depending on the end point of the API and its specific requirements. However, the common question occurs when variables are used without quotes.
problem with {{}} syntax
In JavaScript they have template literals ({…}) and interpolation of String (
$ {…}) in terms of variables. When you use
{{}}, the mail interprets
{}as the beginning of the variable name, which can lead to problems if the variable contains special characters or gaps.
For example, consider an application with such a parameter:
json
Post/API/Price HTTP/1.1
Contents type: application/JSON
{
“Price”: “{{SELLPRICE}}”,
“Symbol”: “{{}}}”
}
`
If you use {{}}
syntax to hand over the variable Sellprice
, Postman will recognize it as a literal template and ignore it in the body’s body.
Why {{}} is not valid
To solve this problem, you must escape from {}
around your variable using double curly brackets ({{{{}}} ). This will tell Postman that the following parts are output symbols for the values:
json
Post/API/Price HTTP/1.1
Contents type: application/JSON
{
“Price”: “{{SELLPRICE}}”,
“Symbol”: “{{}}}”
}
`
Solution
If you want to use your variable {{SELLPRICE}} In the application, follow the following steps:
- Escape
{}
around your variable using double curly strokes ({{…}}
).
- Keep the rest of the syntax intact.
- In your body, Postman Requirements replace
{}}
using{{{}}}>
.
Here is an updated example:
`json
Post/API/Price HTTP/1.1
Contents type: application/JSON
{
“Price”: “{{SELLPRICE}}”,
“Symbol”: “{{}}}”
}
`
tips and variations
- If you are using a template engine (such as handlebars or mustache), you will need to use
{{variable_name}
syntax instead of
}.
- In some cases, it may be necessary to use individual offers (‘
) around the variable name if it contains special characters. For example::
json
Post/API/Price HTTP/1.1
Contents type: application/JSON
{
“Price”: “‘{{{SELLPRICE}}’ ”,
“Symbol”: “‘{{}}}'” “
}
`
According to these steps, you should be able to successfully use your variable {{SELLPRICE}} in the API requirements.
Conclusion
The use of variables with special characters or spaces may lead to errors when sending applications in the postman. By leaking {}
around your variable using double curly pawnshots ({{{{}}}>
), you can ensure that the postman will correctly interpret and give your values as needed.