Automating API calls

Hello,

how would I go about automating this process? For example a Video that needs to be replaced every Monday, because the mediaID changes every time a file is uploaded/replaced?

I guess the POST command can be done via a cronjob.

Iā€™d recommend using tags to identify your media record across revisions - during your weekly upload you can query for media with a particular tag, get the ID and issue the replace.

So /library?media=tag gets me the ID, how do I input that into my replace commad?

Can it be done in a single POST command and/or script?

One call? No.
One script? Yes

Youā€™d need to GET the mediaIDs with the required tag and then use those IDs in your POST call in the ā€˜oldMediaIdā€™ parameter.

Please also be advised that the documentation for deleting old revisions is wrong it should be deleteOldRevisions.

Apparently I am out of my depth with this, are their any good resources you would recommend on working with this type of API and scripting them?

So I am using the following in the Tests section, however it is not producing the EnvironmentVariable like it is supposed to:

var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("oldMediaIDrequest", jsonData.mediaId);

GET {{url}}/api//library?media=mmtv produces the following

[
    {
        "mediaId": 132,
        "ownerId": 1,
        "...

Postman is a tool for API testing and exploration - its been provided so people can see an example of how an API might function.

I donā€™t think weā€™ve tested using Postman to actually run a ā€œcompleteā€ script.

That being said, the response body is an array, so youā€™d probably want:

postman.setEnvironmentVariable("oldMediaIDrequest", jsonData[0].mediaId);

What programming language do you intend to use once you get this up and running?

Ah, yeah that works. Iā€™m leaning towards PHP, as I have no experience with Pythonā€¦ Thank you for your help so far!

1 Like