# API authentication for provisions

**URL:** https://forum.genieacs.com/t/api-authentication-for-provisions/1663
**Category:** Uncategorized
**Created:** [April 23, 2021, 7:01pm UTC](https://forum.genieacs.com/t/api-authentication-for-provisions/1663 "2021-04-23T19:01:30Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![rudymartin](https://avatars.discourse-cdn.com/v4/letter/r/919ad9/32.png) [@rudymartin](https://forum.genieacs.com/u/rudymartin)
#### Post date: [April 23, 2021, 7:01pm UTC](https://forum.genieacs.com/t/api-authentication-for-provisions/1663/1 "2021-04-23T19:01:30Z")

</div>

Hi all.

Short question: How can I push a provision script to GenieACS without using the GUI ?

Using the examples from the docs I was able to hack my way to paste curl code from the browser’ s debugger into bash and it works but it relies on a cookie for authorization which is not desirable in the long term.

> curl ‘[http://myACS:3000/api/provisions/otromas](http://myACS:3000/api/provisions/otromas)’   
> -X PUT   
> -H ‘Accept: application/json, text/\*’   
> -H ‘Origin: [http://myACS3000](http://myACS3000)’   
> -H ‘Referer: [http://myACS:3000/](http://myACS:3000/)’   
> -H ‘Cookie: genieacs-ui-jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiYXV0aE1ldGhvZCI6ImxvY2FsIiwiaWF0IjoxNjE3Mjg4ODAwfQ.W4hvrau1kYrFX3xQf8GAcgc5Y8DeuqR9phQG7nQ4H5M’   
> –compressed -H ‘Content-Type: application/json; charset=utf-8’   
> –data-raw ‘{“script”:“my provision script here”}’ ; echo

at the moment of writting this, it works, but I’m pretty sure it won’t once I close my browser. I could cheat it by using curl which involves saving a session cookie a file and reuse it later but I wonder if there’s a more elegant solution.

thank you.

---

<div class="post-metadata">

### Author: ![JonasGhost](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.genieacs.com/jonasghost/32/286_2.png) [@JonasGhost](https://forum.genieacs.com/u/JonasGhost)
#### Post date: [April 24, 2021, 8:01am UTC](https://forum.genieacs.com/t/api-authentication-for-provisions/1663/2 "2021-04-24T08:01:56Z")

</div>

[http://docs.genieacs.com/en/latest/api-reference.html#create-a-provision](http://docs.genieacs.com/en/latest/api-reference.html#create-a-provision)  
Maby that will help.

---

<div class="post-metadata">

### Author: ![rudymartin](https://avatars.discourse-cdn.com/v4/letter/r/919ad9/32.png) [@rudymartin](https://forum.genieacs.com/u/rudymartin)
#### Post date: [April 24, 2021, 1:02pm UTC](https://forum.genieacs.com/t/api-authentication-for-provisions/1663/3 "2021-04-24T13:02:27Z")

</div>

@JonasGhost sorry about not elaborating a bit more and I think I phrased my question wrong: “How can I update a provision without using GUI?”

yes, as I mentioned in my first post, I saw that section at the docs, but there’s also a related problem:

this works OK:

> curl -X PUT -i ‘[http://localhost:7557/provisions/mynewprovision](http://localhost:7557/provisions/mynewprovision)’ --data ‘log("Provision started at " + now);’

but this does not:

> curl -X PUT -i ‘[http://localhost:7557/provisions/mynewprovision](http://localhost:7557/provisions/mynewprovision)’ --data ‘log("Provision started \n at " + now);’

Notice the \n in the code. Also seems like there’s some regular exp parsing done by mongodb because I get keep getting errors like:

> SyntaxError: Invalid or unexpected token

which in turn lead me to the url in my first post. Seems to me the only “legal” way to update a provision would be to use a proper json document with the “script” tag, at least using GenieACS API. I could also connect directly to MongoDB but I think I will do better if don’t touch the db directly (just thinking aloud here while exploring options).

In case you wonder, final goal is to be able to edit provision externally (with some unit testing in place, that would be awesome) and have it in a git repository.

---

<div class="post-metadata">

### Author: ![JonasGhost](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.genieacs.com/jonasghost/32/286_2.png) [@JonasGhost](https://forum.genieacs.com/u/JonasGhost)
#### Post date: [April 25, 2021, 4:12pm UTC](https://forum.genieacs.com/t/api-authentication-for-provisions/1663/4 "2021-04-25T16:12:26Z")

</div>

I tried it with Postman and it worked without any problems.

Also pushing a file worked:  
`curl -X PUT -i "http://localhost:7557/provisions/mynewprovision1" --data-binary "@testFile"`

![image](https://canada1.discourse-cdn.com/flex035/uploads/genieacs/original/1X/8868644d074093f67c076517488bc08a5b71120f.png)  
I am running Genieacs 1.2.4

---

<div class="post-metadata">

### Author: ![rudymartin](https://avatars.discourse-cdn.com/v4/letter/r/919ad9/32.png) [@rudymartin](https://forum.genieacs.com/u/rudymartin)
#### Post date: [April 26, 2021, 1:29pm UTC](https://forum.genieacs.com/t/api-authentication-for-provisions/1663/5 "2021-04-26T13:29:22Z")

</div>

seems like I been doing all kinds of tests but that one. ty !

---

<div class="post-metadata">

### Author: ![JonasGhost](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.genieacs.com/jonasghost/32/286_2.png) [@JonasGhost](https://forum.genieacs.com/u/JonasGhost)
#### Post date: [April 26, 2021, 4:12pm UTC](https://forum.genieacs.com/t/api-authentication-for-provisions/1663/6 "2021-04-26T16:12:33Z")

</div>

It is an intresting toppic.

I am already storing my provisions in a git repository, but I have not created a Pipeline for that.

---

<div class="post-metadata">

### Author: ![rudymartin](https://avatars.discourse-cdn.com/v4/letter/r/919ad9/32.png) [@rudymartin](https://forum.genieacs.com/u/rudymartin)
#### Post date: [April 27, 2021, 12:51pm UTC](https://forum.genieacs.com/t/api-authentication-for-provisions/1663/7 "2021-04-27T12:51:19Z")

</div>

this script is no exactly rocket science. It’s something I saw while watching a video from Kent Beck and I have been doing it over the years for several different tasks:

> clear  
> inotifywait -m --format %w%f -q -r -e close\_write . …/tests |   
> while read CUAL  
> do  
> if [$? == 0]; then  
> clear  
> # TODO: unit testing ?  
> curl -X PUT -i ‘[http://acstest:7557/provisions/default](http://acstest:7557/provisions/default)’ --data-binary “@provision\_full\_path\_here.js”  
> fi  
> done

Place the script on the same dir as the provision or add a cd command to relocate to the path of the provision. Inotifywait will watch for changes on the files (parameter say “.” but it can be the provision filename). I ran the script from a console and leave it running on background. Each time I modify the provision file it’s automatically uploaded to the ACS.
