question

RyanMatthes-8083 avatar image
0 Votes"
RyanMatthes-8083 asked NelsonJohnson-6239 answered

Logic Apps: HTTP action block not sending "Content-Type" header

We have a REST integration running between Microsoft's Logic Apps service (on Azure) and our NetSuite tenant. Logic Apps can perform REST operations to e.g. GET data from external services, such as NetSuite. For NetSuite to respond to the GET request, it needs to know how we want its response returned -- as XML, as JSON, etc. So in the request, I add a "Content-Type" header with a value of "application/JSON". NetSuite can then interpret that and send its data back as JSON.

Unfortunately it doesn't look like Logic Apps is actually sending out the "Content-Type" header, so NetSuite doesn't know how to respond, and our integration fails. I know Logic Apps isn't sending this header because as a test I redirected the request to point to a second Logic App, which just returns any headers it receives. Sure enough, no "Content-Type" header is being returned by that second Logic App. As another test, if I hit the second Logic App with a request sent via Postman, one that I've verified contains a "Content-Type" header, then the second Logic App shows it received my "Content-Type" header. I can only conclude my first Logic App isn't sending out the header I need it to.

This is not documented behavior. In fact as documented, it should be working -- see "Omitted HTTP headers" here: https://docs.microsoft.com/en-us/azure/connectors/connectors-native-http

azure-logic-apps
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello Ryan,

I am also trying to figure this one out.
I would expect this to be in the httprequestheaders class but I do not see it.
https://docs.microsoft.com/en-us/dotnet/api/system.net.http.headers.httprequestheaders?view=net-5.0

I am calling the TestRail REST API that requires this header.

If I use typescript, I can add the header without issue and the response is as expected.

So, how do I do this with .net 5?

0 Votes 0 ·

For your GET call add an Accept Header.

Header Name - Accept
Value - application/json

If Netsuite Api is robust enough, it should return you json data.

0 Votes 0 ·
MayankBargali-MSFT avatar image
0 Votes"
MayankBargali-MSFT answered RyanMatthes-8083 commented

Hi @RyanMatthes-8083

Can you please confirm if the HTTP request body JSON Schema doesn't have any value?
As the default value will be {} which represents that the request will be application/JSON.

I had some test with the logic app HTTP trigger for GET request and observed that when I have entered '{}' content in the request body of my HTTP trigger then I observed the same behaviour that you have mentioned. Removing this and testing with different content type I didn't observe any issue.

For POST request whatever Content-Type you are defined will be used.

Let me know if it helps and if you are still facing the issue.

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

For some reason I was unable to post my response as a comment off of your post, so I had to write a new Answer. Please check it out, and thank you for your help!

0 Votes 0 ·

Hi Mayank,

I'm back to this again today. I'm fairly certain I've found a Logic Apps bug and would really appreciate some help escalating!


Here's what I'm seeing. My raw HTTP request from Logic Apps (a GET):
53041-image.png


NetSuite responds with an error ("INVALID_RETURN_DATA_FORMAT"):
53011-image.png


It works if I try it via Postman:
53031-image.png


If I disable the Content-Type header, I get the error again:
53051-image.png



I must conclude that the Content-Type header of "application/json" is not being sent via Logic Apps to netSuite. A call with NetSuite support confirmed this.


My next comment will include several links indicating that the missing "Content-Type" header is causing this error.



0 Votes 0 ·
image.png (14.6 KiB)
image.png (39.7 KiB)
image.png (31.6 KiB)
image.png (43.1 KiB)
RyanMatthes-8083 avatar image
1 Vote"
RyanMatthes-8083 answered GregoryPinard-8499 edited

Thank you for your help, Mayank.

For POST request whatever Content-Type you are defined will be used.

That's not what I'm seeing, unfortunately. I'm POSTing from one Logic App to another 'receiving' Logic App in this test. The request body is empty.

Building:
46289-building-http-request.png

Executing:
46268-http-request-sent.png

