# Scripting HTTP GET request with authorization headers/tokens

**URL:** <https://forum.inductiveautomation.com/t/scripting-http-get-request-with-authorization-headers-tokens/95215>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [August 27, 2024, 3:35pm UTC](https://forum.inductiveautomation.com/t/scripting-http-get-request-with-authorization-headers-tokens/95215 "2024-08-27T15:35:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alfonso\_Lopez](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@Alfonso\_Lopez](https://forum.inductiveautomation.com/u/Alfonso_Lopez)\
**Post date:** [August 27, 2024, 3:35pm UTC](https://forum.inductiveautomation.com/t/scripting-http-get-request-with-authorization-headers-tokens/95215/1 "2024-08-27T15:35:11Z")

</div>

I am having issues with an http get request that I can get working using the http bindings but not when using scripting.

Below is a snapshot of the postman URL and headers:

Here's the code that I have. The getToken() functions works properly but the getSPP function gets the error that is also below:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/6/06cb32f4ebf511db35a2e65f2b54acf5952a536b.png)

Any help would be appreciated.

Thanks!

---

<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:** [August 27, 2024, 3:37pm UTC](https://forum.inductiveautomation.com/t/scripting-http-get-request-with-authorization-headers-tokens/95215/2 "2024-08-27T15:37:28Z")

</div>

> [@Alfonso\_Lopez](#):
>
> `client.get(fullUrl, {"Ocp-Apim-Subscription-Key": subscriptionKey, "Authorization":bearer})`

You need to be using named parameters here (even if that's not the issue, but try it).

```python
client.get(url=fullUrl, headers={"Ocp-Apim-Subscription-Key": subscriptionKey, "Authorization":bearer})
```

---

<div class="post-metadata">

**Author:** ![Alfonso\_Lopez](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@Alfonso\_Lopez](https://forum.inductiveautomation.com/u/Alfonso_Lopez)\
**Post date:** [August 27, 2024, 3:40pm UTC](https://forum.inductiveautomation.com/t/scripting-http-get-request-with-authorization-headers-tokens/95215/3 "2024-08-27T15:40:18Z")

</div>

That was it! Thank you, I appreciate the really quick response!

---

<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:** [August 27, 2024, 3:41pm UTC](https://forum.inductiveautomation.com/t/scripting-http-get-request-with-authorization-headers-tokens/95215/4 "2024-08-27T15:41:50Z")

</div>

You should probably invalidate this bearer token now that you've posted it publicly.

---

<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:** [August 27, 2024, 3:42pm UTC](https://forum.inductiveautomation.com/t/scripting-http-get-request-with-authorization-headers-tokens/95215/5 "2024-08-27T15:42:23Z")

</div>

I'd strongly recommend refactoring your script, for two main reasons:

1. You shouldn't be instantiating `httpClient` instances each time you call a project script. They're non-trivial to create, so this is slowing things down and potentially causing resource leaks. Move the call to `system.net.httpClient` out of the function definitions entirely so you can re-use it.
2. Take advantage of the fact that httpClient can encode URL parameters and headers for you, instead of manually assembling full URL strings. This makes maintenance _much_ easier:

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

def getToken():
    url = "https://"
    params = {
        "grant_type": "password",
        "username": "alfonso.lopez@example.com",
        "password": "",
        "response_type": "id_token",
        "scope": "openid+",
        "client_id": ""
    }

    response = client.post(url, params)
    return response.json["access_token"]

def getSPP(token):
    url = "https://example.com"
    params = {
        "deliveryDateFrom": "2024-08-25",
        "deliveryDateTo": "2024-08-26",
        "settlementPoint": "AMO_AMOCO_G1"
    }
    headers = {
        "Ocp-Apim-Subscription-Key": "",
        "Authorization": ("Bearer " + token)
    }

    response = client.get(url, params=params, headers=headers)

    return response.text

```

---

<div class="post-metadata">

**Author:** ![Alfonso\_Lopez](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@Alfonso\_Lopez](https://forum.inductiveautomation.com/u/Alfonso_Lopez)\
**Post date:** [August 27, 2024, 3:47pm UTC](https://forum.inductiveautomation.com/t/scripting-http-get-request-with-authorization-headers-tokens/95215/6 "2024-08-27T15:47:12Z")

</div>

Thank you for the upgrades and response. I'm sorry but as Kevin mentioned, I did not realize I had my information there such as email and the password. Any chance you could edit that and use fake ones?

Thank you!
