Making post requests to external API in AEM author | Community
Skip to main content
stiegjo22
Level 4
October 9, 2024

Making post requests to external API in AEM author

  • October 9, 2024
  • 4 replies
  • 1367 views

We're trying to connect to a new external API for a custom servlet in AEM author but we're getting the following error:
Response: {"error":{"code":"404","message": "Resource not found"}}

 

We've added the excluded path to the Adobe Granite CRSF Filter and the allowed host to the Apache Sling Referrer Filter. Also we can make post requests to the API using Postman without any issues. Thanks for any advice.

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

4 replies

SureshDhulipudi
Community Advisor
Community Advisor
October 10, 2024

Do you see any error in console or error log? Did you try with GET method also, is that working?

can you please provide your Servlet class definition (how you defined) and how you are calling in HTL

 

above configurations are looking good

CSRF Filter and Referrer Filter

Add the servlet path /bin/mycustompost to the Adobe Granite CSRF Filter's excluded paths.

Add the external API host to the Apache Sling Referrer Filter's allowed hosts.

 

@Component(service = Servlet.class,
property = {
ServletResolverConstants.SLING_SERVLET_PATHS + "=/bin/mycustompost",
ServletResolverConstants.SLING_SERVLET_METHODS + "=" + HttpConstants.METHOD_POST
})
public class CustomPostServlet extends SlingAllMethodsServlet {


<form id="customPostForm">
<input type="text" name="key" placeholder="Enter value" required>
<button type="submit">Submit</button>
</form

<script>
document.getElementById('customPostForm').addEventListener('submit', function(event) {
event.preventDefault();
var formData = new FormData(this);
fetch('/bin/mycustompost', {
method: 'POST',
body: formData
})
.then(response => response.json())

----

MukeshYadav_
Community Advisor
Community Advisor
October 10, 2024

Hi @stiegjo22 ,

Which error you are getting when you try aem servlet endpoint(post) request from postman?

There may be following reason for 404-

  • Check if any typo in the url of external Api getting used in servlet.
  • Most probably you may be configuring the endpoint in configuration and using in servlet, if that is the case check the configuration value.
  • Servlet might be not getting registered so check the annotation and imports

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/servlet-in-satisfied-status-not-active/m-p/539954

Thanks

stiegjo22
stiegjo22Author
Level 4
October 11, 2024

Now I'm seeing an error related to SSL certificate validation. The PKIX path building failed error indicates that the Java runtime is unable to find a valid certification path to the requested target, which means the SSL certificate of the target server is not trusted by the Java truststore.

 

11.10.2024 11:52:59.734 *ERROR* Error generating description: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
MukeshYadav_
Community Advisor
Community Advisor
October 12, 2024

Hi @stiegjo22 ,

Add certificate to the java truststore, you may refer steps mentioned in below thread

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/ssl-connection-to-remote-server-issue/m-p/645329

Thanks

kautuk_sahni
Community Manager
Community Manager
October 16, 2024

@stiegjo22 Did you find the suggestions helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!

Kautuk Sahni