The Password Pusher JSON API is a RESTful API that allows developers to interact with the Password Pusher service programmatically. The API provides a simple and intuitive way to manage, create and expire pushes making it easy to integrate with your existing applications and workflows.

The JSON API is available on pwpush.com, oss.pwpush.com and in all self-hosted versions of the application.

Run in Postman

API Endpoints

The main endpoint for JSON requests is:

  • /p.json: manages text based pushes

Note: Previous endpoints /f.json and /r.json still work but have been merged into the /p.json endpoint for simplicity. Please use /p.json for all new API calls going forward.

API Parameters

The Password Pusher JSON API uses standard HTTP parameters, such as Authorization: Bearer <token> headers and query parameters, to pass data between the client and server.

API Responses

The Password Pusher JSON API returns data in JSON format, with each response containing a status field indicating the success or failure of the request.

Self-Hosted

If you are running your own private instance of Password Pusher, these API calls are available on your instance too.

Just point these calls to your own instance. by changing

https://pwpush.com

to where you host your private instance such as

https://pwpush.mycompany.org

Getting Started

To get started with the Password Pusher JSON API, simply visit the API documentation at https://pwpush.com/api. From there, you can explore the available endpoints, methods, and parameters, and start building your own applications using the Password Pusher JSON API.

Premium & Pro Users

To create a push using your API token, create and/or retrieve your API token from here and then you can make requests such as:

curl -X POST
    -H "Authorization: Bearer <YOUR-API-TOKEN>"
    -H "Accept: application/json"
    -F "password[payload]=my_secure_payload"
    -F "password[note]=For New Employee ID 12345" https://pwpush.com/p.json

Note: For Premium & Pro accounts, pushes created with the JSON API will also contain the branding configured for your account.

Pro Users: Push creation will respond with your custom domains (if configured):

curl -X POST
    -H "Authorization: Bearer <YOUR-API-TOKEN>"
    -H "Accept: application/json"
    -F "password[payload]=my_secure_payload"
    -F "password[note]=For New Employee ID 12345" https://pwpush.com/p.json

will return:

{
   "account_id":1,
   "expire_after_duration":8,
   "expire_after_views":5,
   "url_token":"wbjm73kig9kv4gbe_q",
   ..snipped...
   "html_url":"https://pwp.mycompany.com/p/wbjm73kig9kv4gbe_q/r",
   "note":"For New Employee ID 12345"
}

Multiple Accounts

pwpush.com allows a single login to have multiple accounts. When making API calls, it’s possible to specify which account you would like to make the request against.

Tip: If you have multiple accounts, it’s suggested that you also specify an account ID in your API requests.

To do this, first get the list of accounts for for your API token:

curl https://pwpush.com/api/v1/accounts
    -H "Accept: application/json"
    -H "Authorization: Bearer YOURAPITOKEN"

which will return details for each of your accounts:

[
   {
      "id":12992, # <------ The Account ID for "MyCompany"
      "name":"MyCompany",
      "account_users":[
         {
            "id":1,
            "user_id":4
         },
         {
            "id":23098,
            "user_id":23712
         }
      ]
   },
   {
      "id":22923, # <------ The Account ID for "Law Frim"
      "name":"Law Frim",
      "account_users":[
         {
            "id":22913,
            "user_id":4
         }
      ]
   }
]

Then when making an API request, you can specify the account ID using the account_id parameter:

curl -X POST
    -H "Authorization: Bearer YOURAPITOKEN"
    -H "Accept: application/json"
    -F "password[payload]=my_secure_payload"
    -F "password[note]=JSON API created push"
    -F "account_id=22923"  <----- Specify the account ID here
    https://pwpush.com/p.json

Bundled Documentation

Password Pusher bundles the documentation for the JSON API along with the application. It includes detailed endpoint descriptions, method parameters, and response formats.

This documentation is available at pwpush.com/api or on self-hosted instances at the /api path.

Postman

The Password Pusher API v1.0 documentation is also available on Postman, a popular API development and testing platform.

Postman allows you to easily interact with and test APIs without writing any code. You can quickly explore endpoints, send requests, and view responses in a user-friendly interface. This makes it ideal for both developers and non-developers to interact with the API.

To get started with the API in Postman, click the button below to access the full documentation and test out the API endpoints.

Run in Postman

See Also

Example Code

Curl

To create an anonymous push:

curl -X POST
  --data "password[payload]=mypassword"
  https://pwpush.com/p.json

Create a push with files (requires authentication):

curl -X POST -H "X-User-Email: <email>" -H "X-User-Token: MyAPIToken"
  -F "password[payload]=my_secure_payload"
  -F "password[note]=For New Employee ID 12345"
  -F "password[files][]=@/path/to/file/file1.extension"
  -F "password[files][]=@/path/to/file/file2.extension"
  https://pwpush.com/p.json

To create a URL push:

curl -X POST https://pwpush.com/p.json
  -F 'password[kind]=url'
  -F "password[payload]=https://the0x00.dev"

To create a QR code push:

curl -i https://pwpush.com/p.json
  -F 'password[kind]=qr'
  -F "password[payload]=QR Code Content is here"

To retrieve a push:

curl -X GET https://pwpush.com/p/<ID>.json

To expire a push:

curl -X DELETE https://pwpush.com/p/<ID>.json

To get a list of your active pushes:

curl -X GET
  -H "X-User-Email: <email>"
  -H "X-User-Token: MyAPIToken"
  http://lvh.me:3000/p/active.json

To get a list of your expired pushes:

curl -X GET
  -H "X-User-Email: <email>"
  -H "X-User-Token: MyAPIToken"
  http://lvh.me:3000/p/expired.json

Note: Expiration of a push requires authentication if the push was created with password[deletable_by_viewer]=false.

C#

To create an anonymous push:

using System.Net.Http;
using System.Text.Json;

using var client = new HttpClient();
var content = new FormUrlEncodedContent(new[]
{
    new KeyValuePair<string, string>("password[payload]", "mypassword")
});

var response = await client.PostAsync("https://pwpush.com/p.json", content);
var jsonString = await response.Content.ReadAsStringAsync();
var result = JsonSerializer.Deserialize<JsonDocument>(jsonString);
Console.WriteLine($"Share this secret URL: https://pwpush.com/p/{result.RootElement.GetProperty("url_token").GetString()}");

