nfty API call #1

Closed
opened 2026-06-02 05:47:51 +00:00 by schauausgmbh · 1 comment
Owner

Calling API with bearer token for authentication:

file_get_contents('https://ntfy.example.com/mysecrets', false, stream_context_create([
    'http' => [
        'method' => 'POST', // PUT also works
        'header' =>
            'Content-Type: text/plain\r\n' .
            'Authorization: Bearer tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2',
        'content' => 'Look ma, with auth'
    ]
]));

Calling API with username and password:

username   = "testuser"
password   = "fakepassword"
authHeader = "Basic " + base64(username + ":" + password) // -> Basic dGVzdHVzZXI6ZmFrZXBhc3N3b3Jk

echo "Basic $(echo -n 'testuser:fakepassword' | base64)"

file_get_contents('https://ntfy.example.com/mysecrets', false, stream_context_create([
    'http' => [
        'method' => 'POST', // PUT also works
        'header' =>
            'Content-Type: text/plain\r\n' .
            'Authorization: Basic dGVzdHVzZXI6ZmFrZXBhc3N3b3Jk',
        'content' => 'Look ma, with auth'
    ]
]));
Calling API with bearer token for authentication: ``` file_get_contents('https://ntfy.example.com/mysecrets', false, stream_context_create([ 'http' => [ 'method' => 'POST', // PUT also works 'header' => 'Content-Type: text/plain\r\n' . 'Authorization: Bearer tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2', 'content' => 'Look ma, with auth' ] ])); ``` Calling API with username and password: ``` username = "testuser" password = "fakepassword" authHeader = "Basic " + base64(username + ":" + password) // -> Basic dGVzdHVzZXI6ZmFrZXBhc3N3b3Jk ``` `echo "Basic $(echo -n 'testuser:fakepassword' | base64)"` ``` file_get_contents('https://ntfy.example.com/mysecrets', false, stream_context_create([ 'http' => [ 'method' => 'POST', // PUT also works 'header' => 'Content-Type: text/plain\r\n' . 'Authorization: Basic dGVzdHVzZXI6ZmFrZXBhc3N3b3Jk', 'content' => 'Look ma, with auth' ] ])); ```
Author
Owner

API calls are working properly

API calls are working properly
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: VE-Tools/VE.Direct-notify#1