Azure Table service returns error 404 when I try to insert an entity even though the table exists.

Carlen Kaiser 20 Reputation points
2024-05-11T05:15:48.4766667+00:00

I have developed a working application In C# that inserts an entity into the specified table in azure storage. However I really want to be able do this in structured text from a TwinCat 3 PLC. Currently my Structured text code can successfully Query the table storage and return the tables in it. Create a new table with any given name, but I can't insert an entity to any of the existing tables. I just receive 404 Resource not found errors on all of them Even though they exist. My authentication is correct because it works for the other queries.

One frustrating thing is I can't view the physical request from TwinCat because of how the system works, so I can't compare it to the working C# code I built.
Is there any way to find out what the actual error is because the tables obviously exist, so 404 is just wrong.

Am I missing something?

Azure Table Storage
Azure Table Storage
An Azure service that stores structured NoSQL data in the cloud.
158 questions
0 comments No comments
{count} votes

Accepted answer
  1. Nehruji R 2,966 Reputation points Microsoft Vendor
    2024-05-15T14:36:47.85+00:00

    Hello Carlen Kaiser,

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this!

    Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer. Accepted answers show up at the top, resulting in improved discoverability for others.

    User's image

    Issue: Customer can't be able to insert an entity to any of the existing and new tables created.

    Error Message: receive 404 Resource not found errors

    Solution: On adding only, the required headers resolved the issue.

    the following headers are,

    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUri);

    request.Headers.Add("x-ms-date", date);

    request.Headers.Add("Authorization", authorizationHeader);

    request.Headers.Add("x-ms-version", "2020-08-04");

    request.Headers.Add("Accept", "application/json;odata=nometadata");

    request.Content = new StringContent(requestBody, Encoding.UTF8, "application/json");

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Nehruji R 2,966 Reputation points Microsoft Vendor
    2024-05-13T09:14:36.1666667+00:00

    Hello Carlen Kaiser,

    Greetings! Welcome to Microsoft Q&A Platform.

    I understand that you are encountering a 404 error when trying to insert an entity into existing tables in Azure Table Storage from your TwinCat 3 PLC. The 404 error indicates that the resource (in this case, the table) was not found. Double-check the table names, keys, and ensure that the table exists in the specified storage account.

    • First, verify that the entities you’re trying to insert don’t already exist in the table. In Azure Table Storage, the combination of the Partition Key and Row Key acts as a primary key, so duplicate entries with the same keys will cause a conflict. Ensure that the combination of Partition Key and Row Key is unique for each entity.
    • Partition Key and Row Key Format: Confirm that you’re using the correct format for the Partition Key and Row Key. For example, if you’re using date time values, ensure they’re formatted correctly. Incorrectly formatted keys could lead to a 404 error.
    • InsertOrReplace Operation: Consider using the InsertOrReplace operation instead of Insert. This operation inserts the entity if it doesn’t exist or replaces it if it does. Be aware that it doesn’t check eTags, so use it carefully. refer - https://learn.microsoft.com/en-us/rest/api/storageservices/insert-or-replace-entity for more details.
    • Ensure that your TwinCat 3 PLC can communicate with Azure Table Storage. Check for any network issues, firewalls, or security settings that might prevent successful communication.

    Hope this answer helps! Please let us know if you have any further queries. I’m happy to assist you further.


    Please "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.


  2. Carlen Kaiser 20 Reputation points
    2024-05-15T14:26:11.23+00:00

    Update. I solved this myself. I was not sending all the required headers with the request. It would be hugely helpful if the error said something about headers and not just resource not found. The Error message as it is now, is incredibly misleading and I wasted a lot of time. These are the headers I needed.

    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUri);

    request.Headers.Add("x-ms-date", date);

    request.Headers.Add("Authorization", authorizationHeader);

    request.Headers.Add("x-ms-version", "2020-08-04");

    request.Headers.Add("Accept", "application/json;odata=nometadata");

    request.Content = new StringContent(requestBody, Encoding.UTF8, "application/json");

    0 comments No comments