question

steampunkjunkiesx avatar image
1 Like"
steampunkjunkiesx asked

Example of using API to create video?

Hi,


I was pleasantly surprised to hear that eBay is now letting us add videos for products on our listings. The email was a bit hit and miss though, and I can't figure out how to do it. Does anyone have an example code? The "overview" and example URL in their email doesn't work for me:


https://developer.ebay.com/api-docs/commerce/static/managing-video-media.html


(hangs and hangs, and eventually gives an error about SSL not being valid)


Thanks - I'm really looking forward to this! (we have been using videos on other marketplaces for ages, as its a great way to show off our unique products ;))


Cheers


Andy

ebay api api tools
10 |600

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sagar_developersupport avatar image
1 Like"
sagar_developersupport answered

Hi @steampunkjunkiesx,

Media API gives a user, ability to create and upload videos. This video can be used to attach with a listing.
Ref: https://developer.ebay.com/api-docs/commerce/media/static/overview.html

This is a two step process:- First step is to execute createVideo to create a record for the video metadate like title, size, and classification of the video to be created.
Ref:https://developer.ebay.com/api-docs/commerce/media/resources/video/methods/createVideo

After the successful execution of createVideo call, you will get the Video ID in the location header under the response headers.- Second step is to execute UploadVideo call and after the successful execution, you will get the 200 status code in the response.
Ref: https://developer.ebay.com/api-docs/commerce/media/resources/video/methods/uploadVideo

Getting the video status:
- Users can use getVideo call with the videoID to get the current status of that videoID.
Ref: https://developer.ebay.com/api-docs/commerce/media/resources/video/methods/getVideo

How to use a videoID in a listing:- You can attach a VideoID to a listing as soon as you get the VideoID in the location header. There is no need to wait for processing to complete. If your video gets blocked after the processing Blocked, it will not be surfaced to Buyers.

Also, Buyer will only be able to see the video on eBay native apps. They will not be able to see the video on the web application even if a listing has a video.Sellers can use Item.VideoDetails.VideoID field for attaching a video to a listing.Ref: https://developer.ebay.com/Devzone/XML/docs/Reference/eBay/AddItem.html#Request.Item.VideoDetails

https://developer.ebay.com/Devzone/XML/docs/ReleaseNotes.html#1203-NF

Best Regards,
eBay Developer Support

· 1
10 |600

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

steampunkjunkiesx avatar image steampunkjunkiesx commented ·

