How to POST with piston?


#1

1) Give a description of the problem
I’m having issues of understanding how to post. I have a instructions from API documentation and it says:

Examples

Request example using Curl

curl --request POST
–url https://admin.right.xx/api/integration/openpermissions
–header ‘Right-Api-Key: d217d336-550g-4dd3-b834-b7deb95b7607’
–header ‘content-type: application/vdn.right.v1+json’
–data ‘{“right”:{“id”:“66c1b208-7b31-4747-a331-fc9753634104”},“id”: “ext-1”}’

Full request data sent (example)

POST /api/integration/openpermissions HTTP/1.1
Host: admin.right.xx
Accept: application/vdn.right.v1+json
Right-Api-Key: d217d336-550g-4dd3-b834-b7deb95b7607
{
"right": {
"id": "66c1b208-7b31-4747-a331-fc9753634104"
},

"id": "ext-1"

}

Am I able to somehow post or send curl by using webcore. I tried to create piston and chose “send web request” but I’m struggling to understand where to put and what commands. Is there anyone who would like to help me a little?

Examples are examples. There is no real API-keys if someone is freaking out. :slight_smile:


#2

With postman I managed to find right command by setting data(body) and header information. Now I’m trying to understand how to build piston with that information.
This is my piston and yeah…it is not working.

There is two headers needed and one data:
–header ‘Pindora-Api-Key: d217d336-550g-4dd3-b834-b7deb95b7607’
–header ‘content-type: application/vdn.pindora.v1+json’
–data ‘{“pindora”:{“id”:“66c1b208-7b31-4747-a331-fc9753634104”},“id”: “ext-1”}’

I added all those three as strings but first issue that I found was that header should be Pindora-Api-Key…and piston changes it Pindora_Api_Key. I guess that matters right? Same thing with content-type that changes content_type in piston.

I’m missing something obvious but can’t really figure out what it is. How do I sort headers and data so that receiving end would understand what needs to be done?


#3

Try escaping the brackets with a /, without the / webcore try to translate to an expression instead of sending as text.

something like ‘/{“pindora”:/{“id”:“66c1b208-7b31-4747-a331-fc9753634104”/},“id”: “ext-1”/}’


#4

Hi, that did not help. I’m assuming that this line:
“id”:“be2xxxxxx03a7-4xxf-xxxxxxxxxxxxxxxxxxc7ce”},“id”: “ext-1”

Should be expression right, not as value. Well that does not matter because I can’t figure out the right way to type it to a piston. And still I’m concerned about the variable names that should have -, but instead of that are using _.


#5

Also tried different style…not so sure is that even doable but at least it’s not working…


#6

In terms of WebCore, anything surround by { } will be treated as an expression and any contained functions will be evaluated. The brackets are removed in this process and will not be sent as part of the text. I’m thinking that since your curl needed brackets, that you need to send them as part of the text. The only way to tell webcore to send as text is to place the / just before the bracket. I have post request that also requires brackets in the header so i mocked up something based on what I use, give this a shot…obviously it is using your fake key so remember to replace that value…


#7

Thanks! I’m going to test that one. By the way…API instructions say that there is two headers and one data. Is it ok (and I guess I have to) to combine both headers to one header string and would it be something like this:

Pindora-Api-Key: 140a34e7-fxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx9d,content-type:application/vdn.pindora.v1+json


#8

Yep, comma separate…and I just realized that i think it needs to be a back-slash
'\{ "Pindora-Api-Key": "d217d336-550g-4dd3-b834-b7deb95b7607", "content-type" : "application/vdn.pindora.v1+json" \}'


#9

Hi,

Thanks for helping me out but I did not yet succeede.
Though something is different now. I can see that piston contacts api and usage count rises when I execute piston. It is still not doing it’s job which is unlocking door.
Hubitat log says:


Webcore log says:

And my piston at the moment looks like this:

Since usage count is rising I’m guessing that still something needs to be done especially with data and header strings. I’m so lost with all the { , \ " …do not know when to use and what.


#10

Are you putting the data variable in the send variable field and the header variable in the authorization field? It looks like you may be sending both in the send variable field which translates to the body of the request.

The formatting with the \ looks fine as is.


#11

I wasn’t. :slight_smile: I had header in both fields. I changed it like this:


Still no success.

I also tried changing pistons header string like this:

and after that I got different error:


#12

You shouldn’t need the { prior to “content-type”…
last guess, try removing the { and } from just the header variable…

Otherwise I’m not sure…400 bad message usually means a formatting issue


#13

Yep no go. I mean if I remove { from content type then the command does not go to API at all. If I remove {] from header variable same thing. When I leave {} like they are I get “Unsupported media type” error to hubitat log. Oh ■■■■…why this have to be so hard…