I'm trying to update the secret config of vault. I try this using the node-fetch library. To avoid repetition, I've wrapped the types of requests (LIST, GET, POST). These wrappers work with the pki so it is safe to assume that it has nothing to do with the headers of the requests. In my POST wrapper, I pass a JSON Object as a parameter. Following the documentation of vault, this should look something like this:
{
'max_versions': 3,
'cas_required': false,
'delete_version_after': '0s'
}
Vault gives me an error saying invalid character 'o' looking for beginning of value. I can't find the mistake I made since I am passing a JSON Object.
Could someone point me into the right direction of what I am doing wrong?
Related
I'm trying to connect an API endpoint in Azure (api management) to a backend service. However, the set-body policy isn't recognizing my JSON body and thus isn't transforming it for the backend call.
I've tried all iterations i can think of for the "Liquid" and "None" templates. The microsoft documentation is useless as even the "liquid" template is capitalized in the doc while it NEEDS to be lowercase. Even the Deep Dive article that everyone points to is misleading and/or out of date.
i was once able to get the {{context.Request.OriginalUrl}} reference to work using liquid template, but i can't seem to get the {{body.json}} reference to work
Here's the policy i have in the section (purely to test - this has no use for what i'm doing):
<set-body template="liquid">
Calling User Agent: {{context.Request.OriginalUrl}}
</set-body>
And here's an example of what i have to try to read the json body (passing through via POST):
<set-body template="liquid">{{body}}</set-body>
I've tried several iterations and inputs like below:
<set-body template="liquid">{{body.json}}</set-body>
while passing through a body like this:
{"json":"this is an example body"}
No matter what I do, this is what I see in the trace after testing the call:
set-body (0.069 ms)
{
"input": null,
"output": ""
}
i'm obviously open to using the "none" template, but i run into the same problems. The documentation is wrong - if i copy/paste the example:
<set-body>#(context.Body.As<String>())</set-body>
I get errors like:
One or more fields contain incorrect values:
Error in element 'set-body' on line 32, column 10: 'IProxyRequestContext' does not contain a definition for 'Body' and no extension method 'Body' accepting a first argument of type 'IProxyRequestContext' could be found (are you missing a using directive or an assembly reference?)
and when i do get it to not error, it returns the same "output":"" output.
For being able to access the body as an object in the liquid template, you will have to set the Content-Type header to application/json as mentioned in the docs.
If your requests are already sending this header, then it should work without setting it too.
A policy like this in the inbound section will guarantee it works as expected
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
<set-body template="liquid">{{body.json}}"}</set-body>
As for accessing it via the context variable, you have to access it as context.Request.Body.As<string>() as mentioned in the docs, so something like this
<set-body>#(context.Request.Body.As<string>())</set-body>
The official reference for set-body doesn't seem to have the problems you've mentioned.
Was there any other doc you are referring to? If its on learn.microsoft.com, you could open an issue at the end of each doc.
In a swagger spec, I define the schema of the object that is returned by a query. That's great for GETs but if I have a POST endpoint, it could have that same object in it. Can I specify a json.schema for the "parameters" that are POSTed to an endpoint? That is do a $ref: #/definitions/myObject? It would suck to have to define the schema twice, once for incoming and once for outgoing.
And then is it possible to have middleware validate the payload of a post against that json.schema and reject if the payload does not comply?
It seems that all the pieces are available, so now I'm wondering if it's been pulled together or not.
Ok, seems I can't discover anything before posting in desperation. But I found it.
In the docs, surprisingly. Paramnerters. If you declare a parameter type of "body" then you can/must declare a schema type. As in json.schema. So that's part one.
Then for part two there is middleware for node in swagger-tools that validates the request and optionally the response. While it's not exactly explicit I believe that it will validate the body against the schema, so that's pretty cool. I don't know what kind of error messages it generates, hopefully something either configurable or at least intelligible.
I'm brand new to Pentaho and I'm trying to do the following workflow:
read a bunch of lines out of a DB
do some transformations
POST them to a REST web service in JSON
I've got the first two figured out using an input step and the Json Output step.
However I have two problems doing the final step:
1) I can't get the JSON formatted how I want. It insists on doing {""=[{...}]} when I just want {...}. This isn't a big deal - I can work around this since I have control over the web service and I could relax the input requirements a bit. (Note: this page http://wiki.pentaho.com/display/EAI/JSON+output gives an example for the output I want by setting no. rows in a block=1 and an empty JSON block name, but it doesn't work as advertised.)
2) This is the critical one. I can't get the data to POST as JSON. It posts as key=value, where the key is the name I specify in the HTTP Post field name (on the 'Fields' tab) and the value is the encoded JSON. I just want to post the JSON as the request body. I've tried googling on this but can't find anyone else doing it, leading me to believe that I'm just approaching this wrong. Any pointers in the right direction?
Edit: I'm comfortable scripting (in Javascript or another language) but when I tried to use XmlHttpRequest in a custom javascript snippet I got an error that XmlHttpRequest is not defined.
Thanks!
This was trivial...just needed to use the REST Client (http://wiki.pentaho.com/display/EAI/Rest+Client) instead of the HTTP Post task. Somehow all my googling didn't discover that, so I'll leave this answer here in case someone else has the same problem as me.
You need to parse the JSON using a Modified JavaScript step. e.g. if the Output Value from the JSON Output is called result and its contents are {"data"=[{...}]}, you should call var plainJSON = JSON.stringify(JSON.parse(result).data[0]) to get the JSON.
In the HTTP Post step, the Request entity field should be plainJSON. Also, don't forget to add a header for Content-Type as application/json (you might have to add that as a constant)
We want to start a process in JBPM6 using the rest API. We need to pass an object as a process variable.
We know how to do it JAXB and the execute call. But we want to do it with JSON and /runtime/{deploymentId}/process/{processDefId}/start
Is it possible? we try and have no success.
I am not sure whether my answer exactly addresses the question. But for someones use in future I place couple of lines here.
If you want to set a process variable when starting a process using the RESTful API, you can do it like this.
If your variable name is myVar just add the value as a URL parameter by appending the phrase "map_" to the parameter name. It means the parameter name should now be map_myVar. For an example see below request.
http://<host>:<port>/jbpm-console/rest/runtime/{deploymentId}/process/{processDefId}/start?map_myVar=myValue
You can confirm whether the value is set by writing below code in a script task.
Object var = kcontext.getVariable("myVar");
System.out.println("myVar : " + var);
See the 17.1.1.3. Map query parameters section of JBPM6 documentation.
After talking to the dev that is responsible for the REST API. I was able to confirm how it works.
The
/runtime/{deploymentId}/process/{processDefId}/start
Is a POST request where all the contents in the payload are ignored. The variables are written as key=value in the GET string.
With deployment id: com.web:work:1.0
With processDefId: work.worload
2 variables: var1 and var2
For example:
/runtime/com.web:work:1.0/process/work.worload/start?var1=a&var2=b
I'm still after trying to understand how to define objects with the remote API.
Meanwhile, I also confirmed that it is impossible to define objects using this way. The only way to define objects is only by using the JaxB. This uses the "/execute" path
I'm using a Sinatra app to receive server requests and I want to dissect them in a separate class I call "request", but when I pass the request object the body gets dropped. Trying to read the request.body in the main class works but trying to read it in the new class generates a JSONparser octet error.
In the main Sinatra file, this test call generates the correct response:
puts JSON.parse request.body.read
after, I pass the request to the Request Class with the code below.
req=Request.new(request)
But in the Request class initialization def, the same "puts" code above generates the error:
JSON::ParserError - A JSON text must at least contain two octets!:
Both files include the JSON requirement.
A work around is fairly simple but I would prefer the more elegant solution if I could figure out why it is not working as I expect. Any thoughts are appreciated.
from my tests
the Request.new constructor doesn't seem to clone from Request object
request.clone works proper
you need to do the thorough object inspection if you need anything extreme