Homey Community Forum

"Logica" flow card with multiple headers

I’m trying to setup a flowcard “Logica” / “Logic” to perform a POST request.
But when i try to add mutiple headers:

Content-Type: application/json, X-AUTHKEY: ABCDEF
The second header is not correctly splitup

my php $_SERVER request headers are:

'PHP_FCGI_CHILDREN' => '4',
    'PWD' => '/fcgi-bin',
    'SHLVL' => '0',
    'PHP_FCGI_MAX_REQUESTS' => '200',
    '__CF_USER_TEXT_ENCODING' => '0x1F6:0x0:0x5',
    'ORIG_SCRIPT_NAME' => '/fcgi-bin/php7.2.14.fcgi',
    'ORIG_PATH_TRANSLATED' => '/A/htdocs/index.php',
    'ORIG_PATH_INFO' => '/index.php',
    'ORIG_SCRIPT_FILENAME' => '/fcgi-bin/php7.2.14.fcgi',
    'SCRIPT_NAME' => '/index.php',
    'REQUEST_URI' => '/',
    'QUERY_STRING' => '',
    'REQUEST_METHOD' => 'GET',
    'SERVER_PROTOCOL' => 'HTTP/1.1',
    'GATEWAY_INTERFACE' => 'CGI/1.1',
    'REDIRECT_URL' => '/index.php',
    'REMOTE_PORT' => '34580',
    'SCRIPT_FILENAME' => '/htdocs/index.php',
    'SERVER_ADMIN' => 'you@example.com',
    'DOCUMENT_ROOT' => '/htdocs',
    'REMOTE_ADDR' => '10.0.0.52',
    'SERVER_PORT' => '80',
    'SERVER_ADDR' => '10.0.0.59',
    'SERVER_NAME' => 'localhost.10.0.0.59.xip.io',
    'SERVER_SOFTWARE' => 'Apache',
    'SERVER_SIGNATURE' => '',
    'PATH' => '/usr/bin:/bin:/usr/sbin:/sbin',
    'HTTP_HOST' => 'localhost.10.0.0.59.xip.io',
    'HTTP_CONNECTION' => 'close',
    'HTTP_ACCEPT_ENCODING' => 'gzip,deflate',
    'HTTP_ACCEPT' => '*/*',
    **'CONTENT_TYPE' => 'application/json, X-AUTHKEY',**
    'HTTP_USER_AGENT' => 'Homey',
    'REDIRECT_STATUS' => '200',
    'REDIRECT_HANDLER' => 'php-fastcgi',
    'FCGI_ROLE' => 'RESPONDER',
    'PHP_SELF' => '/index.php',
    'REQUEST_TIME_FLOAT' => 1560624802.06124,
    'REQUEST_TIME' => 1560624802,

is it even possible to add mutiple headers?? i’ve tried a lot of thing as the sepator:
: ; ,

but all 3 won’t work.

Does anybody know how the headers syntax is? Thanks!

Each header should be on a separate line:
image
(I can add a line break using Shift-Enter in the web editor, not sure if this is possible in the mobile app)

The result:

POST / HTTP/1.1
User-Agent: Homey
Content-Type: application/json
X-Foo: bar
Accept: */*
Content-Length: 2
Accept-Encoding: gzip,deflate
Connection: close

@robertklep i’m trying to add “Shift+Enter” to paste second header on a new line, but the input field is not allowing me to add an “shift-enter”.
I’ve tried “firefox” and “chrome” on “mac os x”
Also i cannot set the cursor pointer to for example in the middle of the text. it just jumps to the last character of the whole text.

when i do a “normal” enter, or when I use a very long code (ex. X-Foo: BAAAAAAAAAAAAAAAAAAAAAAAAR)
it wil automatically go to the next line but then when i look at the server responses it get this:

‘CONTENT_TYPE’ => ‘application/json©X-AUTHKEY’,
‘HTTP_USER_AGENT’ => ‘Homey’,
‘REDIRECT_STATUS’ => ‘200’,

I use Chrome on macOS and Shift-Enter works. I also don’t have the problem that you’re describing that the cursor jumps to the last character. Are you using a Chrome extension that might be causing that?

Entering a long string until it’s shown on the next line won’t work, it needs to be a hard enter/return.

Well i think i found the issue. but BOY! those input fields are not User Friendly
All the time cursor jumps to end of the text.
I had to use the LEFT SHIFT (and i used the right shift)
Also it’s not possible to drag those tags to the right place in the text. but that’s a different issue.

For now i found the problem and fixed it with using the LEFT SHIFT :smiley:

Thanks @robertklep for pointing out the Shift method!

But i would like to see better also a json string in the headers.

Yes it could be an extension problem

Everytime i click in the textarea field in the middle i also get a javascript warning:

[Violation] Forced reflow while executing JavaScript took 300ms
[Violation] Forced reflow while executing JavaScript took 75ms
[Violation] Forced reflow while executing JavaScript took 302ms
[Violation] Forced reflow while executing JavaScript took 282ms
[Violation] Forced reflow while executing JavaScript took 305ms
[Violation] Forced reflow while executing JavaScript took 275ms
[Violation] Forced reflow while executing JavaScript took 614ms
[Violation] Forced reflow while executing JavaScript took 78ms
[Violation] Forced reflow while executing JavaScript took 298ms
[Violation] Forced reflow while executing JavaScript took 289ms
[Violation] Forced reflow while executing JavaScript took 304ms
[Violation] Forced reflow while executing JavaScript took 285ms
[Violation] Forced reflow while executing JavaScript took 306ms
[Violation] Forced reflow while executing JavaScript took 76ms

I will check guest mode without extensions enabled.

Yep conclusion of the cursor problem is an extension.
Thanks again @robertklep

Ooh no, in the “Body” field, even in guest mode, the cursor goes to the end everytime.
I looks like it’s loading everytime something from the Shadow-DOM into the contenteditable field.

I cannot edit the field anymore. i have to use the app to change text.

Also i noticed, iphone when you put " " arround a key they are a different type of quotes. these: “ and they don’t get replaced by ".

it’s not my day today. to many issues setting up one flow card xD.

Those quotes might be because of an iOS setting (“smart quotes” or something).

@robertklep, not so smart then afterall :wink:

Other problem i still have is the editability of the body field. First of all, it’s slow (like javascript is doing something every time i do an input in that field.)
Second: from the moment i put a “tag card” into the body field i cannot edit anything in the body field anymore.
So again stuck getting back to my iphone app, and add or remove text there.

I’ve tried in Chrome,Firefox,Safari. all the same problem again (disabled all extensions by entering guestmode)

What i’ve typed was this in to the body field:

{ "timestamp" : " (inserted here a Date tag)

after I added the date tag i cannot edit the whole body field anymore. Dragging and dropping tagfields is also not possible.

I will search for the “smart quotes on ios” thnx!

Tag cards don’t work properly for me either when I try to use them inside JSON data.

@robertklep i conclude this method is just unusable, it’s cumbersome and not UserFriendly

Now all my post json data has “spaces” after each tag

array (
'timestamp' => '17-06-2019 T09:24 ',
'electricity_delivered_1' => '5589.29 ',
'electricity_returned_1' => '410.88 ',
'electricity_delevered_2' => '3182.6 ',
'electricity_returned_2' => '811.99 ',
'electricity_currently_delivered' => '510 ',
'electricity_currently_returned' => '0',
'extra_device_delivered' => '0.001 ',

),

i will stop trying for now, until the flow editor is improved. Again thank you for your support. i did become wiser in the “smart quotes” on iOS though :wink:

Perhaps it’s easier to use HomeyScript?

yes i was already trying but need the OAuth scope access: homey.flow

let new_flow = await Homey.flow.updateFlow({
id: '727f1862-8b34-45e2-805a-b2b5c2cf3b6e',
flow: [ { uri: 'homey:manager:logic',
id: 'http',
group: 'then',
args: 
 { method: 'post',
   url: 'http://localhost.10.0.0.59.xip.io/',
   headers: 'Content-Type: application/json\nX-AUTHKEY: [[homey:app:net.i-dev.betterlogic|X-AUTHKEY]]',
   body: '{ "timestamp":"[[homey:manager:cron|date]]T[[homey:manager:cron|time]] ", "electricity_delivered_1":"[[homey:device:45f27888-c506-4d3c-a800-1954d803e3e3|meter_power.offPeak]]","electricity_returned_1":"[[homey:device:45f27888-c506-4d3c-a800-1954d803e3e3|meter_power.producedOffPeak]]","electricity_delevered_2":"[[homey:device:45f27888-c506-4d3c-a800-1954d803e3e3|meter_power.peak]]","electricity_returned_2":"[[homey:device:45f27888-c506-4d3c-a800-1954d803e3e3|meter_power.producedPeak]]","electricity_currently_delivered":"[[homey:device:45f27888-c506-4d3c-a800-1954d803e3e3|measure_power]]","electricity_currently_returned":"0","extra_device_delivered":"[[homey:device:45f27888-c506-4d3c-a800-1954d803e3e3|measure_gas]]" }' },
delay: null,
duration: null } ]  });

returns: “Je hebt geen toegang om dit te doen” / “You have no permissions to execute this”

I meant performing the entire POST request from HomeyScript :slight_smile:

The example here shows how to make a POST request using custom headers and a JSON body.

I did like the updateFlow method :smiley: but i will program a full POST request

But still strange it’s not allowed to exec.

let scopes = await Homey.hasScopes(‘homey.flow’); returns true

Moved to developers.