Create a push with files (requires authentication):

using var client = new HttpClient();
using var multipartContent = new MultipartFormDataContent();

// Add text fields
multipartContent.Add(new StringContent("my_secure_payload"), "password[payload]");
multipartContent.Add(new StringContent("For New Employee ID 12345"), "password[note]");

// Add files
var file1 = File.OpenRead("/path/to/file/file1.txt");
var file2 = File.OpenRead("/path/to/file/file2.txt");
multipartContent.Add(new StreamContent(file1), "password[files][]", "file1.txt");
multipartContent.Add(new StreamContent(file2), "password[files][]", "file2.txt");

client.DefaultRequestHeaders.Add("X-User-Email", "your-email@example.com");
client.DefaultRequestHeaders.Add("X-User-Token", "MyAPIToken");

var response = await client.PostAsync("https://pwpush.com/p.json", multipartContent);

To create a URL push:

using var multipartContent = new MultipartFormDataContent();
multipartContent.Add(new StringContent("url"), "password[kind]");
multipartContent.Add(new StringContent("https://the0x00.dev"), "password[payload]");

var response = await client.PostAsync("https://pwpush.com/p.json", multipartContent);

To create a QR code push:

using var multipartContent = new MultipartFormDataContent();
multipartContent.Add(new StringContent("qr"), "password[kind]");
multipartContent.Add(new StringContent("QR Code Content is here"), "password[payload]");

var response = await client.PostAsync("https://pwpush.com/p.json", multipartContent);

To retrieve a push:

var response = await client.GetAsync($"https://pwpush.com/p/{pushId}.json");
var jsonString = await response.Content.ReadAsStringAsync();
var pushData = JsonSerializer.Deserialize<JsonDocument>(jsonString);

To expire a push:

var response = await client.DeleteAsync($"https://pwpush.com/p/{pushId}.json");

To get a list of your active pushes:

using var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-User-Email", "your-email@example.com");
client.DefaultRequestHeaders.Add("X-User-Token", "MyAPIToken");

var response = await client.GetAsync("https://pwpush.com/p/active.json");
var jsonString = await response.Content.ReadAsStringAsync();
var activePushes = JsonSerializer.Deserialize<JsonDocument>(jsonString);

To get a list of your expired pushes:

using var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-User-Email", "your-email@example.com");
client.DefaultRequestHeaders.Add("X-User-Token", "MyAPIToken");

var response = await client.GetAsync("https://pwpush.com/p/expired.json");
var jsonString = await response.Content.ReadAsStringAsync();
var expiredPushes = JsonSerializer.Deserialize<JsonDocument>(jsonString);

Note: These examples use HttpClient from System.Net.Http and System.Text.Json for JSON handling. For production use, consider implementing proper error handling and using a shared HttpClient instance.

C++

To create an anonymous push:

#include <cpr/cpr.h>
#include <nlohmann/json.hpp>

using json = nlohmann::json;

int main() {
    auto response = cpr::Post(
        cpr::Url{"https://pwpush.com/p.json"},
        cpr::Payloadpassword[payload]
    );

    auto data = json::parse(response.text);
    std::cout << "Share this secret URL: https://pwpush.com/p/"
              << data["url_token"] << std::endl;
}

Create a push with files (requires authentication):

#include <cpr/cpr.h>
#include <filesystem>

namespace fs = std::filesystem;

auto response = cpr::Post(
    cpr::Url{"https://pwpush.com/p.json"},
    cpr::Header{
        {"X-User-Email", "your-email@example.com"},
        {"X-User-Token", "MyAPIToken"}
    },
    cpr::Multipart{
        {"password[payload]", "my_secure_payload"},
        {"password[note]", "For New Employee ID 12345"},
        {"password[files][]", cpr::File{"file1.txt"}},
        {"password[files][]", cpr::File{"file2.txt"}}
    }
);

To create a URL push:

auto response = cpr::Post(
    cpr::Url{"https://pwpush.com/p.json"},
    cpr::Multipart{
        {"password[kind]", "url"},
        {"password[payload]", "https://the0x00.dev"}
    }
);

To create a QR code push:

auto response = cpr::Post(
    cpr::Url{"https://pwpush.com/p.json"},
    cpr::Multipart{
        {"password[kind]", "qr"},
        {"password[payload]", "QR Code Content is here"}
    }
);

To retrieve a push:

auto response = cpr::Get(
    cpr::Url{fmt::format("https://pwpush.com/p/{}.json", pushId)}
);
auto pushData = json::parse(response.text);

To expire a push:

auto response = cpr::Delete(
    cpr::Url{fmt::format("https://pwpush.com/p/{}.json", pushId)}
);

To get a list of your active pushes:

auto response = cpr::Get(
    cpr::Url{"https://pwpush.com/p/active.json"},
    cpr::Header{
        {"X-User-Email", "your-email@example.com"},
        {"X-User-Token", "MyAPIToken"}
    }
);
auto activePushes = json::parse(response.text);

To get a list of your expired pushes:

auto response = cpr::Get(
    cpr::Url{"https://pwpush.com/p/expired.json"},
    cpr::Header{
        {"X-User-Email", "your-email@example.com"},
        {"X-User-Token", "MyAPIToken"}
    }
);
auto expiredPushes = json::parse(response.text);

Note: These examples use the CPR library for HTTP requests and nlohmann/json for JSON parsing. Install them using your package manager or build from source. For production use, consider adding proper error handling and using a shared client instance.

Go

To create an anonymous push:

package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
    "net/url"
)

func main() {
    data := url.Values{}
    data.Set("password[payload]", "mypassword")

    resp, err := http.PostForm("https://pwpush.com/p.json", data)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    var result map[string]interface{}
    if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
        panic(err)
    }

    fmt.Printf("Share this secret URL: https://pwpush.com/p/%s\n", result["url_token"])
}

Create a push with files (requires authentication):

package main

import (
    "bytes"
    "io"
    "mime/multipart"
    "net/http"
    "os"
)

