Error code 415 posting JSON messages

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
schrama@mmsn.nl
Posts: 4
Joined: Wed Aug 23, 2023 2:50 pm

Error code 415 posting JSON messages

Post by schrama@mmsn.nl »

Hi Team,

After installing latest PTF's last Sunday August 20 on our hosted IBM i Power 9 machine (OS: V7R4), we are facing error code 415 posting JSON messages to an external application (= Salesforce). As RPG ILE application involved was running smoothly before August 20, it is quite clear PTF activities must have caused error 415 is showing since. For the moment IBM software support is not able to help on this issue.

As I am not expercienced enough using HTTPAPI I may need some help or suggestions on this issue.

Regards,
Rob.
jonboy49
Posts: 206
Joined: Wed Jul 28, 2021 8:18 pm

Re: Error code 415 posting JSON messages

Post by jonboy49 »

What does the httpapi debug log show? There may be hints there
schrama@mmsn.nl
Posts: 4
Joined: Wed Aug 23, 2023 2:50 pm

Re: Error code 415 posting JSON messages

Post by schrama@mmsn.nl »

Thanks for replying, Jonboy49.

For the moment de debug log (see attachement) is indeed showing the specific error, but does not help me solving the issue.

Regards,
Rob.
Attachments
my_httpapi_log.zip
(4.82 KiB) Downloaded 396 times
schrama@mmsn.nl
Posts: 4
Joined: Wed Aug 23, 2023 2:50 pm

Re: Error code 415 posting JSON messages

Post by schrama@mmsn.nl »

Hello,

Examining the RPG ILE application I noticed the content-type was mentioned in the post instruction as well as in the header data settings. However the application ran smoothly before last weekend's PTF's were added, I am not sure whether it was obliged in the past to mention it twice. Anyway, by removing the content type from the header data setting the new (single) content type was accepted by the Salesforce application.

Although the issue is solved, we would like to know what can be the benifit of describing the content type in the header data settings as well. Please don't hesitate to let me know.

Regards,
Rob.
jonboy49
Posts: 206
Joined: Wed Jul 28, 2021 8:18 pm

Re: Error code 415 posting JSON messages

Post by jonboy49 »

Are you certain that no code changes have been made to your app? The debug log not only identifes the error as 415 (wrong media type) but the actual response from Saleforce very clearly identifies application/json as an unsupported type.

I can't see how the PTFs could have had any impact on that.

Have you checked with Postman or Insomnia etc. to see if you can get the correct response from Salesforce? Have Salesforce changed the API?

I also notice that you are using an old version of HTTPAPI although I can't see why that would have an impact in this case.
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: Error code 415 posting JSON messages

Post by Scott Klement »

Here are your request headers:

Code: Select all

POST /services/data/v46.0/composite/ HTTP/1.1
Host: mmsn.my.salesforce.com
User-Agent: http-api/1.45
Content-Type: application/json     <----- NOTE THIS
Content-Length: 1775
Authorization: Bearer 00D58000000Ij87!AQEAQBV.L3HRWkwqKccGu_jf3vSI1D5u6fNWUQ7Cdi3Q0xsOJ5Y3vR4FfrGELcIrIQfUH2xgrdPhrTQnySTey_owaltb0hT.
Content-Type: application/json   <----- NOTE THIS
Postman-Token: d71e9ff1-af1a-4495-a50b-ea24e6835a95
cache-control: no-cache
[/code]

Notice that you are sending the media type (aka "content-type") twice.

This is the response you're getting from the server:

Code: Select all

[{
	"message": "MediaType of 'application/json,application/json' is not supported by this resource",
	"errorCode": "UNSUPPORTED_MEDIA_TYPE"
}]
Notice that it likewise shows the media type twice -- this is the problem. You are sending it twice.

You are also sending a Postman-Token and cache-control header -- HTTPAPI does not add these headers, so they were added by your code. Probably you are also adding the content-type (in addition to the one that HTTPAPI does add) and that's why it's duplicated.

This has nothing whatsoever to do with an operating system upgrade. (HTTPAPI is not part of the operating system.) Someone added code to add these headers.

Also, having a postman-token header in an HTTPAPI call makes no sense. Postman-Token is something added by the Postman software to work around a bug in the Chrome web browser. You aren't using either Postman or Chrome -- so make makes absolutely no sense that this is here. Someone who didn't understand what they were doing added this code to your program, probably copying it from Postman.
schrama@mmsn.nl
Posts: 4
Joined: Wed Aug 23, 2023 2:50 pm

Re: Error code 415 posting JSON messages

Post by schrama@mmsn.nl »

Thank you all for responding.
Post Reply