Update API
Update metadata for an existing image.
Endpoint
http
POST /update/<object_id>Authentication
Required.
Request Format
Content-Type: application/json
Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
tags | Array | Yes | New array of tags to replace existing tags |
Response
Success: HTTP 200 with empty body
Code Examples
javascript
async function updateImageTags(objectId, tags) {
const response = await fetch(
`https://api.reimage.dev/update/${objectId}`,
{
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.REIMAGE_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ tags })
}
);
if (!response.ok) {
throw new Error(`Update failed: ${response.status}`);
}
return response.ok;
}
// Usage
await updateImageTags('xyz789', ['product', 'featured', 'new']);python
import requests
import os
def update_image_tags(object_id, tags):
"""Update tags for an image"""
url = f'https://api.reimage.dev/update/{object_id}'
headers = {
'Authorization': f'Bearer {os.environ.get("REIMAGE_API_KEY")}',
'Content-Type': 'application/json'
}
data = {'tags': tags}
response = requests.post(url, json=data, headers=headers)
response.raise_for_status()
return response.status_code == 200
# Usage
update_image_tags('xyz789', ['product', 'featured', 'new'])php
<?php
function updateImageTags($objectId, $tags) {
$apiKey = getenv('REIMAGE_API_KEY');
$url = "https://api.reimage.dev/update/$objectId";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'tags' => $tags
]));
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $httpCode === 200;
}
// Usage
updateImageTags('xyz789', ['product', 'featured', 'new']);
?>go
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
)
func updateImageTags(apiKey, objectID string, tags []string) error {
url := fmt.Sprintf("https://api.reimage.dev/update/%s", objectID)
payload := map[string]interface{}{
"tags": tags,
}
jsonData, err := json.Marshal(payload)
if err != nil {
return err
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
if err != nil {
return err
}
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return fmt.Errorf("update failed with status: %d", resp.StatusCode)
}
return nil
}
func main() {
apiKey := os.Getenv("REIMAGE_API_KEY")
err := updateImageTags(apiKey, "xyz789", []string{"product", "featured", "new"})
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Println("Tags updated successfully")
}rust
use reqwest::header::{HeaderMap, HeaderValue, AUTHORIZATION, CONTENT_TYPE};
use serde_json::json;
async fn update_image_tags(
api_key: &str,
object_id: &str,
tags: Vec<&str>,
) -> Result<(), Box<dyn std::error::Error>> {
let url = format!("https://api.reimage.dev/update/{}", object_id);
let payload = json!({ "tags": tags });
let mut headers = HeaderMap::new();
headers.insert(
AUTHORIZATION,
HeaderValue::from_str(&format!("Bearer {}", api_key))?,
);
headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/json"));
let client = reqwest::Client::new();
let response = client
.post(&url)
.headers(headers)
.json(&payload)
.send()
.await?;
if !response.status().is_success() {
return Err(format!("Update failed: {}", response.status()).into());
}
Ok(())
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = std::env::var("REIMAGE_API_KEY")?;
update_image_tags(&api_key, "xyz789", vec!["product", "featured", "new"]).await?;
println!("Tags updated successfully");
Ok(())
}Important Notes
- Tags are completely replaced, not merged
- You must specify all tags you want to keep
- Empty tags array is allowed
- Only the image owner can update tags
Example: Adding a Tag
To add a tag while keeping existing ones, first retrieve current tags:
javascript
// Get current image data
const response = await fetch('https://api.reimage.dev/get/', {
headers: { 'Authorization': `Bearer ${API_KEY}` }
});
const data = await response.json();
// Find your image and get current tags
// Then add new tag
const currentTags = ['existing', 'tags'];
const newTags = [...currentTags, 'new-tag'];
await updateImageTags('xyz789', newTags);