func main() {
    body := &bytes.Buffer{}
    writer := multipart.NewWriter(body)

    // Add text fields
    writer.WriteField("password[payload]", "my_secure_payload")
    writer.WriteField("password[note]", "For New Employee ID 12345")

    // Add files
    files := []string{"/path/to/file/file1.txt", "/path/to/file/file2.txt"}
    for _, filepath := range files {
        file, err := os.Open(filepath)
        if err != nil {
            panic(err)
        }
        defer file.Close()

        part, err := writer.CreateFormFile("password[files][]", filepath)
        if err != nil {
            panic(err)
        }
        io.Copy(part, file)
    }
    writer.Close()

    req, err := http.NewRequest("POST", "https://pwpush.com/p.json", body)
    if err != nil {
        panic(err)
    }

    req.Header.Set("Content-Type", writer.FormDataContentType())
    req.Header.Set("X-User-Email", "your-email@example.com")
    req.Header.Set("X-User-Token", "MyAPIToken")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()
}

To create a URL push:

data := url.Values{}
data.Set("password[kind]", "url")
data.Set("password[payload]", "https://the0x00.dev")

resp, err := http.PostForm("https://pwpush.com/p.json", data)

To create a QR code push:

data := url.Values{}
data.Set("password[kind]", "qr")
data.Set("password[payload]", "QR Code Content is here")

resp, err := http.PostForm("https://pwpush.com/p.json", data)

To retrieve a push:

resp, err := http.Get(fmt.Sprintf("https://pwpush.com/p/%s.json", pushID))
if err != nil {
    panic(err)
}
defer resp.Body.Close()

var pushData map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&pushData); err != nil {
    panic(err)
}

To expire a push:

req, err := http.NewRequest("DELETE", fmt.Sprintf("https://pwpush.com/p/%s.json", pushID), nil)
if err != nil {
    panic(err)
}

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
    panic(err)
}
defer resp.Body.Close()

To get a list of your active pushes:

req, err := http.NewRequest("GET", "https://pwpush.com/p/active.json", nil)
if err != nil {
    panic(err)
}

req.Header.Set("X-User-Email", "your-email@example.com")
req.Header.Set("X-User-Token", "MyAPIToken")

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
    panic(err)
}
defer resp.Body.Close()

var activePushes []map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&activePushes); err != nil {
    panic(err)
}

To get a list of your expired pushes:

req, err := http.NewRequest("GET", "https://pwpush.com/p/expired.json", nil)
if err != nil {
    panic(err)
}

req.Header.Set("X-User-Email", "your-email@example.com")
req.Header.Set("X-User-Token", "MyAPIToken")

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
    panic(err)
}
defer resp.Body.Close()

var expiredPushes []map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&expiredPushes); err != nil {
    panic(err)
}

Note: All examples use Go’s standard net/http package. For more advanced usage, consider using libraries like resty or go-retryablehttp.

Java

To create an anonymous push:

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

HttpClient client = HttpClient.newHttpClient();
String payload = URLEncoder.encode("mypassword", StandardCharsets.UTF_8);
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://pwpush.com/p.json"))
    .header("Content-Type", "application/x-www-form-urlencoded")
    .POST(HttpRequest.BodyPublishers.ofString("password[payload]=" + payload))
    .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Share this secret URL: https://pwpush.com/p/" +
    new JSONObject(response.body()).getString("url_token"));

Create a push with files (requires authentication):

import java.nio.file.Path;

String boundary = "---boundary---" + System.currentTimeMillis();
Path file1 = Path.of("/path/to/file/file1.txt");
Path file2 = Path.of("/path/to/file/file2.txt");

MultipartBodyPublisher publisher = new MultipartBodyPublisher()
    .addPart("password[payload]", "my_secure_payload")
    .addPart("password[note]", "For New Employee ID 12345")
    .addPart("password[files][]", file1)
    .addPart("password[files][]", file2);

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://pwpush.com/p.json"))
    .header("X-User-Email", "your-email@example.com")
    .header("X-User-Token", "MyAPIToken")
    .header("Content-Type", "multipart/form-data; boundary=" + boundary)
    .POST(publisher.build())
    .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

To create a URL push:

MultipartBodyPublisher publisher = new MultipartBodyPublisher()
    .addPart("password[kind]", "url")
    .addPart("password[payload]", "https://the0x00.dev");

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://pwpush.com/p.json"))
    .header("Content-Type", "multipart/form-data; boundary=" + boundary)
    .POST(publisher.build())
    .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

To create a QR code push:

MultipartBodyPublisher publisher = new MultipartBodyPublisher()
    .addPart("password[kind]", "qr")
    .addPart("password[payload]", "QR Code Content is here");

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://pwpush.com/p.json"))
    .header("Content-Type", "multipart/form-data; boundary=" + boundary)
    .POST(publisher.build())
    .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

To retrieve a push:

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://pwpush.com/p/" + pushId + ".json"))
    .GET()
    .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
JSONObject pushData = new JSONObject(response.body());

To expire a push:

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://pwpush.com/p/" + pushId + ".json"))
    .DELETE()
    .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

To get a list of your active pushes:

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://pwpush.com/p/active.json"))
    .header("X-User-Email", "your-email@example.com")
    .header("X-User-Token", "MyAPIToken")
    .GET()
    .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
JSONArray activePushes = new JSONArray(response.body());

To get a list of your expired pushes:

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://pwpush.com/p/expired.json"))
    .header("X-User-Email", "your-email@example.com")
    .header("X-User-Token", "MyAPIToken")
    .GET()
    .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
JSONArray expiredPushes = new JSONArray(response.body());

Note: These examples use Java 11’s HttpClient and require a JSON library (like org.json) for JSON parsing. For multipart file uploads, you’ll need a helper class to handle the multipart form data construction.

JavaScript

To create an anonymous push:

fetch('https://pwpush.com/p.json', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
  },
  body: new URLSearchParams({
    'password[payload]': 'mypassword'
  })
})
.then(response => response.json())
.then(data => console.log(`Share this secret URL: https://pwpush.com/p/${data.url_token}`));

Create a push with files (requires authentication):

const formData = new FormData();
formData.append('password[payload]', 'my_secure_payload');
formData.append('password[note]', 'For New Employee ID 12345');
formData.append('password[files][]', file1);  // file1 from input element or File API
formData.append('password[files][]', file2);  // file2 from input element or File API

fetch('https://pwpush.com/p.json', {
  method: 'POST',
  headers: {
    'X-User-Email': 'your-email@example.com',
    'X-User-Token': 'MyAPIToken'
  },
  body: formData
})
.then(response => response.json());

