import os
import requests
url = f"https://api.github.com/repos/{os.environ['GITHUB_OWNER']}/repo/actions/workflows/main.yml/dispatches"
headers = {
"Authorization": f"Bearer {os.environ['GITHUB_TOKEN']}",
"Accept": "application/vnd.github+json"
}
data = {
"ref": "main",
"inputs": {
"param1": "value1"
}
}
response = requests.post(url, headers=headers, json=data)
response.raise_for_status()
print(response.json())
import os
import httpx
url = f"https://api.github.com/repos/{os.environ['GITHUB_OWNER']}/repo/actions/workflows/main.yml/dispatches"
headers = {
"Authorization": f"Bearer {os.environ['GITHUB_TOKEN']}",
"Accept": "application/vnd.github+json"
}
data = {
"ref": "main",
"inputs": {
"param1": "value1"
}
}
with httpx.Client() as client:
response = client.post(url, headers=headers, json=data)
response.raise_for_status()
print(response.json())
import fetch from 'node-fetch';
import { env } from 'process';
const url = `https://api.github.com/repos/${env.GITHUB_OWNER}/repo/actions/workflows/main.yml/dispatches`;
const headers = {
'Authorization': `Bearer ${env.GITHUB_TOKEN}`,
'Accept': 'application/vnd.github+json'
};
const data = {
ref: 'main',
inputs: {
param1: 'value1'
}
};
try {
const response = await fetch(url, {
method: 'POST',
headers,
body: JSON.stringify(data)
});
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const json = await response.json();
console.log(json);
} catch (error) {
console.error('Request failed:', error);
}
import axios from 'axios';
import { env } from 'process';
const url = `https://api.github.com/repos/${env.GITHUB_OWNER}/repo/actions/workflows/main.yml/dispatches`;
const headers = {
'Authorization': `Bearer ${env.GITHUB_TOKEN}`,
'Accept': 'application/vnd.github+json'
};
const data = {
ref: 'main',
inputs: {
param1: 'value1'
}
};
try {
const response = await axios.post(url, data, { headers });
console.log(response.data);
} catch (error) {
if (error.response) {
console.error('Request failed:', error.response.status, error.response.data);
} else {
console.error('Request failed:', error.message);
}
}
package main
import (
"fmt"
"log"
"net/http"
"os"
"strings"
)
func main() {
owner := os.Getenv("GITHUB_OWNER")
token := os.Getenv("GITHUB_TOKEN")
url := fmt.Sprintf("https://api.github.com/repos/%s/repo/actions/workflows/main.yml/dispatches", owner)
data := `{"ref":"main","inputs":{"param1":"value1"}}`
req, err := http.NewRequest("POST", url, strings.NewReader(data))
if err != nil {
log.Fatal(err)
}
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Accept", "application/vnd.github+json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
log.Fatalf("Request failed with status: %s", resp.Status)
}
// Simple response body read (in real code, use json.Decoder)
body := make([]byte, 1024)
n, _ := resp.Body.Read(body)
fmt.Println(string(body[:n]))
}
<?php
$owner = getenv('GITHUB_OWNER');
$token = getenv('GITHUB_TOKEN');
$url = "https://api.github.com/repos/{$owner}/repo/actions/workflows/main.yml/dispatches";
$data = [
'ref' => 'main',
'inputs' => [
'param1' => 'value1'
]
];
$options = [
'http' => [
'header' => [
"Authorization: Bearer {$token}",
"Accept: application/vnd.github+json"
],
'method' => 'POST',
'content' => json_encode($data),
'ignore_errors' => true
]
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
if ($http_response_header[0] !== 'HTTP/1.1 204 No Content') {
throw new Exception("Request failed: " . $http_response_header[0]);
}
print($response);
require 'net/http'
require 'json'
require 'uri'
owner = ENV['GITHUB_OWNER']
token = ENV['GITHUB_TOKEN']
uri = URI.parse("https://api.github.com/repos/#{owner}/repo/actions/workflows/main.yml/dispatches")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Authorization'] = "Bearer #{token}"
request['Accept'] = 'application/vnd.github+json'
request.body = {
ref: 'main',
inputs: {
param1: 'value1'
}
}.to_json
response = http.request(request)
unless response.is_a?(Net::HTTPSuccess)
raise "Request failed with status: #{response.code}"
end
puts response.body
import Foundation
guard let owner = ProcessInfo.processInfo.environment["GITHUB_OWNER"],
let token = ProcessInfo.processInfo.environment["GITHUB_TOKEN"] else {
fatalError("Missing required environment variables")
}
let url = URL(string: "https://api.github.com/repos/" + owner + "/repo/actions/workflows/main.yml/dispatches")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
request.setValue("application/vnd.github+json", forHTTPHeaderField: "Accept")
let body: [String: Any] = [
"ref": "main",
"inputs": [
"param1": "value1"
]
]
request.httpBody = try? JSONSerialization.data(withJSONObject: body)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
fatalError("Request failed: \(error)")
}
guard let httpResponse = response as? HTTPURLResponse,
(200...299).contains(httpResponse.statusCode) else {
fatalError("Request failed with status: \((response as? HTTPURLResponse)?.statusCode ?? 0)")
}
if let data = data, let json = try? JSONSerialization.jsonObject(with: data) {
print(json)
}
}
task.resume()
// Keep the program running to allow async task to complete
RunLoop.main.run()
use std::env;
use reqwest::blocking::Client;
use serde_json::json;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let owner = env::var("GITHUB_OWNER")?;
let token = env::var("GITHUB_TOKEN")?;
let url = format!(
"https://api.github.com/repos/{}/repo/actions/workflows/main.yml/dispatches",
owner
);
let client = Client::new();
let response = client
.post(&url)
.header("Authorization", format!("Bearer {}", token))
.header("Accept", "application/vnd.github+json")
.json(&json!({
"ref": "main",
"inputs": {
"param1": "value1"
}
}))
.send()?;
if !response.status().is_success() {
return Err(format!("Request failed with status: {}", response.status()).into());
}
let body = response.text()?;
println!("{}", body);
Ok(())
}
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var owner = Environment.GetEnvironmentVariable("GITHUB_OWNER");
var token = Environment.GetEnvironmentVariable("GITHUB_TOKEN");
var url = $"https://api.github.com/repos/{owner}/repo/actions/workflows/main.yml/dispatches";
var data = new {
@ref = "main",
inputs = new {
param1 = "value1"
}
};
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.github+json"));
var response = await client.PostAsJsonAsync(url, data);
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
}