API Endpoint - postimages

  • Endpoint URL: https://api.osbn.io/v1/postimages.php
  • HTTP Method: POST
  • Headers:
    • Authorization: {token}
    • OSBN: {OSBN}
    • Testing: true
  • Multipart/Form Parameters:
    • cover_image or cover_url, author_image or author_url

Description:

The postimages REST API endpoint allows you to update an existing OSBN record with image data by making a POST request.

Notes:

  1. The OSBN record must already exist.
  2. At least one of cover_image or cover_url, author_image or author_url must be specified.
  3. Specifying Content-Type is unnecessary and not recommended. cURL has already set the Content-Type to multipart/form-data due to the presence of -F.
  4. If the user specifies the same filetype twice (for example, a cover_image and a cover_image again), then the second will be used.
  5. If the user specifies the same type twice (for example, a cover_image and a cover_url), then the URL will be used.
  6. Acceptable image format for files are: jpg, png, gif, and webp.
  7. Maximum file size is: 256kB.

Request Parameters:

  1. Authorization (Header): The authorization header is used to authenticate the request. You should include a valid token to access the API.
  2. OSBN (Header): The OSBN to update in expanded format. (for example, OSBN-01-001-000001-001-4)
  3. Optional: Testing (Header): If set, then the OSBN record isn't altered.
  4. and at least one of the below is required:
  5. cover_image (Data) string: path/filename to the cover image file on disk.
  6. cover_url (Data) string: The URL of the cover image.
  7. author_image (Data) string: path/filename to the author image file on disk.
  8. author_url (Data) string: The URL of the author image.

Deleting existing cover/author images:

  1. To delete image data, specify a dot "." instead of an image file or URL.
  2. -F "cover_url=." will delete both a cover URL or a cover FILE, if it exists.
  3. -F "author_image=@." will delete both an author URL or an author FILE, if it exists.

Example 1: cURL Command:

curl -X POST https://api.osbn.io/v1/postimages.php \
-H "Authorization: Wmp6ADsd8PtWfMODoaYMXNHIjhHA5Ws" \
-H "OSBN: OSBN-01-001-000001-001-4" \
-F "cover_url=https://arnehemingway.com/books/TheBookOfArne/TheBookOfArneCoverBespoke.jpg"

Example 2: cURL Command:

curl -X POST https://api.osbn.io/v1/postimages.php \
-H "Authorization: Wmp6ADsd8PtWfMODoaYMXNHIjhHA5Ws" \
-H "OSBN: OSBN-01-001-000001-001-4" \
-F "author_image=@/home/arne/Pictures/Arne unshaven rugged handsome.jpg" \
-F "cover_url=https://arnehemingway.com/books/TheBookOfArne/TheBookOfArneCoverBespoke.jpg"

Example 3: cURL Command: (test mode, one line)

curl -X POST https://api.osbn.io/v1/postimages.php -H "Authorization: Wmp6ADsd8PtWfMODoaYMXNHIjhHA5Ws" -H "OSBN: OSBN-01-001-000001-001-4" -H "Testing: true" -F "cover_image=@C:/Users/Emma/Desktop/Emma After Harry cover.png" -F "author_image=@C:/Users/Arne/Desktop/Emma Watson.jpg"

Example 4: cURL Command: (delete existing cover image and author image)

curl -X POST https://api.osbn.io/v1/postimages.php \
-H "Authorization: Wmp6ADsd8PtWfMODoaYMXNHIjhHA5Ws" \
-H "OSBN: OSBN-01-001-000001-001-4" \
-F "cover_url=." \
-F "author_image=@."

Responses:

  • If the POSTed data is accepted and the provided token is valid, you will receive a JSON response containing the book's OSBN.
  • If the request is unauthorized or if the data is not accepted, appropriate error responses will be provided.
Response Example (Success):
	{
		"status":"success",
		"message":"POSTimages Success!",
		"osbn":"OSBN-01-001-000001-001-4"
	}
	
Response Example (Invalid OSBN (or an OSBN that you don't own)):
	{
		"status":"error",
		"message":"Invalid OSBN: OSBN-01-001-000001-001-4"
	}
	
Response Example (Missing required field):
	{
		"status":"error",
		"message":"At least one field is required: cover_image, author_image, cover_url, or author_url."
	}