To create a URL push:

const formData = new FormData();
formData.append('password[kind]', 'url');
formData.append('password[payload]', 'https://the0x00.dev');

fetch('https://pwpush.com/p.json', {
  method: 'POST',
  body: formData
})
.then(response => response.json());

To create a QR code push:

const formData = new FormData();
formData.append('password[kind]', 'qr');
formData.append('password[payload]', 'QR Code Content is here');

fetch('https://pwpush.com/p.json', {
  method: 'POST',
  body: formData
})
.then(response => response.json());

To retrieve a push:

fetch(`https://pwpush.com/p/${pushId}.json`)
  .then(response => response.json())
  .then(pushData => console.log(pushData));

To expire a push:

fetch(`https://pwpush.com/p/${pushId}.json`, {
  method: 'DELETE'
})
.then(response => response.json());

To get a list of your active pushes:

fetch('https://pwpush.com/p/active.json', {
  headers: {
    'X-User-Email': 'your-email@example.com',
    'X-User-Token': 'MyAPIToken'
  }
})
.then(response => response.json())
.then(activePushes => console.log(activePushes));

To get a list of your expired pushes:

fetch('https://pwpush.com/p/expired.json', {
  headers: {
    'X-User-Email': 'your-email@example.com',
    'X-User-Token': 'MyAPIToken'
  }
})
.then(response => response.json())
.then(expiredPushes => console.log(expiredPushes));

Note: These examples use the Fetch API which is available in all modern browsers and Node.js (v18+). For older environments, consider using libraries like axios or adding a fetch polyfill.

Kotlin

To create an anonymous push:

suspend fun createPush(payload: String) {
    val client = HttpClient(CIO) {
        install(ContentNegotiation) {
            json()
        }
    }

    val response = client.post("https://pwpush.com/p.json") {
        setBody(FormDataContent(Parameters.build {
            append("password[payload]", payload)
        }))
    }

    val data = response.body<JsonObject>()
    println("Share this secret URL: https://pwpush.com/p/${data["url_token"]?.jsonPrimitive?.content}")

    client.close()
}

Create a push with files (requires authentication):

suspend fun createAuthenticatedPush(
    payload: String,
    note: String,
    files: List<File>,
    email: String,
    apiToken: String
) {
    val client = HttpClient(CIO)

    val response = client.post("https://pwpush.com/p.json") {
        headers {
            append("X-User-Email", email)
            append("X-User-Token", apiToken)
        }

        setBody(MultiPartFormDataContent(
            formData {
                append("password[payload]", payload)
                append("password[note]", note)
                files.forEach { file ->
                    append("password[files][]", file.readBytes(), Headers.build {
                        append(HttpHeaders.ContentDisposition, "filename=${file.name}")
                    })
                }
            }
        ))
    }

    client.close()
}

To create a URL push:

suspend fun createUrlPush(url: String) {
    val client = HttpClient(CIO)

    val response = client.post("https://pwpush.com/p.json") {
        setBody(MultiPartFormDataContent(
            formData {
                append("password[kind]", "url")
                append("password[payload]", url)
            }
        ))
    }

    client.close()
}

To create a QR code push:

suspend fun createQRPush(content: String) {
    val client = HttpClient(CIO)

    val response = client.post("https://pwpush.com/p.json") {
        setBody(MultiPartFormDataContent(
            formData {
                append("password[kind]", "qr")
                append("password[payload]", content)
            }
        ))
    }

    client.close()
}

To retrieve a push:

suspend fun retrievePush(pushId: String): JsonObject {
    val client = HttpClient(CIO) {
        install(ContentNegotiation) {
            json()
        }
    }

    val response = client.get("https://pwpush.com/p/$pushId.json")
    val pushData = response.body<JsonObject>()

    client.close()
    return pushData
}

To expire a push:

suspend fun expirePush(pushId: String) {
    val client = HttpClient(CIO)

    client.delete("https://pwpush.com/p/$pushId.json")

    client.close()
}

To get a list of your active pushes:

suspend fun getActivePushes(email: String, apiToken: String): List<JsonObject> {
    val client = HttpClient(CIO) {
        install(ContentNegotiation) {
            json()
        }
    }

    val response = client.get("https://pwpush.com/p/active.json") {
        headers {
            append("X-User-Email", email)
            append("X-User-Token", apiToken)
        }
    }

    val activePushes = response.body<List<JsonObject>>()

    client.close()
    return activePushes
}

To get a list of your expired pushes:

suspend fun getExpiredPushes(email: String, apiToken: String): List<JsonObject> {
    val client = HttpClient(CIO) {
        install(ContentNegotiation) {
            json()
        }
    }

    val response = client.get("https://pwpush.com/p/expired.json") {
        headers {
            append("X-User-Email", email)
            append("X-User-Token", apiToken)
        }
    }

    val expiredPushes = response.body<List<JsonObject>>()

    client.close()
    return expiredPushes
}

Note: These examples use Kotlin Coroutines and the Ktor client library. Add these dependencies to your build.gradle.kts:

dependencies {
    implementation("io.ktor:ktor-client-core:2.3.7")
    implementation("io.ktor:ktor-client-cio:2.3.7")
    implementation("io.ktor:ktor-client-content-negotiation:2.3.7")
    implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.7")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
}

Usage Examples:

suspend fun main() {
    // Create an anonymous push
    createPush("my secret password")

    // Create an authenticated push with files
    createAuthenticatedPush(
        payload = "secure content",
        note = "For employee onboarding",
        files = listOf(File("document1.pdf"), File("document2.pdf")),
        email = "your-email@example.com",
        apiToken = "your-api-token"
    )

    // Create a URL push
    createUrlPush("https://example.com")

    // Create a QR code push
    createQRPush("QR Code content here")

    // Get active pushes
    val activePushes = getActivePushes(
        email = "your-email@example.com",
        apiToken = "your-api-token"
    )
}

Perl

To create an anonymous push:

use strict;
use warnings;
use LWP::UserAgent;
use JSON;
use URI::Escape;

my $ua = LWP::UserAgent->new;
my $response = $ua->post('https://pwpush.com/p.json',
    Content => 'password[payload]=' . uri_escape('mypassword')
);

