# Microsoft Azure REST API

**URL:** <https://forum.inductiveautomation.com/t/microsoft-azure-rest-api/42461>\
**Category:** Ignition\
**Created:** [January 20, 2021, 9:47pm UTC](https://forum.inductiveautomation.com/t/microsoft-azure-rest-api/42461 "2021-01-20T21:47:38Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonas.wells](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jonas.wells/32/24861_2.png) [@jonas.wells](https://forum.inductiveautomation.com/u/jonas.wells)\
**Post date:** [January 20, 2021, 9:47pm UTC](https://forum.inductiveautomation.com/t/microsoft-azure-rest-api/42461/1 "2021-01-20T21:47:38Z")

</div>

Hello all,

I have been recently using Azure Blob Storage to store and access data in an Ignition project. I have had success using a GET request to access the stored data. The issue I am having however is using a PUT request to upload data from Ignition. I believe I am having difficulty in constructing the authorization header, but I am not completely sure. I am currently receiving a 403 HTTP response code (meaning Client authorization is not acceptable I believe). Has anyone been able to successfully accomplish something similar?

Thanks

---

<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:** [January 20, 2021, 10:18pm UTC](https://forum.inductiveautomation.com/t/microsoft-azure-rest-api/42461/2 "2021-01-20T22:18:04Z")

</div>

What Ignition version are you using? Can you share any of your script so far?  
For a variety of reasons, I highly recommend [`system.net.httpClient()`](https://docs.inductiveautomation.com/display/DOC81/system.net.httpClient) for interacting with REST/web APIs.

---

<div class="post-metadata">

**Author:** ![jonas.wells](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jonas.wells/32/24861_2.png) [@jonas.wells](https://forum.inductiveautomation.com/u/jonas.wells)\
**Post date:** [January 28, 2021, 6:14pm UTC](https://forum.inductiveautomation.com/t/microsoft-azure-rest-api/42461/3 "2021-01-28T18:14:00Z")

</div>

The system.net.httpClient() is definitely something I have been using. The PUT request has been providing a 403 HTTP error as well as a compiling error that states ‘Content-Length’ is a restricted header (when included). The exact code I am using is included below:

```
import datetime
import hmac
import hashlib
import base64

storage_account_name = '...'
storage_account_key = '...'
container_name='...'
api_version = '2016-05-31'
request_time = datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')

string_params = {
    'verb': 'PUT',
    'Content-Encoding': '',
    'Content-Language': '',
    'Content-Length': '11',
    'Content-MD5': '',
    'Content-Type': 'text/plain; charset=UTF-8',
    'Date': '',
    'If-Modified-Since': '',
    'If-Match': '',
    'If-None-Match': '',
    'If-Unmodified-Since': '',
    'Range': '',
    'CanonicalizedHeaders': 'x-ms-blob-type:BlockBlob' + '\nx-ms-date:' + request_time + '\nx-ms-version:' + api_version + '\n',
    'CanonicalizedResource': '/' + storage_account_name +'/'+container_name+ '/' +'fname'
}

string_to_sign = (string_params['verb'] + '\n' 
                  + string_params['Content-Encoding'] + '\n'
                  + string_params['Content-Language'] + '\n'
                  + string_params['Content-Length'] + '\n'
                  + string_params['Content-MD5'] + '\n' 
                  + string_params['Content-Type'] + '\n' 
                  + string_params['Date'] + '\n' 
                  + string_params['If-Modified-Since'] + '\n'
                  + string_params['If-Match'] + '\n'
                  + string_params['If-None-Match'] + '\n'
                  + string_params['If-Unmodified-Since'] + '\n'
                  + string_params['Range'] + '\n'
                  + string_params['CanonicalizedHeaders']
                  + string_params['CanonicalizedResource'])

signed_string = base64.b64encode(hmac.new(base64.b64decode(storage_account_key), msg=string_to_sign.encode('utf-8'), digestmod=hashlib.sha256).digest()).decode()

headerVals = {
    'x-ms-version' : api_version,
    'x-ms-date' : request_time,
    'x-ms-blob-type': 'BlockBlob',
    'Content-Type': "text/plain; charset=UTF-8",
    'Authorization' : ('SharedKey ' + storage_account_name + ':' + signed_string),
    'Content-Length': '11'
}

urlCurr = ('https://' + storage_account_name + '.blob.core.windows.net/'+container_name+'/fname')

putData = 'hello world'

# Create the JythonHttpClient
client = system.net.httpClient()

response = client.put(url=urlCurr, data=putData, headers=headerVals)
```

---

<div class="post-metadata">

**Author:** ![jonas.wells](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jonas.wells/32/24861_2.png) [@jonas.wells](https://forum.inductiveautomation.com/u/jonas.wells)\
**Post date:** [June 8, 2021, 6:39pm UTC](https://forum.inductiveautomation.com/t/microsoft-azure-rest-api/42461/4 "2021-06-08T18:39:19Z")

</div>

BUMP

I noticed that about a week ago a nightly fix was uploaded to the HTTP client POST function. The fix was aimed at resolving corruption when posting binary data. As seen in this post, I am using a PUT request and still seem to observe some data corruption on the byte arrays that I have been using (ie Content-Length is still incorrect). Has anybody been able to find a functional work-around or have any insight into how to resolve this problem? Also, is it possible that the bug identified in the POST function exists in the PUT function as well?

---

<div class="post-metadata">

**Author:** ![tmahaffey](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tmahaffey/32/30949_2.png) [@tmahaffey](https://forum.inductiveautomation.com/u/tmahaffey)\
**Post date:** [November 18, 2021, 5:53pm UTC](https://forum.inductiveautomation.com/t/microsoft-azure-rest-api/42461/5 "2021-11-18T17:53:38Z")

</div>

I wonder if Microsoft’s Python library for Azure blobs is compatible with ignition (always a question of whether it is a C-based library)

[https://docs.microsoft.com/en-us/python/api/overview/azure/storage-blob-readme?view=azure-python](https://docs.microsoft.com/en-us/python/api/overview/azure/storage-blob-readme?view=azure-python)

That would certainly help. It’s also a bummer that this thread went dead. I’m looking for answers on this as well.

---

<div class="post-metadata">

**Author:** ![jonas.wells](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jonas.wells/32/24861_2.png) [@jonas.wells](https://forum.inductiveautomation.com/u/jonas.wells)\
**Post date:** [January 10, 2022, 5:42pm UTC](https://forum.inductiveautomation.com/t/microsoft-azure-rest-api/42461/6 "2022-01-10T17:42:35Z")

</div>

So I was actually able to get the API call to work. The C-based library compatibility presented itself as an issue when trying to use the Microsoft provided functions. The API call however uses generic libraries/functions, provided by ignition, for HTTP requests. A solution that worked for me was using the PUT BLOB call of the Azure Cloud Storage. The file intended for upload needed to be split up into smaller chunks and uploaded independently. After that I was able to upload and download to the Azure Cloud.

Here is some documentation on how to do this: [Put Blob (REST API) - Azure Storage | Microsoft Docs](https://docs.microsoft.com/en-us/rest/api/storageservices/put-blob)

---

<div class="post-metadata">

**Author:** ![scottmwyant](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/scottmwyant/32/66369_2.png) [@scottmwyant](https://forum.inductiveautomation.com/u/scottmwyant)\
**Post date:** [January 11, 2022, 2:53am UTC](https://forum.inductiveautomation.com/t/microsoft-azure-rest-api/42461/7 "2022-01-11T02:53:39Z")

</div>

Worth mentioning for future readers that Postman is a phenomenal tool for testing APIs. See [https://www.postman.com/](https://www.postman.com/). Using a tool like this will help you clarify whether the request itself is set up right.

---

<div class="post-metadata">

**Author:** ![Trent.Boudreaux](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/trent.boudreaux/32/4138_2.png) [@Trent.Boudreaux](https://forum.inductiveautomation.com/u/Trent.Boudreaux)\
**Post date:** [January 28, 2022, 5:12pm UTC](https://forum.inductiveautomation.com/t/microsoft-azure-rest-api/42461/8 "2022-01-28T17:12:26Z")

</div>

I just wanted to thank you for posting this. It was very helpful in quick-starting Azure Blob Storage interaction. I had to remove ‘Content-Length’ from headerVals, but otherwise it worked perfectly!

---

<div class="post-metadata">

**Author:** ![Steven\_Oosterbosch](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@Steven\_Oosterbosch](https://forum.inductiveautomation.com/u/Steven_Oosterbosch)\
**Post date:** [February 15, 2022, 6:21pm UTC](https://forum.inductiveautomation.com/t/microsoft-azure-rest-api/42461/9 "2022-02-15T18:21:21Z")

</div>

Hi everybody,

At our company we are moving our ERP-system from onprem to the Azure cloud. We are planning to connect with Busines Central (BC) through webservices (API’s). At the moment we use almost standard query’s for everything.

But I have only limited knowledge regarding connecting to the cloud. I have been told BC will use OAuth2.0 authentication. In Postman I was able to connect to the test cloud environment. But is there somewhere I can get information on how to perform this trick in Ignition?

Thanks in advance!

KR,  
Steven

---

<div class="post-metadata">

**Author:** ![jonas.wells](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jonas.wells/32/24861_2.png) [@jonas.wells](https://forum.inductiveautomation.com/u/jonas.wells)\
**Post date:** [February 15, 2022, 8:15pm UTC](https://forum.inductiveautomation.com/t/microsoft-azure-rest-api/42461/10 "2022-02-15T20:15:35Z")

</div>

I am unsure of the exact solution you would need, as I have never worked with BC before. I suspect that you could build out a template for API connections and use Ignitions scripting functions to establish that connection. The template would look something like the code posted above, but it would include only the information provided by the MS documentation. I have included one of the more general landing pages for such documentation that I briefly looked through.

[Business Central API Overview - Microsoft Graph | Microsoft Docs](https://docs.microsoft.com/en-us/graph/dynamics-business-central-concept-overview)

---

<div class="post-metadata">

**Author:** ![Steven\_Oosterbosch](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@Steven\_Oosterbosch](https://forum.inductiveautomation.com/u/Steven_Oosterbosch)\
**Post date:** [February 15, 2022, 8:23pm UTC](https://forum.inductiveautomation.com/t/microsoft-azure-rest-api/42461/11 "2022-02-15T20:23:12Z")

</div>

Jonas, thank you for the quick response.  
We do have an external partner for implementing the BC ERP-system. They have knowledge regarding the available API’s for BC.

I’ll try with modifying the code above you are referring to.

KR  
Steven

---

<div class="post-metadata">

**Author:** ![jonas.wells](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jonas.wells/32/24861_2.png) [@jonas.wells](https://forum.inductiveautomation.com/u/jonas.wells)\
**Post date:** [February 15, 2022, 8:29pm UTC](https://forum.inductiveautomation.com/t/microsoft-azure-rest-api/42461/12 "2022-02-15T20:29:59Z")

</div>

So the code pasted above is specifically for a Put Blob request into Azure. It may help guide you in replacing some of your standard queries you mentioned. In regards to establishing a simple connection, nearly all of the overall structure and library imports can be disregarded. I’m not all that familiar with 0Auth2.0 authentication, so it may be worth reading about its relationship to the services you need.

---

<div class="post-metadata">

**Author:** ![Steven\_Oosterbosch](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@Steven\_Oosterbosch](https://forum.inductiveautomation.com/u/Steven_Oosterbosch)\
**Post date:** [February 15, 2022, 8:32pm UTC](https://forum.inductiveautomation.com/t/microsoft-azure-rest-api/42461/13 "2022-02-15T20:32:55Z")

</div>

If I am correct 0Auth2 is implied from Q1 2022, so like “as we speak”. I don’t know much about it either. I was able to create an GET request to it in Postman. But now I need to translate this to Ignition.

I’ll keep you posted if it ever worked 🙂

---

<div class="post-metadata">

**Author:** ![Jelle\_Verstappen](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@Jelle\_Verstappen](https://forum.inductiveautomation.com/u/Jelle_Verstappen)\
**Post date:** [September 25, 2023, 7:14am UTC](https://forum.inductiveautomation.com/t/microsoft-azure-rest-api/42461/14 "2023-09-25T07:14:21Z")

</div>

Hi, I am currently running into the same issue. Was this resolved in Business Central / ERP? Or is there a workaround within Ignition?

---

<div class="post-metadata">

**Author:** ![tanda](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tanda/32/19154_2.png) [@tanda](https://forum.inductiveautomation.com/u/tanda)\
**Post date:** [December 29, 2023, 2:18am UTC](https://forum.inductiveautomation.com/t/microsoft-azure-rest-api/42461/15 "2023-12-29T02:18:30Z")

</div>

I know it's been quite some time but... Thank You!! I was able to get this working in a fraction of the time it would take to sort it by myself from scratch.

---

<div class="post-metadata">

**Author:** ![tanda](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tanda/32/19154_2.png) [@tanda](https://forum.inductiveautomation.com/u/tanda)\
**Post date:** [December 29, 2023, 2:19am UTC](https://forum.inductiveautomation.com/t/microsoft-azure-rest-api/42461/16 "2023-12-29T02:19:44Z")

</div>

Thanks for the comment. I was using the code above and was running into the same issue with Content-Length key in the headerVals
