# How to write tag from external code

**URL:** <https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991>\
**Category:** Ignition\
**Created:** [August 22, 2024, 5:59am UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991 "2024-08-22T05:59:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrd](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jrd](https://forum.inductiveautomation.com/u/jrd)\
**Post date:** [August 22, 2024, 5:59am UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991/1 "2024-08-22T05:59:52Z")

</div>

What steps do I need to take to write an Ignition tag from external (python) code?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 22, 2024, 6:31am UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991/2 "2024-08-22T06:31:30Z")

</div>

By external, you mean outside of ignition ?

Use webdev and setup an API.

---

<div class="post-metadata">

**Author:** ![jrd](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jrd](https://forum.inductiveautomation.com/u/jrd)\
**Post date:** [August 22, 2024, 7:35am UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991/3 "2024-08-22T07:35:26Z")

</div>

Thank you  
I have not used web dev so I will need to do some investigating

---

<div class="post-metadata">

**Author:** ![jrd](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jrd](https://forum.inductiveautomation.com/u/jrd)\
**Post date:** [August 31, 2024, 4:09am UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991/4 "2024-08-31T04:09:39Z")

</div>

Could you (or anyone) point me to an example  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 31, 2024, 7:20am UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991/5 "2024-08-31T07:20:58Z")

</div>

Using webdev ?

Expose a POST endpoint that will receive the tag path and its value through the request's data, then use these with `system.tag.readBlocking`.

I have an edge project that's just for that, but a bit more complicated so I can't give you the code as an example. It also takes lists to update multiple tags at once.

Basically, it would look something like this:

```python
def doPost(request, session):
	path = request['data']['path']
	value = request['data']['value']
	ret = system.tag.writeBlocking([path], [value])
	return {'json': {'result': ret}}

```

---

<div class="post-metadata">

**Author:** ![jrd](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jrd](https://forum.inductiveautomation.com/u/jrd)\
**Post date:** [August 31, 2024, 10:49am UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991/6 "2024-08-31T10:49:51Z")

</div>

Thank you Pascal

What I don’t get is what is on the Python (non-Ignition) side

Regards

Ross Dye

0400669880

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [August 31, 2024, 3:04pm UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991/7 "2024-08-31T15:04:27Z")

</div>

it will be a url with parameters.

/projectName/NameOfDoPostPage?path='path/to/Tag'.,value=ValueToWrite

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 1, 2024, 4:17pm UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991/8 "2024-09-01T16:17:50Z")

</div>

If the endpoint's method is POST and he's pulling data from `request.data`, I think he'll have to pass the payload in the request's body.

something like

```python
import requests

url = 'your endpoint's address'
payload = {
  'path': "tag path",
  'value': "some value"
}
requests.post(
  url=url,
  json=payload
)

```

@jrd It doesn't have to be python. That's the point of a web API: the only thing you need is an url and the proper format for the payload. You can test it with postman or any other tool you like. You can send your requests with a python script, or a java application, or any other language.  
You can even send your requests directly from a terminal with something like

```bash
curl -X POST -d '{"path": "tag path", "value": "some value"}' your_endpoint_url

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [September 1, 2024, 8:17pm UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991/9 "2024-09-01T20:17:41Z")

</div>

Hi, jrd. Please see [Keep it tidy](https://forum.inductiveautomation.com/faq#keep-tidy) on the forum FAQ. It has some regulations regarding signatures in forum posts.

---

<div class="post-metadata">

**Author:** ![jrd](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jrd](https://forum.inductiveautomation.com/u/jrd)\
**Post date:** [September 3, 2024, 5:08am UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991/10 "2024-09-03T05:08:06Z")

</div>

Sorry @transistor  
I simply replied to an email in my inbox  
Shan't be doing that again!

---

<div class="post-metadata">

**Author:** ![jrd](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jrd](https://forum.inductiveautomation.com/u/jrd)\
**Post date:** [September 3, 2024, 5:30am UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991/11 "2024-09-03T05:30:22Z")

</div>

Sorry guys, I remain confused. It is a state with which I am familiar !  
I have not previously used WebDev. I have read the doco and the posts above, and I have not changed state! I remain confused.

I will try and state my needs a bit more clearly

I have an existing application written python. It is running on same server as Ignition Gateway. From time to time I would like this app to send notifications to Ignition. I would like these notifications to be text (likely with embedded integers). These notifications would then be displayed in certain pages in Perspective sessions. I do not require a response returned from Ig to the app (but that could be useful later)

I figure that the best way to do this communication would be via Ig tags, ie send a message (post?) to Ig, read the message in WebDev, write data to Ignition tag(s), then display on a Perspective page in appropriate component, label, table or whatever. I can manage that bit !!

So in my python app I do as suggested above, ie specify url, payload etc.  
but this line fails:

```python
import requests

```

where do I import 'requests' from?

Secondly, I don't understand why I would need

```python
def doPost(....

```

On the Ignition side, wouldn't I be waiting for a "Post", from external and so use doGet?

Thanks and confused  
jrd

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 3, 2024, 6:24am UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991/12 "2024-09-03T06:24:24Z")

</div>

ALL endpoints are waiting for incoming requests. The different methods are used for different things.  
To make things simple, let's see the 4 main methods:

- get is used to ask the server for data.
- post is used to ask the server to add data
- delete is used to delete data
- put is used to update data

The method used by both the client and the server need to match. You can't catch a post with a get.  
I suggest you dive a bit deeper and read some docs on APIs to understand why we use different methods, but the simple answer is: this allows to use the same url for different operations, and to put different access rights on each of them.

So, you want to change a tag value in ignition, from a python script.  
In this case, ignition is the server, and the external script is the client.  
The client will ask the server to do something, through a request on your configured endpoint (url + method).  
Since you're asking ignition to change things on its side, you'll need either a post or a put method.  
Which one you use doesn't really matter in the end, so I suggested post. This matches the intent of "sending notifications".

if you can't import `requests` in your script, then you're not using a compatible version.  
You can try `urllib3` instead. Or you can tell us exactly what version of python you're using, and maybe with which interpreter - not all interpreters accept the same libraries. For example, ignition's python is actually Jython, built on Java, and as such cannot use libraries built for C python.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 3, 2024, 11:51am UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991/13 "2024-09-03T11:51:33Z")

</div>

How long is this existing application in python? Less than a few hundred lines of code? If so, I would translate it to Ignition Jython.

---

<div class="post-metadata">

**Author:** ![jrd](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jrd](https://forum.inductiveautomation.com/u/jrd)\
**Post date:** [September 3, 2024, 11:24pm UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991/14 "2024-09-03T23:24:43Z")

</div>

it is 15+ modules each 150-20 lines  
But size is not the issue.  
The application uses a couple of essential libraries that do not run in Jython

Thanks

---

<div class="post-metadata">

**Author:** ![jrd](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jrd](https://forum.inductiveautomation.com/u/jrd)\
**Post date:** [September 6, 2024, 6:02am UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991/15 "2024-09-06T06:02:51Z")

</div>

THANK YOU !! for the clarifications  
I will try this in the next few days and advise  
Thanks again !

---

<div class="post-metadata">

**Author:** ![jrd](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jrd](https://forum.inductiveautomation.com/u/jrd)\
**Post date:** [September 13, 2024, 8:29am UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991/16 "2024-09-13T08:29:15Z")

</div>

Thanks sir  
Can you advise what 'NameOfDoPostPage?' is in your reply?  
Is this the name of the Web Dev resource?  
And when I create this resource, I assume I create a Python resource?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 13, 2024, 8:55am UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991/17 "2024-09-13T08:55:20Z")

</div>

Yes you'll need a python resource for this.

To get the url of your endpoint, right click on it in the project browser, and select "copy mounted path"

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/2/121ac7b8d241840de48985a4434a56b7bf0e9ead.png)

It will give you something that looks like this:  
`/system/webdev/{project_name}/{ressource_name}`

Append this to your gateway's address to get the full url:  
example with a local dev gateway, a webdev resource named 'foo' on a project named sandbox:  
`http://localhost:8088/system/webdev/sandbox/foo`

---

<div class="post-metadata">

**Author:** ![jrd](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jrd](https://forum.inductiveautomation.com/u/jrd)\
**Post date:** [September 13, 2024, 12:45pm UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991/18 "2024-09-13T12:45:26Z")

</div>

Great, thank you. Progress... now I don't get a timeout in my Python application  
But the Ig tag does not get written.  
My Python (external app) code is:

```python
import requests
url = 'http://localhost:8088/system/webdev/F3_Scheduler/writeTag'
payload = {
  'path': "[Sample_Tags]F3/TextTag1",
  'value': "my new value"
}
requests.post(
  url=url,
  json=payload
)ype or paste code here

```

and my Web Dev code:

```python
type or paste code herdef doPost(request, session):
	path = request['data']['path']
	value = request['data']['value']
	ret = system.tag.writeBlocking([path], [value])
	return {'json': {'result': ret}}

```

What is the missing piece?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 13, 2024, 12:49pm UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991/19 "2024-09-13T12:49:26Z")

</div>

Add some logging to your WebDev code so you can see what you are getting for `path` and `value`.

---

<div class="post-metadata">

**Author:** ![jrd](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jrd](https://forum.inductiveautomation.com/u/jrd)\
**Post date:** [September 14, 2024, 7:14am UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991/20 "2024-09-14T07:14:30Z")

</div>

Thank you to all who advised  
It is now ok

[Next page](https://forum.inductiveautomation.com/t/how-to-write-tag-from-external-code/94991.md?page=2)