if ($response->is_success) {
    my $data = decode_json($response->content);
    print "Share this secret URL: https://pwpush.com/p/" . $data->{url_token} . "\n";
} else {
    die $response->status_line;
}

Create a push with files (requires authentication):

use HTTP::Request::Common qw(POST);
use File::Basename;

my $ua = LWP::UserAgent->new;
my $request = POST 'https://pwpush.com/p.json',
    Content_Type => 'form-data',
    Headers => [
        'X-User-Email' => 'your-email@example.com',
        'X-User-Token' => 'MyAPIToken'
    ],
    Content => [
        'password[payload]' => 'my_secure_payload',
        'password[note]' => 'For New Employee ID 12345',
        'password[files][]' => [ '/path/to/file/file1.txt' ],
        'password[files][]' => [ '/path/to/file/file2.txt' ]
    ];

my $response = $ua->request($request);

To create a URL push:

my $request = POST 'https://pwpush.com/p.json',
    Content_Type => 'form-data',
    Content => [
        'password[kind]' => 'url',
        'password[payload]' => 'https://the0x00.dev'
    ];

my $response = $ua->request($request);

To create a QR code push:

my $request = POST 'https://pwpush.com/p.json',
    Content_Type => 'form-data',
    Content => [
        'password[kind]' => 'qr',
        'password[payload]' => 'QR Code Content is here'
    ];

my $response = $ua->request($request);

To retrieve a push:

my $response = $ua->get("https://pwpush.com/p/$push_id.json");
if ($response->is_success) {
    my $push_data = decode_json($response->content);
    # Handle push data
}

To expire a push:

my $response = $ua->delete("https://pwpush.com/p/$push_id.json");

To get a list of your active pushes:

my $request = HTTP::Request->new(GET => 'https://pwpush.com/p/active.json');
$request->header('X-User-Email' => 'your-email@example.com');
$request->header('X-User-Token' => 'MyAPIToken');

my $response = $ua->request($request);
if ($response->is_success) {
    my $active_pushes = decode_json($response->content);
    # Handle active pushes
}

To get a list of your expired pushes:

my $request = HTTP::Request->new(GET => 'https://pwpush.com/p/expired.json');
$request->header('X-User-Email' => 'your-email@example.com');
$request->header('X-User-Token' => 'MyAPIToken');

my $response = $ua->request($request);
if ($response->is_success) {
    my $expired_pushes = decode_json($response->content);
    # Handle expired pushes
}

Note: These examples use the LWP::UserAgent module for HTTP requests and JSON for JSON handling. Install them using CPAN: cpan LWP::UserAgent JSON URI::Escape. For production use, consider adding proper error handling and using a shared user agent instance.

PHP

To create an anonymous push:

$ch = curl_init('https://pwpush.com/p.json');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
    'password[payload]' => 'mypassword'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$data = json_decode($response, true);
echo "Share this secret URL: https://pwpush.com/p/" . $data['url_token'];
curl_close($ch);

Create a push with files (requires authentication):

$ch = curl_init('https://pwpush.com/p.json');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'X-User-Email: your-email@example.com',
    'X-User-Token: MyAPIToken'
]);

$postFields = [
    'password[payload]' => 'my_secure_payload',
    'password[note]' => 'For New Employee ID 12345',
    'password[files][]' => new CURLFile('/path/to/file/file1.txt'),
    'password[files][]' => new CURLFile('/path/to/file/file2.txt')
];

curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$data = json_decode($response, true);
curl_close($ch);

To create a URL push:

$ch = curl_init('https://pwpush.com/p.json');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
    'password[kind]' => 'url',
    'password[payload]' => 'https://the0x00.dev'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$data = json_decode($response, true);
curl_close($ch);

To create a QR code push:

$ch = curl_init('https://pwpush.com/p.json');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
    'password[kind]' => 'qr',
    'password[payload]' => 'QR Code Content is here'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$data = json_decode($response, true);
curl_close($ch);

To retrieve a push:

$ch = curl_init("https://pwpush.com/p/{$pushId}.json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$pushData = json_decode($response, true);
curl_close($ch);

To expire a push:

$ch = curl_init("https://pwpush.com/p/{$pushId}.json");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
curl_close($ch);

To get a list of your active pushes:

$ch = curl_init('https://pwpush.com/p/active.json');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'X-User-Email: your-email@example.com',
    'X-User-Token: MyAPIToken'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$activePushes = json_decode($response, true);
curl_close($ch);

To get a list of your expired pushes:

$ch = curl_init('https://pwpush.com/p/expired.json');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'X-User-Email: your-email@example.com',
    'X-User-Token: MyAPIToken'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$expiredPushes = json_decode($response, true);
curl_close($ch);

Note: These examples use PHP’s cURL extension. Make sure it’s installed and enabled in your PHP environment. For production use, consider adding proper error handling and using a more modern HTTP client like Guzzle.

PowerShell

To create an anonymous push:

$body = @{
    'password[payload]' = 'mypassword'
}

$response = Invoke-RestMethod -Uri 'https://pwpush.com/p.json' -Method Post -Body $body
Write-Host "Share this secret URL: https://pwpush.com/p/$($response.url_token)"

Create a push with files (requires authentication):

$headers = @{
    'X-User-Email' = 'your-email@example.com'
    'X-User-Token' = 'MyAPIToken'
}

$form = @{
    'password[payload]' = 'my_secure_payload'
    'password[note]' = 'For New Employee ID 12345'
    'password[files][]' = Get-Item -Path @(
        '/path/to/file/file1.extension',
        '/path/to/file/file2.extension'
    )
}

$response = Invoke-RestMethod -Uri 'https://pwpush.com/p.json' -Method Post -Headers $headers -Form $form

To create a URL push:

$form = @{
    'password[kind]' = 'url'
    'password[payload]' = 'https://the0x00.dev'
}

$response = Invoke-RestMethod -Uri 'https://pwpush.com/p.json' -Method Post -Form $form

To create a QR code push:

$form = @{
    'password[kind]' = 'qr'
    'password[payload]' = 'QR Code Content is here'
}

$response = Invoke-RestMethod -Uri 'https://pwpush.com/p.json' -Method Post -Form $form

To retrieve a push:

$pushId = 'YOUR-PUSH-ID'
$response = Invoke-RestMethod -Uri "https://pwpush.com/p/$pushId.json" -Method Get

To expire a push:

$pushId = 'YOUR-PUSH-ID'
$response = Invoke-RestMethod -Uri "https://pwpush.com/p/$pushId.json" -Method Delete

To get a list of your active pushes:

$headers = @{
    'X-User-Email' = 'your-email@example.com'
    'X-User-Token' = 'MyAPIToken'
}

$response = Invoke-RestMethod -Uri 'https://pwpush.com/p/active.json' -Method Get -Headers $headers

To get a list of your expired pushes:

$headers = @{
    'X-User-Email' = 'your-email@example.com'
    'X-User-Token' = 'MyAPIToken'
}

$response = Invoke-RestMethod -Uri 'https://pwpush.com/p/expired.json' -Method Get -Headers $headers

Note: These examples use PowerShell’s Invoke-RestMethod cmdlet which automatically handles JSON serialization/deserialization. For PowerShell versions earlier than 6.0, you may need to use Invoke-WebRequest instead.

Python

To create an anonymous push:

import requests

response = requests.post(
    "https://pwpush.com/p.json",
    data={"password[payload]": "mypassword"}
)
print(f"Share this secret URL: https://pwpush.com/p/${response.json()['url_token']}")

Create a push with files (requires authentication):

import requests

headers = {
    "X-User-Email": "your-email@example.com",
    "X-User-Token": "MyAPIToken"
}

files = {
    "password[payload]": (None, "my_secure_payload"),
    "password[note]": (None, "For New Employee ID 12345"),
    "password[files][]": [
        ("file1.txt", open("/path/to/file/file1.txt", "rb")),
        ("file2.txt", open("/path/to/file/file2.txt", "rb"))
    ]
}

response = requests.post(
    "https://pwpush.com/p.json",
    headers=headers,
    files=files
)

To create a URL push:

response = requests.post(
    "https://pwpush.com/p.json",
    data={
        "password[kind]": "url",
        "password[payload]": "https://the0x00.dev"
    }
)

To create a QR code push:

response = requests.post(
    "https://pwpush.com/p.json",
    data={
        "password[kind]": "qr",
        "password[payload]": "QR Code Content is here"
    }
)

To retrieve a push:

response = requests.get(f"https://pwpush.com/p/{push_id}.json")
push_data = response.json()

To expire a push:

response = requests.delete(f"https://pwpush.com/p/{push_id}.json")

To get a list of your active pushes:

headers = {
    "X-User-Email": "your-email@example.com",
    "X-User-Token": "MyAPIToken"
}

response = requests.get(
    "https://pwpush.com/p/active.json",
    headers=headers
)
active_pushes = response.json()

To get a list of your expired pushes:

headers = {
    "X-User-Email": "your-email@example.com",
    "X-User-Token": "MyAPIToken"
}

response = requests.get(
    "https://pwpush.com/p/expired.json",
    headers=headers
)
expired_pushes = response.json()

Note: All examples assume you have the requests library installed (pip install requests).

Ruby

To create an anonymous push:

require 'net/http'
require 'json'

uri = URI('https://pwpush.com/p.json')
response = Net::HTTP.post_form(uri, 'password[payload]' => 'mypassword')
data = JSON.parse(response.body)
puts "Share this secret URL: https://pwpush.com/p/#{data['url_token']}"

Create a push with files (requires authentication):

require 'net/http'
require 'uri'
require 'json'

uri = URI('https://pwpush.com/p.json')
request = Net::HTTP::Post.new(uri)
request['X-User-Email'] = 'your-email@example.com'
request['X-User-Token'] = 'MyAPIToken'

form_data = [
  ['password[payload]', 'my_secure_payload'],
  ['password[note]', 'For New Employee ID 12345'],
  ['password[files][]', File.open('/path/to/file/file1.txt')],
  ['password[files][]', File.open('/path/to/file/file2.txt')]
]

request.set_form form_data, 'multipart/form-data'
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
  http.request(request)
end

To create a URL push:

response = Net::HTTP.post_form(URI('https://pwpush.com/p.json'),
  'password[kind]' => 'url',
  'password[payload]' => 'https://the0x00.dev'
)

To create a QR code push:

response = Net::HTTP.post_form(URI('https://pwpush.com/p.json'),
  'password[kind]' => 'qr',
  'password[payload]' => 'QR Code Content is here'
)

To retrieve a push:

uri = URI("https://pwpush.com/p/#{push_id}.json")
response = Net::HTTP.get(uri)
push_data = JSON.parse(response)

To expire a push:

uri = URI("https://pwpush.com/p/#{push_id}.json")
request = Net::HTTP::Delete.new(uri)
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
  http.request(request)
end

To get a list of your active pushes:

uri = URI('https://pwpush.com/p/active.json')
request = Net::HTTP::Get.new(uri)
request['X-User-Email'] = 'your-email@example.com'
request['X-User-Token'] = 'MyAPIToken'

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
  http.request(request)
end
active_pushes = JSON.parse(response.body)

To get a list of your expired pushes:

uri = URI('https://pwpush.com/p/expired.json')
request = Net::HTTP::Get.new(uri)
request['X-User-Email'] = 'your-email@example.com'
request['X-User-Token'] = 'MyAPIToken'

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
  http.request(request)
end
expired_pushes = JSON.parse(response.body)

Note: All examples use Ruby’s standard library net/http. For a more user-friendly experience, consider using gems like httparty or faraday.

Rust

To create an anonymous push:

use reqwest;
use serde_json::Value;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();
    let params = [("password[payload]", "mypassword")];

    let response = client.post("https://pwpush.com/p.json")
        .form(&params)
        .send()
        .await?;

    let data: Value = response.json().await?;
    println!("Share this secret URL: https://pwpush.com/p/{}",
             data["url_token"].as_str().unwrap());

    Ok(())
}

Create a push with files (requires authentication):

