Creating a Source, Channel, and Target
12 min
to help you get started with the zen master api, we will walk through some common tasks here create a source create a channel create a target because there are many ways to use rest apis, we will do this in two different ways first, we will create the objects using the popular rest client postman; next, we will complete the same tasks using a python script prerequisites general access to the zen master api an api key the zen master api reference (find it in the documents section of the customer portal ) a creating a new broadcaster cluster docid\ njaoz 85pcy2 qxguyjso with at least one adding a broadcaster to a manual cluster docid\ xyscyso498ly77zjqr 51 set up in zen master for the postman section postman you can use either the desktop or online version if you haven't already set up a zen master api collection in postman, follow the instructions in step 2 getting started with postman docid 8rvjfs6 skyedlj8wpyf7 for the python section python installed on your system postman instructions note you should look at the api reference for each of the requests we will only be including required fields here, but there are many more get ids that will be needed for other requests first we will get id values for the broadcaster, cluster and other objects that will be required for the api requests that we will be making get the id for your broadcaster cluster by going to the clusters > get list all clusters request in postman uncheck all the request parameters unless you know the exact name of you your cluster, in which case you can set that as the value of the name parameter to return just that object request parameters with or without the name parameter, click send to submit the request if you used the name parameter, there should be just one object in the response if not, you will get all the cluster objects, but you can find the one you are looking for by searching the response json for some portion of the cluster name searching in the postman response save the cluster id for use in steps below now do the same for broadcasters get broadcasters , using the name parameter if you have the exact name, or find it in the list and save its id as well you also need to get or create a tag id to do this, go to the tags section of the api and either get a list of all tags and choose one, or use the post request to create a new one if you create a new one, just go to the body of the post request and enter a name for the tag you will find the id for the tag in the response after you send the request create tag request body next, you will need an alerting profile id , which is the same thing as an event profile id go to events>profiles> get list all events profiles and send the request save the id for the default profile it will probably be the first one, though it will probably not have the id you see below default events profile now you have all the information you need to go on and create your source, channel, and targets create the source now go to sources>fileurl> post create file url source go to the body tab and replace the json there with the following { "broadcaster cluster id" your cluster id, "name" "test source pm", "protocol" "http file", "resource tag ids" \[ your tag id ], "target broadcaster id" your broadcaster id, "type" "file", "url" "https //zixi file sources s3 amazonaws com/ts/bbb avc 420 8bit 1080p60 ts", "alerting profile id" your alerting profile id } replace the values in all caps with the id values you obtained in the previous section, so that your request body looks something like this sample request body for create source you should see a success response if you get an error instead, check the request body to make sure you put in the correct id values for the tag, alerting profile, cluster, and broadcaster when you get a success response, save the returned source id as you will need it for the next section create a pass through channel go to channels>passthrough> post create a new pass through channel go to the body tab and replace the json there with the following { "name" "test channel pm", "resource tag ids" \[ your tag id ], "alerting profile id" your alerting profile id, "broadcaster cluster id" your cluster id, "target broadcaster id" your broadcaster id, "sources" \[ { "primary" true, "source id" the id of the source you created } ] } if you forgot to save the source id , you can find it using a get list sources request and searching the results for the source name replace the values in all caps with the id values you obtained in the previous section, so that your request body looks something like this you should see a success response if you get an error instead, check the request body to make sure you put in the correct id values for the source, tag, alerting profile, cluster, and broadcaster when you get a success response, save the returned channel id as you will need it for the next section create a udp target go to targets>urd rtp> post create a new udp/rtp target go to the body tab and replace the json there with the following { "name" "test target pm", "resource tag ids" \[ your tag id ], "alerting profile id" your alerting profile id, "rtp" false, "host" "127 0 0 1", "port" 5001, "passthrough channel id" the id of the channel you created } note that the host value of 127 0 0 1 is the localhost ip this assumes that the broadcaster you are working with is installed on the same machine you are working on if that is not the case, you will need to use get list broadcasters to get the broadcaster objects again, find your broadcaster, and get the value of the source ip field in the response replace the values in all caps with the id values you obtained in the previous section, so that your request body looks something like this if you forgot to save the channel id , you can find it using a get list pass through channels request and searching the results for the channel name you should see a success response if you get an error instead, check the request body to make sure you put in the correct id values for the channel, tag, and alerting profile python instructions the beauty of rest apis is that you can automate your requests using any language that supports http requests nodejs, java, swift, whatever you use here we are going to use the popular python language rather than build a script from scratch, we're just going to give you one that is very flexible and that you can use for any zen master api request(s) \# create source, channel, and target print("tech week create source, channel, targets") import requests import json \######################################### \# class for zm api requests \######################################### class apiclient def init (self, baseurl, headers) self baseurl = baseurl self headers = headers def make request(self, method, endpoint, payload) url = self baseurl + endpoint response = requests request(method, url, headers=self headers, data=payload) \# parse the json response into a python dictionary data = response json() print(f"api request method {method} success {data\['success']}") print(f"object id {data\['result']\['id']}") print(f"object name {data\['result']\['name']}") return data \######################################### \# zen master environment \######################################### baseurl = "https //api zen zixi com/v2" apikey = 'your api key headers = { 'content type' 'application/json', 'accept' 'application/json', 'charset' 'utf 8', 'x api key' apikey } client = apiclient(baseurl, headers) \######################################### \# create file url source \######################################### endpoint = "/sources" payload = json dumps({ "name" "test source python", "resource tag ids" \[ your tag id ], "alerting profile id" your alerting profile id, "broadcaster cluster id" your cluster id, "target broadcaster id" your broadcaster id, "protocol" "http file", "type" "file", "url" "https //zixi file sources s3 amazonaws com/ts/bbb avc 420 8bit 1080p60 ts" }) \# response = requests request("post", url, headers=headers, data=payload) data = client make request("post", endpoint, payload) sourceid = data\['result']\['id'] print(f"create file url source id {sourceid}") \######################################### \# create pass through channel \######################################### endpoint = "/channels/passthrough" payload = json dumps({ "name" "test channel python", "resource tag ids" \[ your tag id ], "alerting profile id" your alerting profile id, "broadcaster cluster id" your cluster id, "target broadcaster id" your broadcaster id, "sources" \[ { "primary" true, "source id" sourceid } ] }) data = client make request("post", endpoint, payload) channelid = data\['result']\['id'] print(f"create pass through channel id {channelid}") \######################################### \# create udp target (2) \######################################### endpoint = "/targets/udp rtp" payload = json dumps({ "name" "test target python", "resource tag ids" \[ your tag id ], "alerting profile id" your alerting profile id, "rtp" false, "host" "127 0 0 1", "port" 5001, "passthrough channel id" channelid }) data = client make request("post", endpoint, payload) \######################################### \# end \######################################### as with the postman requests, you will need to replace the all caps values with your own (but not the source and channel ids, as the script captures those from the responses) see the first section under postman instructions above to get the tag, alerting profile, cluster, and broadcaster ids note that the first two sections of the script define a class for submitting requests and parsing responses, and then to define the zen master envoronment the sections after that define the endpoints and request bodies for each request, and then invoke the client object to make the request you can run the script in on a command line by navigating to the folder where saved the edited script and running python3 {script name} py you may need to install the python requests and/or json modules, which the script imports