Scheduling a downlink with HTTP - Solved

Hi all. I used curl to schedule a downlink to my MKR WAN 1300 with no problems. Now what I would like to do is provide a means of scheduling a downlink by having a button say on a page which would be part of the application. (The idea is that occasionally a command may need to be sent to the endpoint). I have tried using an XMHLHttpRequest but get a CORS error as noted in various posts elsewhere, so that is not an option, I believe.
I tried looking at running curl from a php file, but can’t seem to get anywhere. I tried:

<?php
curlPost('https://integrations.thethingsnetwork.org/ttn-eu/api/v2/down/mkrwan1300a8610a3237397a01/sendvalvestatus?key=ttn-account-v2.lYA16-TFHQZgyuRnS7IOzqxxxxxxxxxxxxxxxx', [
    'dev_id' => 'a8xxxxxxxxxxxx1',
    'payload_raw' => 'AA==',
	
]);


function curlPost($url, $data) {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $response = curl_exec($ch);
    $error = curl_error($ch);
    curl_close($ch);
    if ($error !== '') {
        throw new \Exception($error);
    }

    return $response;
}
?>

(What am I doing wrong here?)
Or should I be using mqtt or node-red as this is more in the ‘spirit’ of TTN ?
regards
Russell

How did you do this - because if that worked, it could be called by your button - it would be useful to know what sort of application the button would be on.

Hi , thanks for reply. All I did was:

curl -v -X POST --data "{\"dev_id\":\"a86xxxxxxxxxx\",\"payload_raw\":\"Ag==\"}" https://integrations.thethingsnetwork.org/ttn-eu/api/v2/down/mkrwan1300a8610a3237397a01/sendvalvestatus?key=ttn-account-v2.lYA16-TFHQZgyuRnS7xxxxxxxxxxxxxx

Yes, I agree it should as ‘simply’ then be able to be called by a button on an html page.
At the moment, I’m just trying to enable the simplest means of causing this curl command to execute without the command line so that a user can action it from an application - for now just a form button.

Further: I ran this:

<?php


 echo('hello');

 $url = 'https://integrations.thethingsnetwork.org/ttn-eu/api/v2/down/mkrwan1300a8610a3237xxxxxx/sendvalvestatus?key=ttn-account-v2.lYA16-TFHQZgyuRnS7IOzqYujpj8xxxxxxxxxxxxx';
    $ch = curl_init($url);  
     // Setup request to send json via POST
    $data = array(
        'payload_raw' => 'AQ=='
    );
    $payload = json_encode(array("user" => $data));

    // Attach encoded JSON string to the POST fields
    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

    // Set the content type to application/json
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));

    // Return response instead of outputting
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Execute the POST request
    $result = curl_exec($ch);

 
    $output=curl_exec($ch);
    $info = curl_getinfo($ch);
    echo "<pre>";   
    print_r($info);
    echo "</pre>";    
     // Close cURL resource
    curl_close($ch);

 
?>

And obtain this:

hello
Array
(
    [url] => https://integrations.thethingsnetwork.org/ttn-eu/api/v2/down/mkrwan1300a8610a3237xxxxx/sendvalvestatus?key=ttn-account-v2.lYA16-TFHQZgyuRnS7IOzqYujpxxxxxxxxxxxxx
    [content_type] => text/plain; charset=utf-8
    [http_code] => 400
    [header_size] => 171
    [request_size] => 279
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.203
    [namelookup_time] => 1.0E-6
    [connect_time] => 1.0E-6
    [pretransfer_time] => 1.0E-6
    [size_upload] => 31
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 152
    [download_content_length] => 0
    [upload_content_length] => 31
    [starttransfer_time] => 0.203
    [redirect_time] => 0
    [redirect_url] => 
    [primary_ip] => 13.69.184.129
    [certinfo] => Array
        (
        )

    [primary_port] => 443
    [local_ip] => 10.0.0.109
    [local_port] => 53197
)

Ok - Solved. I forgot to add the dev_id in the json payload.
regards