use reqwest;
use tokio::fs::File;
use tokio_util::codec::{BytesCodec, FramedRead};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();
    let form = reqwest::multipart::Form::new()
        .text("password[payload]", "my_secure_payload")
        .text("password[note]", "For New Employee ID 12345");

    // Add files
    let file1 = File::open("/path/to/file/file1.txt").await?;
    let file2 = File::open("/path/to/file/file2.txt").await?;

    let stream1 = FramedRead::new(file1, BytesCodec::new());
    let stream2 = FramedRead::new(file2, BytesCodec::new());

    let form = form
        .part("password[files][]", reqwest::multipart::Part::stream(stream1))
        .part("password[files][]", reqwest::multipart::Part::stream(stream2));

    let response = client.post("https://pwpush.com/p.json")
        .header("X-User-Email", "your-email@example.com")
        .header("X-User-Token", "MyAPIToken")
        .multipart(form)
        .send()
        .await?;

    Ok(())
}

To create a URL push:

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();
    let form = reqwest::multipart::Form::new()
        .text("password[kind]", "url")
        .text("password[payload]", "https://the0x00.dev");

    let response = client.post("https://pwpush.com/p.json")
        .multipart(form)
        .send()
        .await?;

    Ok(())
}

To create a QR code push:

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();
    let form = reqwest::multipart::Form::new()
        .text("password[kind]", "qr")
        .text("password[payload]", "QR Code Content is here");

    let response = client.post("https://pwpush.com/p.json")
        .multipart(form)
        .send()
        .await?;

    Ok(())
}

To retrieve a push:

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();
    let response = client.get(&format!("https://pwpush.com/p/{}.json", push_id))
        .send()
        .await?;

    let push_data: Value = response.json().await?;
    println!("{:#?}", push_data);

    Ok(())
}

To expire a push:

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();
    let response = client.delete(&format!("https://pwpush.com/p/{}.json", push_id))
        .send()
        .await?;

    Ok(())
}

To get a list of your active pushes:

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();
    let response = client.get("https://pwpush.com/p/active.json")
        .header("X-User-Email", "your-email@example.com")
        .header("X-User-Token", "MyAPIToken")
        .send()
        .await?;

    let active_pushes: Value = response.json().await?;
    println!("{:#?}", active_pushes);

    Ok(())
}

To get a list of your expired pushes:

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();
    let response = client.get("https://pwpush.com/p/expired.json")
        .header("X-User-Email", "your-email@example.com")
        .header("X-User-Token", "MyAPIToken")
        .send()
        .await?;

    let expired_pushes: Value = response.json().await?;
    println!("{:#?}", expired_pushes);

    Ok(())
}

Note: These examples use the reqwest crate for HTTP requests and serde_json for JSON handling. Add these dependencies to your Cargo.toml:

[dependencies]
reqwest = { version = "0.11", features = ["multipart", "json"] }
tokio = { version = "1.0", features = ["full"] }
serde_json = "1.0"
tokio-util = { version = "0.7", features = ["codec"] }

Swift

To create an anonymous push:

let url = URL(string: "https://pwpush.com/p.json")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")

let parameters = "password[payload]=mypassword"
request.httpBody = parameters.data(using: .utf8)

URLSession.shared.dataTask(with: request) { data, response, error in
    guard let data = data else { return }
    if let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
       let urlToken = json["url_token"] as? String {
        print("Share this secret URL: https://pwpush.com/p/\(urlToken)")
    }
}.resume()

Create a push with files (requires authentication):

let url = URL(string: "https://pwpush.com/p.json")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("your-email@example.com", forHTTPHeaderField: "X-User-Email")
request.setValue("MyAPIToken", forHTTPHeaderField: "X-User-Token")

let boundary = UUID().uuidString
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

var data = Data()

// Add text fields
let payload = "my_secure_payload"
let note = "For New Employee ID 12345"

data.append("--\(boundary)\r\n".data(using: .utf8)!)
data.append("Content-Disposition: form-data; name=\"password[payload]\"\r\n\r\n".data(using: .utf8)!)
data.append("\(payload)\r\n".data(using: .utf8)!)

data.append("--\(boundary)\r\n".data(using: .utf8)!)
data.append("Content-Disposition: form-data; name=\"password[note]\"\r\n\r\n".data(using: .utf8)!)
data.append("\(note)\r\n".data(using: .utf8)!)

// Add files
let files = ["file1.txt", "file2.txt"]
for file in files {
    if let fileURL = Bundle.main.url(forResource: file, withExtension: nil),
       let fileData = try? Data(contentsOf: fileURL) {
        data.append("--\(boundary)\r\n".data(using: .utf8)!)
        data.append("Content-Disposition: form-data; name=\"password[files][]\"; filename=\"\(file)\"\r\n".data(using: .utf8)!)
        data.append("Content-Type: application/octet-stream\r\n\r\n".data(using: .utf8)!)
        data.append(fileData)
        data.append("\r\n".data(using: .utf8)!)
    }
}

data.append("--\(boundary)--\r\n".data(using: .utf8)!)
request.httpBody = data

URLSession.shared.dataTask(with: request) { data, response, error in
    // Handle response
}.resume()

To create a URL push:

let url = URL(string: "https://pwpush.com/p.json")!
var request = URLRequest(url: url)
request.httpMethod = "POST"

let boundary = UUID().uuidString
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

var data = Data()
data.append("--\(boundary)\r\n".data(using: .utf8)!)
data.append("Content-Disposition: form-data; name=\"password[kind]\"\r\n\r\n".data(using: .utf8)!)
data.append("url\r\n".data(using: .utf8)!)
data.append("--\(boundary)\r\n".data(using: .utf8)!)
data.append("Content-Disposition: form-data; name=\"password[payload]\"\r\n\r\n".data(using: .utf8)!)
data.append("https://the0x00.dev\r\n".data(using: .utf8)!)
data.append("--\(boundary)--\r\n".data(using: .utf8)!)

request.httpBody = data

URLSession.shared.dataTask(with: request) { data, response, error in
    // Handle response
}.resume()

To create a QR code push:

let url = URL(string: "https://pwpush.com/p.json")!
var request = URLRequest(url: url)
request.httpMethod = "POST"

let boundary = UUID().uuidString
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

var data = Data()
data.append("--\(boundary)\r\n".data(using: .utf8)!)
data.append("Content-Disposition: form-data; name=\"password[kind]\"\r\n\r\n".data(using: .utf8)!)
data.append("qr\r\n".data(using: .utf8)!)
data.append("--\(boundary)\r\n".data(using: .utf8)!)
data.append("Content-Disposition: form-data; name=\"password[payload]\"\r\n\r\n".data(using: .utf8)!)
data.append("QR Code Content is here\r\n".data(using: .utf8)!)
data.append("--\(boundary)--\r\n".data(using: .utf8)!)

