# API call with script getting IOError: no protocol

**URL:** <https://forum.inductiveautomation.com/t/api-call-with-script-getting-ioerror-no-protocol/57043>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [March 10, 2022, 1:53am UTC](https://forum.inductiveautomation.com/t/api-call-with-script-getting-ioerror-no-protocol/57043 "2022-03-10T01:53:58Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luke\_Abraams](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@Luke\_Abraams](https://forum.inductiveautomation.com/u/Luke_Abraams)\
**Post date:** [March 10, 2022, 1:53am UTC](https://forum.inductiveautomation.com/t/api-call-with-script-getting-ioerror-no-protocol/57043/1 "2022-03-10T01:53:58Z")

</div>

Hi I am new to Ignition and trying to learn quickly. I am currently trying to figure out the formatting needed to post API calls with rest via script. Currently I am getting an error when I execute the script and I can’t quite figure out what I have incorrect. Below is my script being used. Followed by the error I am receiving. Any ideas on what I have incorrect?

```auto
import pprint

pp = pprint.PrettyPrinter(indent=4)
headers = {
#Request headers
    'Content-Type': 'application/json',
    'Ocp-Apim-Subscription-Key': 'MYSubscriptionKEY',
}
body = {

    "resourceGroup": "Tugger",
    "location": "B05",
    "description": "Test with Python",
    "requestType": "Pull",
    "itemNo": "18308-TGZ-A030-21",
    "containerCount": 1 
}

#Get the json response from Cella
url = "https://api.cella-tech.com/RequestManagement/v1/ResourceGroup/Request", body, headers
CellaResponse = system.net.httpPost(url)
CellaJSON = system.util.jsonDecode(CellaResponse)

#print to see the response
print pp.pprint(CellaJSON)

```

```auto
Traceback (most recent call last):
  File "input", line 21, in module
IOError: no protocol: ('https://api.cella-tech.com/RequestManagement/v1/ResourceGroup/Request', {'resourceGroup': 'Tugger', 'requestType': 'Pull', 'description': 'Test with Python', 'itemNo': '18308-TGZ-A030-21', 'location': 'B05', 'containerCount': 1}, {'Ocp-Apim-Subscription-Key': 'MYSubscriptionKEY', 'Content-Type': 'application/json'})

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 10, 2022, 4:13am UTC](https://forum.inductiveautomation.com/t/api-call-with-script-getting-ioerror-no-protocol/57043/2 "2022-03-10T04:13:21Z")

</div>

Can you fix your post so that the code is posted with proper formatting?

Either enclose it in triple backticks or use the preformatted text editor control.

---

<div class="post-metadata">

**Author:** ![Luke\_Abraams](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@Luke\_Abraams](https://forum.inductiveautomation.com/u/Luke_Abraams)\
**Post date:** [March 10, 2022, 10:46pm UTC](https://forum.inductiveautomation.com/t/api-call-with-script-getting-ioerror-no-protocol/57043/3 "2022-03-10T22:46:24Z")

</div>

Hey @Kevin.Herron I have updated this now.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 10, 2022, 10:48pm UTC](https://forum.inductiveautomation.com/t/api-call-with-script-getting-ioerror-no-protocol/57043/4 "2022-03-10T22:48:14Z")

</div>

> [@Luke\_Abraams](#):
>
> `url = "https://api.cella-tech.com/RequestManagement/v1/ResourceGroup/Request", body, headers`

I'm not sure what you think this line is doing, but it's probably not what you think.

This turns the `url` variable into a tuple, which is not the argument expected by `httpPost`.

---

<div class="post-metadata">

**Author:** ![Luke\_Abraams](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@Luke\_Abraams](https://forum.inductiveautomation.com/u/Luke_Abraams)\
**Post date:** [March 10, 2022, 11:28pm UTC](https://forum.inductiveautomation.com/t/api-call-with-script-getting-ioerror-no-protocol/57043/5 "2022-03-10T23:28:01Z")

</div>

Yea I have updated since then. Still getting a 400 error, I was just getting python down a little so the changes with the jython are getting me. Below is my current that I get a 400 return response. Below that is my python that works correctly though. I am not sure what is sending differently that it doesn’t like the post.

```auto
import pprint
pp = pprint.PrettyPrinter(indent=4)

headerValues = {
# Request headers

    'Content-Type': 'application/json',

    'Ocp-Apim-Subscription-Key': 'MySubscriptionKey',

} 

postData = "{'resourceGroup': 'Tugger','location': 'B05','description': 'Test with Python','requestType': 'Pull','itemNo': '18308-TGZ-A030-21','containerCount': 1 }"

# get the json response from Cella
url = "https://api.cella-tech.com/RequestManagement/v1/ResourceGroup/Request"

#CellaResponse = system.net.httpPost(url, "application/json", postData, 10000, 60000, "", "", headerValues)
CellaResponse = system.net.httpPost(url, "application/json", postData, 10000, 60000, "", "", headerValues, "false")

CellaJSON = system.util.jsonDecode(CellaResponse)

#print to see the response
print pp.pprint(CellaJSON)

```

```auto
import http.client
import json

connection = http.client.HTTPSConnection('api.cella-tech.com', 443, timeout=30)

headers = {'Content-type': 'application/json','Cache-Control': 'no-cache','Ocp-Apim-Subscription-Key': 'MySubscriptionKey'}

data = {

    "resourceGroup": "Tugger",

    "location": "B05",

    "description": "Test with Python",

    "requestType": "Pull",

    "itemNo": "18308-TGZ-A030-21",

    "containerCount": 1 

}

 

json_data = json.dumps(data)

connection.request('POST', '/RequestManagement/v1/ResourceGroup/Request', json_data, headers)

response = connection.getresponse()

print(response.read().decode())

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 10, 2022, 11:50pm UTC](https://forum.inductiveautomation.com/t/api-call-with-script-getting-ioerror-no-protocol/57043/6 "2022-03-10T23:50:23Z")

</div>

> [@Luke\_Abraams](#):
>
> ```auto
> postData = "{'resourceGroup': 'Tugger','location': 'B05','description': 'Test with Python','requestType': 'Pull','itemNo': '18308-TGZ-A030-21','containerCount': 1 }"
> 
> ```

I'm not sure JSON allows single quotes to be used...

You can put all this into a dictionary like you had before and then use `system.util.jsonEncode` to encode it as JSON.

---

<div class="post-metadata">

**Author:** ![Luke\_Abraams](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@Luke\_Abraams](https://forum.inductiveautomation.com/u/Luke_Abraams)\
**Post date:** [March 10, 2022, 11:57pm UTC](https://forum.inductiveautomation.com/t/api-call-with-script-getting-ioerror-no-protocol/57043/7 "2022-03-10T23:57:32Z")

</div>

> [@Kevin.Herron](#):
>
> system.util.jsonEncode

Thank you for the suggestion, sorry if I sound ignorant on this. Is the below how that would be done properly?

```auto
Data = "{'resourceGroup': 'Tugger','location': 'B05','description': 'Test with Python','requestType': 'Pull','itemNo': '18308-TGZ-A030-21','containerCount': 1 }"

postData = system.util.jsonEncode(Data)

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 10, 2022, 11:58pm UTC](https://forum.inductiveautomation.com/t/api-call-with-script-getting-ioerror-no-protocol/57043/8 "2022-03-10T23:58:51Z")

</div>

No, it would be like the body in your first post.

```auto
data = {
    "resourceGroup": "Tugger",
    "location": "B05",
    "description": "Test with Python",
    "requestType": "Pull",
    "itemNo": "18308-TGZ-A030-21",
    "containerCount": 1 
}

postData = system.util.jsonEncode(data)

```

---

<div class="post-metadata">

**Author:** ![Luke\_Abraams](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@Luke\_Abraams](https://forum.inductiveautomation.com/u/Luke_Abraams)\
**Post date:** [March 11, 2022, 12:03am UTC](https://forum.inductiveautomation.com/t/api-call-with-script-getting-ioerror-no-protocol/57043/9 "2022-03-11T00:03:12Z")

</div>

@Kevin.Herron Thank you! I think that was it, it posted successfully! I am sure I will have more questions along the way but this was huge for me. Thanks for pointing me the right way.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 11, 2022, 12:49am UTC](https://forum.inductiveautomation.com/t/api-call-with-script-getting-ioerror-no-protocol/57043/10 "2022-03-11T00:49:16Z")

</div>

You don’t specify your Ignition version, but most of 8.X and all of 8.1.X can use `system.net.httpClient`, which will take care of JSON encoding (of your outbound data) and decoding (of the inbound data) for you, e.g:

```auto
client = system.net.httpClient()

headers = {
    'Content-type': 'application/json',
    'Cache-Control': 'no-cache',
    'Ocp-Apim-Subscription-Key': 'MySubscriptionKey'
}

data = {
    "resourceGroup": "Tugger",
    "location": "B05",
    "description": "Test with Python",
    "requestType": "Pull",
    "itemNo": "18308-TGZ-A030-21",
    "containerCount": 1 
}

response = client.post('api.cella-tech.com' + '/RequestManagement/v1/ResourceGroup/Request', headers=headers, data=data)

if response.good:
    print response.json

```

---

<div class="post-metadata">

**Author:** ![Luke\_Abraams](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@Luke\_Abraams](https://forum.inductiveautomation.com/u/Luke_Abraams)\
**Post date:** [March 11, 2022, 12:57am UTC](https://forum.inductiveautomation.com/t/api-call-with-script-getting-ioerror-no-protocol/57043/11 "2022-03-11T00:57:05Z")

</div>

Thanks @paul-griffith I will keep that in mind. So far I have downloaded the current version which looks like 8.1.15. Once I am able to make/run some POC’s I will move on from running it on my laptop in demo mode. I will definitely keep this in mind during my testing. I was able to use your script above but had to add https:// to the start of the url or it gave an error of no protocol.
