# Automating API calls

**URL:** https://community.xibo.org.uk/t/automating-api-calls/10513
**Category:** Developer Experience
**Created:** [June 21, 2017, 1:12pm UTC](https://community.xibo.org.uk/t/automating-api-calls/10513 "2017-06-21T13:12:02Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![abcdef0987](https://community.xibo.org.uk/letter_avatar_proxy/v4/letter/a/73ab20/32.png) [@abcdef0987](https://community.xibo.org.uk/u/abcdef0987)
#### Post date: [June 21, 2017, 1:12pm UTC](https://community.xibo.org.uk/t/automating-api-calls/10513/1 "2017-06-21T13:12:02Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dan](https://community.xibo.org.uk/user_avatar/community.xibo.org.uk/dan/32/9115_2.png) [@dan](https://community.xibo.org.uk/u/dan)
#### Post date: [June 22, 2017, 7:39am UTC](https://community.xibo.org.uk/t/automating-api-calls/10513/2 "2017-06-22T07:39:55Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![abcdef0987](https://community.xibo.org.uk/letter_avatar_proxy/v4/letter/a/73ab20/32.png) [@abcdef0987](https://community.xibo.org.uk/u/abcdef0987)
#### Post date: [June 27, 2017, 9:08am UTC](https://community.xibo.org.uk/t/automating-api-calls/10513/3 "2017-06-27T09:08:23Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Peter](https://community.xibo.org.uk/user_avatar/community.xibo.org.uk/peter/32/8154_2.png) [@Peter](https://community.xibo.org.uk/u/Peter)
#### Post date: [June 27, 2017, 11:38am UTC](https://community.xibo.org.uk/t/automating-api-calls/10513/4 "2017-06-27T11:38:13Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![abcdef0987](https://community.xibo.org.uk/letter_avatar_proxy/v4/letter/a/73ab20/32.png) [@abcdef0987](https://community.xibo.org.uk/u/abcdef0987)
#### Post date: [June 27, 2017, 12:35pm UTC](https://community.xibo.org.uk/t/automating-api-calls/10513/5 "2017-06-27T12:35:40Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![abcdef0987](https://community.xibo.org.uk/letter_avatar_proxy/v4/letter/a/73ab20/32.png) [@abcdef0987](https://community.xibo.org.uk/u/abcdef0987)
#### Post date: [June 27, 2017, 1:34pm UTC](https://community.xibo.org.uk/t/automating-api-calls/10513/6 "2017-06-27T13:34:13Z")

</div>

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,
        "...
```

---

<div class="post-metadata">

### Author: ![dan](https://community.xibo.org.uk/user_avatar/community.xibo.org.uk/dan/32/9115_2.png) [@dan](https://community.xibo.org.uk/u/dan)
#### Post date: [June 28, 2017, 6:55am UTC](https://community.xibo.org.uk/t/automating-api-calls/10513/7 "2017-06-28T06:55:59Z")

</div>

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:

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

```

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

---

<div class="post-metadata">

### Author: ![abcdef0987](https://community.xibo.org.uk/letter_avatar_proxy/v4/letter/a/73ab20/32.png) [@abcdef0987](https://community.xibo.org.uk/u/abcdef0987)
#### Post date: [June 28, 2017, 1:12pm UTC](https://community.xibo.org.uk/t/automating-api-calls/10513/8 "2017-06-28T13:12:10Z")

</div>

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