Create resource
curl --request POST \
--url https://api.thehaystack.ai/v2/haystack/items/{itemId}/resources/create \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"title": "<string>",
"subTitle": "<string>",
"description": "<string>",
"resourceTypeId": 123,
"fileMimeType": "application/pdf",
"fileSizeBytes": 1048576,
"originalFilename": "<string>",
"linkTarget": "<string>",
"externalPlatformId": "dQw4w9WgXcQ"
}
'import requests
url = "https://api.thehaystack.ai/v2/haystack/items/{itemId}/resources/create"
payload = {
"title": "<string>",
"subTitle": "<string>",
"description": "<string>",
"resourceTypeId": 123,
"fileMimeType": "application/pdf",
"fileSizeBytes": 1048576,
"originalFilename": "<string>",
"linkTarget": "<string>",
"externalPlatformId": "dQw4w9WgXcQ"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
title: '<string>',
subTitle: '<string>',
description: '<string>',
resourceTypeId: 123,
fileMimeType: 'application/pdf',
fileSizeBytes: 1048576,
originalFilename: '<string>',
linkTarget: '<string>',
externalPlatformId: 'dQw4w9WgXcQ'
})
};
fetch('https://api.thehaystack.ai/v2/haystack/items/{itemId}/resources/create', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.thehaystack.ai/v2/haystack/items/{itemId}/resources/create",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'title' => '<string>',
'subTitle' => '<string>',
'description' => '<string>',
'resourceTypeId' => 123,
'fileMimeType' => 'application/pdf',
'fileSizeBytes' => 1048576,
'originalFilename' => '<string>',
'linkTarget' => '<string>',
'externalPlatformId' => 'dQw4w9WgXcQ'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.thehaystack.ai/v2/haystack/items/{itemId}/resources/create"
payload := strings.NewReader("{\n \"title\": \"<string>\",\n \"subTitle\": \"<string>\",\n \"description\": \"<string>\",\n \"resourceTypeId\": 123,\n \"fileMimeType\": \"application/pdf\",\n \"fileSizeBytes\": 1048576,\n \"originalFilename\": \"<string>\",\n \"linkTarget\": \"<string>\",\n \"externalPlatformId\": \"dQw4w9WgXcQ\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.thehaystack.ai/v2/haystack/items/{itemId}/resources/create")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"title\": \"<string>\",\n \"subTitle\": \"<string>\",\n \"description\": \"<string>\",\n \"resourceTypeId\": 123,\n \"fileMimeType\": \"application/pdf\",\n \"fileSizeBytes\": 1048576,\n \"originalFilename\": \"<string>\",\n \"linkTarget\": \"<string>\",\n \"externalPlatformId\": \"dQw4w9WgXcQ\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.thehaystack.ai/v2/haystack/items/{itemId}/resources/create")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"title\": \"<string>\",\n \"subTitle\": \"<string>\",\n \"description\": \"<string>\",\n \"resourceTypeId\": 123,\n \"fileMimeType\": \"application/pdf\",\n \"fileSizeBytes\": 1048576,\n \"originalFilename\": \"<string>\",\n \"linkTarget\": \"<string>\",\n \"externalPlatformId\": \"dQw4w9WgXcQ\"\n}"
response = http.request(request)
puts response.read_body{
"resource": {
"id": 123,
"itemId": 123,
"title": "<string>",
"subTitle": "<string>",
"description": "<string>",
"resourceTypeId": 123,
"displayOrder": 123,
"fileMimeType": "<string>",
"fileSizeBytes": 123,
"externalPlatformId": "<string>",
"thumbnailImgUrl": "<string>",
"url": "<string>",
"resourceType": {
"id": 123,
"name": "<string>"
},
"linkTarget": "<string>"
},
"uploadUrl": "https://s3.amazonaws.com/bucket/key?signature=..."
}{
"result": "error",
"error": {
"type": "<string>",
"message": "<string>"
}
}{
"result": "error",
"error": {
"type": "<string>",
"message": "<string>"
}
}Resources
Create Resource
Attach a file, external link, or external video to an item. For file resources, the response includes an uploadUrl — a presigned S3 URL that you must PUT the file to (with the same Content-Type as fileMimeType) to complete the upload. link and video resources have no upload step and return uploadUrl: null.
POST
/
items
/
{itemId}
/
resources
/
create
Create resource
curl --request POST \
--url https://api.thehaystack.ai/v2/haystack/items/{itemId}/resources/create \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"title": "<string>",
"subTitle": "<string>",
"description": "<string>",
"resourceTypeId": 123,
"fileMimeType": "application/pdf",
"fileSizeBytes": 1048576,
"originalFilename": "<string>",
"linkTarget": "<string>",
"externalPlatformId": "dQw4w9WgXcQ"
}
'import requests
url = "https://api.thehaystack.ai/v2/haystack/items/{itemId}/resources/create"
payload = {
"title": "<string>",
"subTitle": "<string>",
"description": "<string>",
"resourceTypeId": 123,
"fileMimeType": "application/pdf",
"fileSizeBytes": 1048576,
"originalFilename": "<string>",
"linkTarget": "<string>",
"externalPlatformId": "dQw4w9WgXcQ"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
title: '<string>',
subTitle: '<string>',
description: '<string>',
resourceTypeId: 123,
fileMimeType: 'application/pdf',
fileSizeBytes: 1048576,
originalFilename: '<string>',
linkTarget: '<string>',
externalPlatformId: 'dQw4w9WgXcQ'
})
};
fetch('https://api.thehaystack.ai/v2/haystack/items/{itemId}/resources/create', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.thehaystack.ai/v2/haystack/items/{itemId}/resources/create",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'title' => '<string>',
'subTitle' => '<string>',
'description' => '<string>',
'resourceTypeId' => 123,
'fileMimeType' => 'application/pdf',
'fileSizeBytes' => 1048576,
'originalFilename' => '<string>',
'linkTarget' => '<string>',
'externalPlatformId' => 'dQw4w9WgXcQ'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.thehaystack.ai/v2/haystack/items/{itemId}/resources/create"
payload := strings.NewReader("{\n \"title\": \"<string>\",\n \"subTitle\": \"<string>\",\n \"description\": \"<string>\",\n \"resourceTypeId\": 123,\n \"fileMimeType\": \"application/pdf\",\n \"fileSizeBytes\": 1048576,\n \"originalFilename\": \"<string>\",\n \"linkTarget\": \"<string>\",\n \"externalPlatformId\": \"dQw4w9WgXcQ\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.thehaystack.ai/v2/haystack/items/{itemId}/resources/create")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"title\": \"<string>\",\n \"subTitle\": \"<string>\",\n \"description\": \"<string>\",\n \"resourceTypeId\": 123,\n \"fileMimeType\": \"application/pdf\",\n \"fileSizeBytes\": 1048576,\n \"originalFilename\": \"<string>\",\n \"linkTarget\": \"<string>\",\n \"externalPlatformId\": \"dQw4w9WgXcQ\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.thehaystack.ai/v2/haystack/items/{itemId}/resources/create")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"title\": \"<string>\",\n \"subTitle\": \"<string>\",\n \"description\": \"<string>\",\n \"resourceTypeId\": 123,\n \"fileMimeType\": \"application/pdf\",\n \"fileSizeBytes\": 1048576,\n \"originalFilename\": \"<string>\",\n \"linkTarget\": \"<string>\",\n \"externalPlatformId\": \"dQw4w9WgXcQ\"\n}"
response = http.request(request)
puts response.read_body{
"resource": {
"id": 123,
"itemId": 123,
"title": "<string>",
"subTitle": "<string>",
"description": "<string>",
"resourceTypeId": 123,
"displayOrder": 123,
"fileMimeType": "<string>",
"fileSizeBytes": 123,
"externalPlatformId": "<string>",
"thumbnailImgUrl": "<string>",
"url": "<string>",
"resourceType": {
"id": 123,
"name": "<string>"
},
"linkTarget": "<string>"
},
"uploadUrl": "https://s3.amazonaws.com/bucket/key?signature=..."
}{
"result": "error",
"error": {
"type": "<string>",
"message": "<string>"
}
}{
"result": "error",
"error": {
"type": "<string>",
"message": "<string>"
}
}Authorizations
Enter your API token from the Haystack dashboard
Path Parameters
Body
application/json
Display title for the resource
Available options:
file, link, video Category for grouping (see /resource-types)
Required when contentType is file
Example:
"application/pdf"
Required when contentType is file
Example:
1048576
Original filename, used to choose an extension
Required when contentType is link
Required when contentType is video
Available options:
youtube, vimeo Required when contentType is video
Example:
"dQw4w9WgXcQ"
⌘I

