curl --request GET "${CHENVOYA_BASE_URL}/v1/assets/${ASSET_ID}" \
--header "Authorization: Bearer ${CHENVOYA_API_KEY}" import urllib.request
import urllib.parse
import json
import os
import sys
import re
import uuid
key = os.environ["CHENVOYA_API_KEY" ].strip()
if not key or re.search(r"[\x00-\x1f\x7f-\x9f]" , key):
sys.exit("Set CHENVOYA_API_KEY to a non-empty value without control characters" )
base = os.environ["CHENVOYA_BASE_URL" ].rstrip("/" )
headers = {"Authorization" : "Bearer " + key}
ASSET_ID = os.environ["ASSET_ID" ]
if not re.fullmatch("^ast-[0-9a-f]{32}$" , ASSET_ID):
sys.exit("Set ASSET_ID to the ID from the creation response" )
path = "/v1/assets/{asset_id}" .replace("{asset_id}" , urllib.parse.quote(ASSET_ID, safe="" ))
request = urllib.request.Request(base + path, data=None , headers=headers, method="GET" )
try :
with urllib.request.urlopen(request) as response:
print(response.read().decode("utf-8" ))
except urllib.request.HTTPError as error:
print(error.read().decode("utf-8" ))
sys.exit(1 ) Show all 24 lines Show less
// Needs Node.js 20 or later; save it as a .mjs file and run it.
const key = process.env.CHENVOYA_API_KEY?.trim();
if (!key || /[\x00-\x1f\x7f-\x9f]/.test(key)) {
console.error("Set CHENVOYA_API_KEY to a non-empty value without control characters" );
process.exit(1 );
}
const base = process.env.CHENVOYA_BASE_URL;
if (!base) throw new Error("Set CHENVOYA_BASE_URL" );
const headers = {Authorization: `Bearer ${key}` };
const ASSET_ID = process.env.ASSET_ID;
if (!ASSET_ID) throw new Error("Set ASSET_ID" );
if (typeof ASSET_ID !== "string" || (new RegExp("^ast-[0-9a-f]{32}$" )).exec(ASSET_ID)?.[0 ] !== ASSET_ID) throw new Error("Set ASSET_ID to the ID from the creation response" );
const path = "/v1/assets/{asset_id}" .replace("{asset_id}" , encodeURIComponent(ASSET_ID));
const response = await fetch(base.replace(/\/$/, "" ) + path, {method: "GET" , headers, body: undefined });
console.log(await response.text());
if (!response.ok) process.exitCode = 1 ;package main
import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"regexp"
"strings"
)
func main() {
key := strings.TrimSpace(os.Getenv("CHENVOYA_API_KEY" ))
if key == "" || regexp.MustCompile(`[\x00-\x1f\x7f-\x9f]` ).MatchString(key) {
fail("Set CHENVOYA_API_KEY to a non-empty value without control characters" )
}
base := strings.TrimRight(os.Getenv("CHENVOYA_BASE_URL" ), "/" )
if base == "" {
fail("Set CHENVOYA_BASE_URL" )
}
assetID := os.Getenv("ASSET_ID" )
if assetID == "" {
fail("Set ASSET_ID" )
}
if !regexp.MustCompile(`\A(?:ast-[0-9a-f]{32})\z` ).MatchString(assetID) {
fail("Set ASSET_ID to the ID from the creation response" )
}
path := strings.Replace("/v1/assets/{asset_id}" , "{asset_id}" , url.PathEscape(assetID), 1 )
request, err := http.NewRequest("GET" , base+path, nil )
if err != nil {
fail(err .Error())
}
request.Header.Set("Authorization" , "Bearer " +key)
response, err := http.DefaultClient.Do(request)
if err != nil {
fail(err .Error())
}
text, err := io.ReadAll(response.Body)
response.Body.Close()
if err != nil {
fail(err .Error())
}
fmt.Println(string(text))
if response.StatusCode < 200 || response.StatusCode > 299 {
os.Exit(1 )
}
}
func fail(message string) {
fmt.Fprintln(os.Stderr, message)
os.Exit(1 )
} Show all 53 lines Show less