Output:
46269-http-request-output.png


So no content-type is being sent on the request. The second 'receiving' Logic App shows no Content-Type in the headers it receives.
46219-http-request-received-no-ct-header.png


Compare that to this request sent to the same 'receiving' Logic App via Postman:
46169-http-request-received-ct-header.png


I can do another request with GETs if that would be helpful, just let me know.

Again, thank you for your help!


· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Content-Type is used to define the payload type. I believe you are looking for the Accept header instead?


0 Votes 0 ·

Hi Pramod,

Thank you so much for your insights. I'll admit that I'm not as knowledgeable about these things as I'd like to be, but from my research the community writ large believes my request is missing the Content-Type header, not the Accept header.

See:
- https://stackoverflow.com/questions/43525585/netsuite-restlet-error-code-invalid-return-data-format
- https://stackoverflow.com/questions/18321065/errors-when-trying-netsuites-restlet-interface-datain-is-null
- https://stackoverflow.com/questions/48799069/trying-to-get-netsuite-json-data-into-excel-via-restlet

All three have answers indicating a Content-Type header isn't being sent to NetSuite. There are many more too, these three just came up with Google. :)

This coincides with my own experience too. When I sent a request to NetSuite with the Content-Type header via Postman, NetSuite responds without issue. If I remove the Content-Type header, NetSuite gives an error.


0 Votes 0 ·

Hello @RyanMatthes-8083 , @PramodValavala-MSFT

I also had a similar issue with a POST request where the Content-Type Header I was sending was not received by the API, sending me back an incorrect data-type error.

Making my own tests with Logic Apps and Postman, I came under the conclusion that Logic Apps will ignore the Content-Type Header for a POST if the body is empty, as my API requested. On the other hand, it will include it if I put curly brackets as the body :
{
}

This solution satisfied my API, which now sends back the proper message.

I know it's late, but I hope this will also fix the issue for you.

EDIT : Having looked more into it, it seems that the API I was calling required that I specifically mention content-type: application/json, receiving "Invalid content type (application/octet-stream). These are valid: application/json" if I didn't specify it. Since I specified a content-type for the body, it had to contain a valid json payload, so either {} or [], as someone mentioned here : https://stackoverflow.com/questions/40614416/is-empty-body-correct-if-content-type-is-application-json

1 Vote 1 ·
JohnathanSeal-0210 avatar image
0 Votes"
JohnathanSeal-0210 answered JohnathanSeal-0210 commented

I am hoping the following code snip will help triage this issue:
public async Task<TestRailTestCase> getTestCase(int testcasenumber)
{
string url = getTestrailTestCaseUrlSnip().Replace("|id|", testcasenumber.ToString());

         client.DefaultRequestHeaders.Accept.Clear();

         client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(
         System.Text.ASCIIEncoding.ASCII.GetBytes(
            $"{getUserName()}:{getPassWord()}")));

         client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

         MediaTypeWithQualityHeaderValue mediaType = new MediaTypeWithQualityHeaderValue("application/json");

         var res = await client.GetAsync(url);

         string content = await res.Content.ReadAsStringAsync();

         var testCase = JsonSerializer.Deserialize<TestRailTestCase>(content);
         return testCase;
     }


gives:
content "{\"error\":\"Content-Type header missing (use Content-Type: application\\/json)\"}" string

So, where do you set this?


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@JohnathanSeal-0210 Are you using Logic Apps here?

0 Votes 0 ·

Hello Pramod,

Unlike Ryan, I am not using Logic Apps.
I am trying to get information out of TestRail.
The reason for the reply is that I suspected both Ryan and myself were having the same http header issue.

0 Votes 0 ·
jrobijn-6698 avatar image
2 Votes"
jrobijn-6698 answered jrobijn-6698 commented

This is still an issue and needs to be fixed.

I'm trying to query a 3rd party API that returns a 422 error if the application/json Content-Type header is not set and as of right now I'm simply unable to use Logic Apps to send recurring GET requests to this API.

