# Sending API Value to a tag

**URL:** <https://forum.inductiveautomation.com/t/sending-api-value-to-a-tag/95841>\
**Category:** Ignition\
**Created:** [September 11, 2024, 11:02am UTC](https://forum.inductiveautomation.com/t/sending-api-value-to-a-tag/95841 "2024-09-11T11:02:30Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Filippos\_Onisiforou](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/filippos_onisiforou/32/68090_2.png) [@Filippos\_Onisiforou](https://forum.inductiveautomation.com/u/Filippos_Onisiforou)\
**Post date:** [September 11, 2024, 11:02am UTC](https://forum.inductiveautomation.com/t/sending-api-value-to-a-tag/95841/1 "2024-09-11T11:02:30Z")

</div>

Hi Guys , I would like your help , i have this API which i isolated a specific value as below the value 234.56

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/a/5aaf13699008474dbdea2cea578c594edc3ec287.png)

I want to send this value to a specific Tag and use it as a setpoint. How can i achieve this? Have anyone of you done something Similar ?  
Thank you in advance

---

<div class="post-metadata">

**Author:** ![Omer\_Faruk\_YALCIN1](https://avatars.discourse-cdn.com/v4/letter/o/977dab/32.png) [@Omer\_Faruk\_YALCIN1](https://forum.inductiveautomation.com/u/Omer_Faruk_YALCIN1)\
**Post date:** [September 11, 2024, 11:40am UTC](https://forum.inductiveautomation.com/t/sending-api-value-to-a-tag/95841/2 "2024-09-11T11:40:17Z")

</div>

![API](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/8/7805b5557ede005e02c47fcc48605699db073c75.png)  
Here is an example shows that how you can get the spesific data from api

---

<div class="post-metadata">

**Author:** ![Filippos\_Onisiforou](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/filippos_onisiforou/32/68090_2.png) [@Filippos\_Onisiforou](https://forum.inductiveautomation.com/u/Filippos_Onisiforou)\
**Post date:** [September 11, 2024, 11:55am UTC](https://forum.inductiveautomation.com/t/sending-api-value-to-a-tag/95841/3 "2024-09-11T11:55:41Z")

</div>

Hi Omer , i have got the specific data from the API. I want to use that specific value to write it in a Tag using it as a setpoint. Still thank you for your fast response to this thread.

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [September 11, 2024, 12:00pm UTC](https://forum.inductiveautomation.com/t/sending-api-value-to-a-tag/95841/4 "2024-09-11T12:00:27Z")

</div>

You would use the [system.tag.writeBlocking | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-writeBlocking) function.

```python
tagPaths = ['theTagToWrite']
values = [valueFromTheAPI]
result = system.tag.writeBlocking(tagPaths,values)

```

---

<div class="post-metadata">

**Author:** ![Filippos\_Onisiforou](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/filippos_onisiforou/32/68090_2.png) [@Filippos\_Onisiforou](https://forum.inductiveautomation.com/u/Filippos_Onisiforou)\
**Post date:** [September 11, 2024, 12:08pm UTC](https://forum.inductiveautomation.com/t/sending-api-value-to-a-tag/95841/5 "2024-09-11T12:08:23Z")

</div>

Thank you Bschroeder, im not sure in which area to write this code. can you give me some more details please?

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [September 11, 2024, 12:21pm UTC](https://forum.inductiveautomation.com/t/sending-api-value-to-a-tag/95841/6 "2024-09-11T12:21:42Z")

</div>

Typically, you would make the call out a HTTP end point in a script, process the data and then write it to the tags.

You can do that in a button, timer script etc...

So let's start from the beginning.

How/where are you calling the API?

---

<div class="post-metadata">

**Author:** ![Filippos\_Onisiforou](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/filippos_onisiforou/32/68090_2.png) [@Filippos\_Onisiforou](https://forum.inductiveautomation.com/u/Filippos_Onisiforou)\
**Post date:** [September 11, 2024, 12:32pm UTC](https://forum.inductiveautomation.com/t/sending-api-value-to-a-tag/95841/8 "2024-09-11T12:32:15Z")

</div>

I took A Text Display i added the binding Type HTTP and then i isolated the required value i want to use as a setpoint

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/2/622df4abd5eebdc779bebf5bd4bf26b6e47abb1f.png)  
required value  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/2/629d36c2da9ee44460762acfe19171ef4ccd5e6c.png)

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [September 11, 2024, 12:34pm UTC](https://forum.inductiveautomation.com/t/sending-api-value-to-a-tag/95841/9 "2024-09-11T12:34:39Z")

</div>

So... if that page isn't open then what do you want to happen? If you are only reading this on that page via a binding, then when that page isn't open then nothing will be happening.

---

<div class="post-metadata">

**Author:** ![Filippos\_Onisiforou](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/filippos_onisiforou/32/68090_2.png) [@Filippos\_Onisiforou](https://forum.inductiveautomation.com/u/Filippos_Onisiforou)\
**Post date:** [September 11, 2024, 12:39pm UTC](https://forum.inductiveautomation.com/t/sending-api-value-to-a-tag/95841/10 "2024-09-11T12:39:49Z")

</div>

Lets say this value 234.56 i want to write it on this tag which is a Register on PLC. the communication is a Modbus TCP  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/4/44ce4b7942e7d0bf0506013aad30898cac8a111b.png)

is it possible ?

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [September 11, 2024, 12:49pm UTC](https://forum.inductiveautomation.com/t/sending-api-value-to-a-tag/95841/11 "2024-09-11T12:49:47Z")

</div>

Of course it is possible.

However, if you are reading this value just into a label on a view, and that view isn't open then the API is being called to get the new value.

So you need to move your logic to access the API data to a gateway timer script and use the [system.net.httpClient | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-net/system-net-httpClient) scripting function to get the data, process that value and then write it to the tag you want via the system.tag.writeBlocking function.

---

<div class="post-metadata">

**Author:** ![Filippos\_Onisiforou](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/filippos_onisiforou/32/68090_2.png) [@Filippos\_Onisiforou](https://forum.inductiveautomation.com/u/Filippos_Onisiforou)\
**Post date:** [September 11, 2024, 1:00pm UTC](https://forum.inductiveautomation.com/t/sending-api-value-to-a-tag/95841/12 "2024-09-11T13:00:22Z")

</div>

I understand but my knowledge on this is very limited , i would be kindly ask you to assist me on this please if you can and you have the time for it.

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [September 11, 2024, 1:20pm UTC](https://forum.inductiveautomation.com/t/sending-api-value-to-a-tag/95841/13 "2024-09-11T13:20:58Z")

</div>

Sure.

Put this into it's own project scripting library. Something like project.api

```python
httpAddress = "apiAddressHere"
tagPath = "fullTagPathHere"
# Create the JythonHttpClient.
client = system.net.httpClient()

def getSetpoint():
	# Sent a GET request.
	response = client.get(httpAddress)
	if response.good:
	    # Do something with the response
	    setpoint = response.json['nested1']['value1']
	    print setpoint #Comment out this line when it is working
	    #system.tag.writeBlocking(tagPaths=[tagPath], values=[setpoint]) #Un commend this line when it is working

```

Edit the httpAddress and tagPath details.

Then in your scripting console call the project script.

```python
project.api.getSetpoint()

```

You should get the setpoint from the API printed in the console.  
If you don't post the error here.

And once it is all working, comment the

```python
print setpoint

```

and uncomment the

```python
system.tag.writeBlocking

```

and run it again. Then your tag should change to that setpoint.

Once you have that going, then move the call to a Gateway timer script that runs at the pace you want it to run to update it on the frequency you want.

---

<div class="post-metadata">

**Author:** ![Filippos\_Onisiforou](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/filippos_onisiforou/32/68090_2.png) [@Filippos\_Onisiforou](https://forum.inductiveautomation.com/u/Filippos_Onisiforou)\
**Post date:** [September 11, 2024, 1:29pm UTC](https://forum.inductiveautomation.com/t/sending-api-value-to-a-tag/95841/14 "2024-09-11T13:29:41Z")

</div>

thank you but how do i check if this is working see below

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/e/bef61ee963ac58e7fd69a506432a597ac3bdc7ef.png)

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [September 11, 2024, 1:35pm UTC](https://forum.inductiveautomation.com/t/sending-api-value-to-a-tag/95841/15 "2024-09-11T13:35:32Z")

</div>

you could call this function in the script console

> [@bschroeder](#):
>
> Once you have that going, then move the call to a Gateway timer script that runs at the pace you want it to run to update it on the frequency you want.

or just put it in a timer immeadiatly

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [September 11, 2024, 1:51pm UTC](https://forum.inductiveautomation.com/t/sending-api-value-to-a-tag/95841/16 "2024-09-11T13:51:41Z")

</div>

I was babystepping it... 😃

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [September 11, 2024, 1:52pm UTC](https://forum.inductiveautomation.com/t/sending-api-value-to-a-tag/95841/17 "2024-09-11T13:52:46Z")

</div>

Save the project, open up the scripting console and run:

```python
Project_API.getSetpoint()

```

Make sure you are in read/write mode in designer.

---

<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 11, 2024, 1:53pm UTC](https://forum.inductiveautomation.com/t/sending-api-value-to-a-tag/95841/18 "2024-09-11T13:53:26Z")

</div>

I'd put `@system.util.runInGateway` above that library function, so your call from the designer script console will produce a valid gateway-scope test. 😁

(You could also return the result for printing/use by the caller.)

---

<div class="post-metadata">

**Author:** ![Filippos\_Onisiforou](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/filippos_onisiforou/32/68090_2.png) [@Filippos\_Onisiforou](https://forum.inductiveautomation.com/u/Filippos_Onisiforou)\
**Post date:** [September 13, 2024, 12:56pm UTC](https://forum.inductiveautomation.com/t/sending-api-value-to-a-tag/95841/19 "2024-09-13T12:56:18Z")

</div>

Hi Mate ,sorry for the late reply, Just to inform you that It did worked. See screenshot below. Much appreciated.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/4/34c6800b135d4a0959e0f3658eaf5a53dfc411ec.png)

Now i have to somehow be able to control this when to execute these values , and how to stop .