Thank you. Is there an example of this being done in PHP? I'm going to be using Perl, but would like to see how its done in PHP so I can try to adapt :) I use Net::eBay currently, but I have a feeling that won't work without some tweaks (sorry, I replied below but just realised that wasn't a "reply" to you!)

0 Likes 0 ·
steampunkjunkiesx avatar image
0 Likes"
steampunkjunkiesx answered

Does anyone actually have any example PHP code I can see? I'm trying to convert it into Perl :)


Thanks!

10 |600

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

tigramber avatar image
0 Likes"
tigramber answered

Yea, that webpage wasn't very helpful for me either! I wrote this python script that works for me, maybe it will be helpful:

# NOTE: As found on https://developer.ebay.com/devzone/xml/docs/Reference/eBay/ReviseItem.html
# "If you are revising a US eBay Motors vehicle listing, only use ReviseItem if the vehicle was
# listed via the eBay API, but not if the vehicle was listed through the US eBay Motors Web site."


# eBay Video Instructions
# First, get a User Access Token to your eBay account:
# - If logged into eBay, log out of eBay
# - Go to www.developer.ebay.com and log in
# - In the top right corner click you username --> User Access Tokens
# - Click the Production radio button, the Videos keyset will automatically display
# - Click the OAuth radio button, then click Sign In to Production for OAth
# - Sign in with your eBay account (not developer account!) credentials
# - A really long token is returned. It expires in 2 hours. Click Copy Token To Clipboard.
# Copy and paste the token near the top of the script where it says here: BearerToken = "HERE"
# Enter the other required information into the "ENTER THESE VALUES MANUALLY" section below
# Save the updated script file.
# Run the script from the Windows Terminal by entering something like:
# "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python.exe" "C:\eBay Create Video.py"


import requests
from requests.structures import CaseInsensitiveDict
import json
import time
import xml.etree.ElementTree


### ENTER THESE VALUES MANUALLY ###
BearerToken = "HERE" # Must be within 2 hours of creation!
VideoSize = "42745130" # For Windows, use the "Size" value (not the "Size On Disk" value)
VideoTitle = "2015 Ford Mustang GT Premium PP"
VideoLocation = r"L:\Mustang GT For Sale\Photos and Videos\Highlight_00_Video.MP4" # Enter the filepath to the video; the r is needed for Windows
ServiceEndpoint = "https://api.ebay.com/ws/api.dll" # Use an "XML API" Gateway URI; see the "Service Endpoints" section here: https://developer.ebay.com/devzone/xml/docs/Concepts/MakingACall.html#CallStructureandRouting
APIschemaVersion = "1277" # Use the highest number listed here: https://developer.ebay.com/devzone/xml/docs/releasenotes.html
Item_ID = "255703505560" # aka the "eBay item number" displayed on the listing page


### Get a unique video URL ###

url = "https://apim.ebay.com/commerce/media/v1_beta/video"
headers = CaseInsensitiveDict()
headers["Content-Type"] = "application/json"
headers["Authorization"] = "Bearer %s" % BearerToken
data = """
{
    "size": "%s",
    "title": "%s",
    "classification": [
        "ITEM"
    ]
}
""" % (VideoSize, VideoTitle)

CreateVideo = requests.post(url, headers=headers, data=data)
print(CreateVideo.headers) # prints the entire header as a dictionary
#print(CreateVideo.headers["location"]) # prints a specific section of the dictionary
location = (CreateVideo.headers["location"])
print("The location is:", location)
#split = location.split("/")
#print(split)
Video_ID = location.split("/")[-1:][0]
print("The video ID is:", Video_ID)


### Upload the video to that unique URL ###

url2 = "%s/upload" % location
#print(url2)
headers2 = CaseInsensitiveDict()
headers2["Content-Type"] = "application/octet-stream"
headers2["Authorization"] = "Bearer %s" % BearerToken
print("Now converting the video file to binary (may take a few minutes)...")
with open("%s" % VideoLocation, mode='rb') as VideoFile: # b is important -> binary
    data2 = VideoFile.read()

UploadVideo = requests.post(url2, headers=headers2, data=data2)
UploadStatus = UploadVideo.status_code
print("The video upload status code is:", UploadStatus)
print("If the above status code is 200, the upload was successful and processing will now begin.")
print("It may take ~10 minutes to process the video.")


### Check the processing status periodically ###

print("Now waiting for 2 minutes...")
time.sleep(120) # Wait 2 minutes

JobRuntime = 2 # minutes so far
while(True): # Repeat this loop until a break or quit statement is issued
    VideoInfo = requests.get(location, headers={"Authorization": "Bearer %s" % BearerToken})
    VideoInfoText = VideoInfo.json()
    #print("The video info is:",VideoInfoText)
    VideoStatus = VideoInfoText["status"]
    print("The video status is:", VideoStatus)
    if (VideoStatus == "LIVE"):
        break # Exit this While loop
    elif (VideoStatus == "PROCESSING"):
        print("The video is still being processed.")
        print("The job runtime so far is: %s minutes" % JobRuntime)
        print("Now waiting for 1 more minute...")
        time.sleep(60)
        JobRuntime+=1
    elif (VideoStatus == "BLOCKED"):
        print("The job has been blocked after submitting.")
        print("The total blocked job runtime was:", JobRuntime, "minutes.")
        StatusMessage = VideoInfo["statusMessage"]
        print("The status message is:", StatusMessage)
        print("Something is wrong. Now quitting.")
        quit()
    elif (VideoStatus == "PROCESSING_FAILED"):
        print("The job has failed after submitting.")
        print("The total failed job runtime was:", JobRuntime, "minutes.")
        StatusMessage = VideoInfo["statusMessage"]
        print("The status message is:", StatusMessage)
        print("Something is wrong. Now quitting.")
        quit()
    else:
        print("The job has an unrecognized status.")
        StatusMessage = VideoInfo["statusMessage"]
        print("The status message is:", StatusMessage)
        print("Something is wrong. Now quitting.")
        requests.close() # End the session and stop the job on the remote server
        quit()
print("Congratulations! The video has been successfully processed.")
print("The total job runtime was:", JobRuntime, "minutes.")


### Attach the video to the item ###

print("Now attaching the processed video to the listed item...")

headers3 = CaseInsensitiveDict()
headers3["Content-Type"] = "text/xml"
headers3["X-EBAY-API-SITEID"] = "0"
headers3["X-EBAY-API-IAF-TOKEN"] = "Bearer %s" % BearerToken
headers3["X-EBAY-API-COMPATIBILITY-LEVEL"] = "%s" % APIschemaVersion
headers3["X-EBAY-API-CALL-NAME"] = "ReviseItem"
data3 = """
<?xml version="1.0" encoding="utf-8"?>
<ReviseItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
  <Item>
    <ItemID>%s</ItemID>
    <VideoDetails>
<VideoID>%s</VideoID>
</VideoDetails>
  </Item>
</ReviseItemRequest>
""" % (Item_ID,Video_ID)

AttachVideo = requests.post(ServiceEndpoint, headers=headers3, data=data3)
print("The result is:")
print(AttachVideo.content)

print("\nSo far, so good?\n")    
    

### Verify successful video attachment ###

print("Now checking if the processed video was successfully attached to the listed item...")

headers4 = CaseInsensitiveDict()
headers4["Content-Type"] = "text/xml"
headers4["X-EBAY-API-SITEID"] = "0"
headers4["X-EBAY-API-IAF-TOKEN"] = "Bearer %s" % BearerToken
headers4["X-EBAY-API-COMPATIBILITY-LEVEL"] = "%s" % APIschemaVersion
headers4["X-EBAY-API-CALL-NAME"] = "GetItem"
data4 = """
<?xml version="1.0" encoding="utf-8"?>
<GetItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
  <ItemID>%s</ItemID>
</GetItemRequest>
""" % Item_ID

ItemInfo=requests.post(ServiceEndpoint, headers=headers4, data=data4)
#print(ItemInfo.content)
root=xml.etree.ElementTree.fromstring(ItemInfo.content)
dictionary_Video={} # initialize an empty dictionary
dictionary_Video["Video Info"]=dictionary_Video.get("Item.VideoDetails","MISSING") # add the video info to the dictionary, or "MISSING" if the value doesn't exist
ItemVideoInfo = dictionary_Video["Video Info"]
print("The item's video info is:", ItemVideoInfo)
if ItemVideoInfo == "MISSING":
    print("The item's video info is missing, so the video was not attached.")
    print("Something is wrong. Now quitting.")
    quit()
dictionary_Video["Video ID"]=dictionary_Video.get("Item.VideoDetails.VideoID","MISSING") # add the video ID to the dictionary, or "MISSING" if the value doesn't exist
ItemVideoID = dictionary_Video["Video ID"]
print("The item's video ID is:", ItemVideoID)
if ItemVideoID == "MISSING":
    print("The item's video ID is missing, so the video was not attached.")
    print("Something is wrong. Now quitting.")
    quit()
print("It should match the uploaded video ID:",Video_ID)
if ItemVideoID == Video_ID:
    print("Congratulations! The uploaded video was the same one attached to the item.")
else:
    print("The uploaded video wasn't the same one attached to the item.")
    print("Something is wrong. Now quitting.")
    quit()
print("Congratulations! The video is attached to the item listing.")
print("It should be reviewed and posted to your listing within 48 hours.")
print("Videos are displayed in the eBay app and the mobile browser (in the image gallery of the listing).
10 |600

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.