During a test run Logic Apps tells me that it actually did send the Content-Type header as input, but the 3rd party API returns an error. Meanwhile, if I do a simple curl (on my laptop) to the API endpoint with -H "Content-Type: application/json" the API returns a proper result.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for weighing in. It looks like that that makes three of us who've noticed this. I wish MSFT would acknowledge the issue.

0 Votes 0 ·

For now, I just worked around the issue by creating a simple Python-based Azure Function (using a HTTP trigger) that queries the API for me with the correct Content-Type header.

Would be great if the issue can be resolved so I can replace all of this with a simple HTTP GET request connector again.

1 Vote 1 ·
RyanMatthes-8083 avatar image
1 Vote"
RyanMatthes-8083 answered

@MayankBargali-MSFT Just noticed I could @ you here! I wrote up a detailed response a few days ago, and noticed someone else chimed in today as well. Do you think you could take a look when you have the time?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RyanMatthes-8083 avatar image
0 Votes"
RyanMatthes-8083 answered RyanMatthes-8083 commented

@MayankBargali-MSFT Any update at all please?

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello Ryan,

I found this solution that works.

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "relativeAddress");
request.Content = new StringContent("{\"name\":\"John Doe\",\"age\":33}",
Encoding.UTF8,
"application/json");//CONTENT-TYPE header

Credit to carlosfigueira on stackoverflow

Ryan, can you please file a document task to get this solution into the knowledge base?

Thanks

0 Votes 0 ·

I'm sorry, I don't see how this applies to my particular logic app issue. This looks like a C# solution.

1 Vote 1 ·
TorArneGjelhus-3643 avatar image
0 Votes"
TorArneGjelhus-3643 answered

Hi

If i read the bottom section here https://docs.microsoft.com/en-us/azure/connectors/connectors-native-http#disable-location-header-check under known issues it seems to me that logic apps removed the content-type outbound without notification so what we see is as expected.
I was facing the same issue as you was and i guess i will have to make an azure function for my scenario

best regards
Tor Arne Gjelhus

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

TorArneGjelhus-3643 avatar image
0 Votes"
TorArneGjelhus-3643 answered TorArneGjelhus-3643 commented

Hi

I was facing he same issue and came here for a solution, but then i found this documentation: https://docs.microsoft.com/en-us/azure/connectors/connectors-native-http#known-issues

If i read this correctly logic apps removes content-type among other headers outbound without error.

best regards
Tor Arne Gjelhus

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

That same documentation also says it's supposed to make an exception for Content-Disposition, Content-Encoding, and Content-Type. The Content-Type header being removed is clearly not intended behaviour.



0 Votes 0 ·

@jrobijn-6698 Exactly right, this is clearly a bug and this forum is getting us no where. I created a bug here: https://github.com/MicrosoftDocs/azure-docs/issues/69469

Can you please help confirm this bug is real with a comment and help me get a little traction?


Also @TorArneGjelhus-3643 @JohnathanSeal-0210 @PramodValavala-MSFT @MayankBargali-MSFT

0 Votes 0 ·

Hi

Sorry seems like i cant read :)

Will confirm the bug.

TAG

0 Votes 0 ·
NelsonJohnson-6239 avatar image
0 Votes"
NelsonJohnson-6239 answered

I tested my logic app using https://postman-echo.com to figure out Content-Type was missing. This is still an issue and if not fixed, will require us to use 3rd party integration tools if MSFT does not address it. Why does MSFT impose their interpretation of the RFC on this when it limits the ability to use it? We are trying to work with a customer that has Java apps that use a framework that requires Content-Type on a GET. I don't care that the documentation says that this is the expected behavior. If we are going to use these tools in real-world applications, then they need to be flexible enough to deal with non-MS systems that have a different implementation. @PramodValavala-MSFT Why not just warn us that the header is not "MS-standard", but still allow it?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.