request.httpBody = data

URLSession.shared.dataTask(with: request) { data, response, error in
    // Handle response
}.resume()

To retrieve a push:

let url = URL(string: "https://pwpush.com/p/\(pushId).json")!
URLSession.shared.dataTask(with: url) { data, response, error in
    guard let data = data else { return }
    if let pushData = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
        // Handle push data
    }
}.resume()

To expire a push:

let url = URL(string: "https://pwpush.com/p/\(pushId).json")!
var request = URLRequest(url: url)
request.httpMethod = "DELETE"

URLSession.shared.dataTask(with: request) { data, response, error in
    // Handle response
}.resume()

To get a list of your active pushes:

let url = URL(string: "https://pwpush.com/p/active.json")!
var request = URLRequest(url: url)
request.setValue("your-email@example.com", forHTTPHeaderField: "X-User-Email")
request.setValue("MyAPIToken", forHTTPHeaderField: "X-User-Token")

URLSession.shared.dataTask(with: request) { data, response, error in
    guard let data = data else { return }
    if let activePushes = try? JSONSerialization.jsonObject(with: data) as? [[String: Any]] {
        // Handle active pushes
    }
}.resume()

To get a list of your expired pushes:

let url = URL(string: "https://pwpush.com/p/expired.json")!
var request = URLRequest(url: url)
request.setValue("your-email@example.com", forHTTPHeaderField: "X-User-Email")
request.setValue("MyAPIToken", forHTTPHeaderField: "X-User-Token")

URLSession.shared.dataTask(with: request) { data, response, error in
    guard let data = data else { return }
    if let expiredPushes = try? JSONSerialization.jsonObject(with: data) as? [[String: Any]] {
        // Handle expired pushes
    }
}.resume()

Note: These examples use Swift’s URLSession for networking. For production use, consider using libraries like Alamofire or implementing proper error handling and response parsing.

TypeScript

To create an anonymous push:

interface PushResponse {
  url_token: string;
  payload: string;
  expire_after_days: number;
  expire_after_views: number;
  expired: boolean;
  created_at: string;
  updated_at: string;
}

async function createPush(payload: string): Promise<PushResponse> {
  const response = await fetch('https://pwpush.com/p.json', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: new URLSearchParams({
      'password[payload]': payload
    })
  });

  const data: PushResponse = await response.json();
  console.log(`Share this secret URL: https://pwpush.com/p/${data.url_token}`);
  return data;
}

Create a push with files (requires authentication):

interface AuthenticatedPushOptions {
  payload: string;
  note?: string;
  files?: File[];
  email: string;
  apiToken: string;
}

async function createAuthenticatedPush({
  payload,
  note,
  files,
  email,
  apiToken
}: AuthenticatedPushOptions): Promise<PushResponse> {
  const formData = new FormData();
  formData.append('password[payload]', payload);

  if (note) {
    formData.append('password[note]', note);
  }

  if (files) {
    files.forEach(file => {
      formData.append('password[files][]', file);
    });
  }

  const response = await fetch('https://pwpush.com/p.json', {
    method: 'POST',
    headers: {
      'X-User-Email': email,
      'X-User-Token': apiToken
    },
    body: formData
  });

  return response.json();
}

To create a URL push:

interface URLPushOptions {
  url: string;
}

async function createURLPush({ url }: URLPushOptions): Promise<PushResponse> {
  const formData = new FormData();
  formData.append('password[kind]', 'url');
  formData.append('password[payload]', url);

  const response = await fetch('https://pwpush.com/p.json', {
    method: 'POST',
    body: formData
  });

  return response.json();
}

To create a QR code push:

interface QRPushOptions {
  content: string;
}

async function createQRPush({ content }: QRPushOptions): Promise<PushResponse> {
  const formData = new FormData();
  formData.append('password[kind]', 'qr');
  formData.append('password[payload]', content);

  const response = await fetch('https://pwpush.com/p.json', {
    method: 'POST',
    body: formData
  });

  return response.json();
}

To retrieve a push:

async function retrievePush(pushId: string): Promise<PushResponse> {
  const response = await fetch(`https://pwpush.com/p/${pushId}.json`);
  return response.json();
}

To expire a push:

async function expirePush(pushId: string): Promise<void> {
  await fetch(`https://pwpush.com/p/${pushId}.json`, {
    method: 'DELETE'
  });
}

To get a list of your active pushes:

interface AuthCredentials {
  email: string;
  apiToken: string;
}

async function getActivePushes({ email, apiToken }: AuthCredentials): Promise<PushResponse[]> {
  const response = await fetch('https://pwpush.com/p/active.json', {
    headers: {
      'X-User-Email': email,
      'X-User-Token': apiToken
    }
  });

  return response.json();
}

To get a list of your expired pushes:

interface AuthCredentials {
  email: string;
  apiToken: string;
}

async function getExpiredPushes({ email, apiToken }: AuthCredentials): Promise<PushResponse[]> {
  const response = await fetch('https://pwpush.com/p/expired.json', {
    headers: {
      'X-User-Email': email,
      'X-User-Token': apiToken
    }
  });

  return response.json();
}

Note: These examples use the Fetch API which is available in all modern browsers and Node.js (v18+). For older environments, consider using libraries like axios. The examples also use TypeScript interfaces to provide type safety and better IDE support.

Usage Examples:

// Create an anonymous push
const push = await createPush('my secret password');

// Create an authenticated push with files
const fileInput = document.querySelector<HTMLInputElement>('input[type="file"]');
if (fileInput?.files) {
  const push = await createAuthenticatedPush({
    payload: 'secure content',
    note: 'For employee onboarding',
    files: Array.from(fileInput.files),
    email: 'your-email@example.com',
    apiToken: 'your-api-token'
  });
}

// Create a URL push
const urlPush = await createURLPush({
  url: 'https://example.com'
});

// Create a QR code push
const qrPush = await createQRPush({
  content: 'QR Code content here'
});

// Get active pushes
const activePushes = await getActivePushes({
  email: 'your-email@example.com',
  apiToken: 'your-api-token'
});

Updated: