APIs & Integrations

Steffen1
Member

Create page request results in 500 Internal Server Error

 

Hi all,

 

trying to create a landing page using Spring via API results in a 500 Internal Server Error. The call works using Postman - but I have no idea what is wrong in my code, though. Is there a way to get additional error information?

 

The offending code simplifies to:

 

import java.net.URI;
import java.util.HashMap;
import java.util.Map;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriBuilder;

import com.fasterxml.jackson.databind.JsonNode;

public class CopyPageTest
{
	private static final String						USER_ID				= "XXXXXXX";
	private static final String						HAPI_KEY			= "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
	private static final String						PAGE_ID				= "XXXXXXXXXX";
	private static final String						BASE_URI			= "https://api.hubapi.com";
	private static final DefaultUriBuilderFactory	URI_BUILDER_FACTORY	= new DefaultUriBuilderFactory(BASE_URI);
	private static final RestTemplate				REST_TEMPLATE		= new RestTemplate();

	private static final URI buildUri(String path, String query, Map<String, Object> parameters)
	{
		UriBuilder builder = URI_BUILDER_FACTORY.builder();
		builder.path(path);
		builder.query(query);
		builder.queryParam("userId", USER_ID);
		builder.queryParam("hapikey", HAPI_KEY);
		return builder.build(parameters);
	}

	private static JsonNode createPage(JsonNode page)
	{
		HashMap<String, Object> parameters = new HashMap<>();
		URI uri = buildUri("/content/api/v2/pages", "", parameters);
		HttpHeaders headers = new HttpHeaders();
		headers.setContentType(MediaType.APPLICATION_JSON);
		HttpEntity<String> request = new HttpEntity<String>(page.toString(), headers);
		return REST_TEMPLATE.postForObject(uri, request, JsonNode.class);
	}

	private static JsonNode getPage()
	{
		HashMap<String, Object> parameters = new HashMap<>();
		parameters.put("id", PAGE_ID);
		URI uri = buildUri("/content/api/v2/pages/{id}", "", parameters);
		return REST_TEMPLATE.getForObject(uri, JsonNode.class);
	}

	public static void main(String[] arguments)
	{
		JsonNode page = getPage();
		JsonNode clone = createPage(page);
		System.out.println(clone.toString());
	}
}

Any ideas?

 

Thanks,

Steffen

 

 

 

0 Upvotes
5 Replies 5
jdoe62
Member

Create page request results in 500 Internal Server Error

This error can occur due to various reasons, including:

Code Errors: Issues with the server-side code, such as syntax errors, missing dependencies, or logic flaws, can trigger the internal server error.

Server Configuration: Misconfigured server settings, such as incorrect permissions, conflicting configurations, or resource limitations, can lead to the 500 Internal Server Error.

Database Problems: If the server relies on a database, issues like connection failures, corrupted data, or insufficient database permissions can result in the error.

To troubleshoot and resolve this error, you can consider the following steps:

Check Server Logs: Review the server logs for more specific error information. The logs can provide valuable insights into the underlying cause of the error, helping you identify the issue.

Review Code: Examine the server-side code responsible for handling the page creation request. Look for any errors, exceptions, or potential problems in the code's syntax and logic. Correct any identified issues and retest the page creation process.

Verify Server Configuration: Ensure that the server settings, including file permissions, resource limits, and configuration files, are properly configured. Make any necessary adjustments or consult a server administrator or hosting provider for assistance.

Database Connectivity: Verify that the database server is running and accessible. Check the database connection parameters in the server-side code and confirm that the required permissions are granted.

 WoW private servers are unauthorized game servers that aim to replicate the World of Warcraft experience outside the official Blizzard servers. It's important to exercise caution when engaging with private servers, as they may violate Blizzard's terms of service and can pose security risks or be subject to legal issues. If you decide to explore WoW private servers, ensure they are reputable, secure, and comply with any applicable legal requirements.

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Create page request results in 500 Internal Server Error

Hi @Steffen1 , do you have the raw request you're sending to HubSpot? If you could provide me with the endpoint you're hitting, as well as the raw request body, and the full error message that comes back from the HubSpot servers I'd be happy to dig into the problem, but can't with just the code you're writing. Thanks!

0 Upvotes
Steffen1
Member

Create page request results in 500 Internal Server Error

Hi CBarley,

 

obviously my reply has been "eaten" by the new forum. Sending you a private message now.

 

In case someone else is in a similar trouble: the following post helps print the request.

 

https://stackoverflow.com/questions/7952154/spring-resttemplate-how-to-enable-full-debugging-logging...

0 Upvotes
Steffen1
Member

Create page request results in 500 Internal Server Error

Finally, after some detailed debugging, I found the server response:

HTTP/1.1 500 Internal Server Error\r\nDate: Fri, 22 Feb 2019 13:22:11 GMT\r\nContent-Type: application/json;charset=utf-8\r\nContent-Length: 147\r\nConnection: keep-alive\r\nSet-Cookie: __cfduid=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX; expires=Sat, 22-Feb-20 13:22:11 GMT; path=/; domain=.hubapi.com; HttpOnly\r\nX-Trace: 2BB34BDAC2CCB73D421BEE05AB7FB74A5C2906E8948A2B77E28EAF700C01\r\nx-last-modified-timestamp: 1550841731209\r\nX-HubSpot-RateLimit-Daily: 40000\r\nX-HubSpot-RateLimit-Daily-Remaining: 39981\r\nX-HubSpot-RateLimit-Secondly: 10\r\nX-HubSpot-RateLimit-Secondly-Remaining: 9\r\nAccess-Control-Allow-Credentials: false\r\nStrict-Transport-Security: max-age=31536000; includeSubDomains; preload\r\nExpect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"\r\nServer: cloudflare\r\nCF-RAY: 4ad1c292ebe42d6b-TXL\r\n\r\n{"correlationId":"e5d23223-160d-4612-81e9-c8ca9537875b","message":"internal error","requestId":"47786aeda6bc6095e2855ae6c7bf3ec4","status":"error"}

0 Upvotes
Steffen1
Member

Create page request results in 500 Internal Server Error

Hi CBarley,

 

thank you for your response. The communication runs via TLS, so I have to rely on what Spring's doing. If anybody is interested, the following output was created using the technique described here: https://stackoverflow.com/questions/7952154/spring-resttemplate-how-to-enable-full-debugging-logging...

 

13:15:14.696 [main] DEBUG LoggingRequestInterceptor - URI : https://api.hubapi.com/content/api/v2/pages?userId=XXXXXXX&hapikey=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX...
13:15:14.696 [main] DEBUG LoggingRequestInterceptor - Method : POST
13:15:14.696 [main] DEBUG LoggingRequestInterceptor - Headers : {Accept=[application/json, application/*+json], Content-Type=[application/json], Content-Length=[6357], Accept-Charset=[big5, big5-hkscs, cesu-8, euc-jp, euc-kr, gb18030, gb2312, gbk, ibm-thai, ibm00858, ibm01140, ibm01141, ibm01142, ibm01143, ibm01144, ibm01145, ibm01146, ibm01147, ibm01148, ibm01149, ibm037, ibm1026, ibm1047, ibm273, ibm277, ibm278, ibm280, ibm284, ibm285, ibm290, ibm297, ibm420, ibm424, ibm437, ibm500, ibm775, ibm850, ibm852, ibm855, ibm857, ibm860, ibm861, ibm862, ibm863, ibm864, ibm865, ibm866, ibm868, ibm869, ibm870, ibm871, ibm918, iso-2022-cn, iso-2022-jp, iso-2022-jp-2, iso-2022-kr, iso-8859-1, iso-8859-13, iso-8859-15, iso-8859-2, iso-8859-3, iso-8859-4, iso-8859-5, iso-8859-6, iso-8859-7, iso-8859-8, iso-8859-9, jis_x0201, jis_x0212-1990, koi8-r, koi8-u, shift_jis, tis-620, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-32be, utf-32le, utf-8, windows-1250, windows-1251, windows-1252, windows-1253, windows-1254, windows-1255, windows-1256, windows-1257, windows-1258, windows-31j, x-big5-hkscs-2001, x-big5-solaris, x-compound_text, x-euc-jp-linux, x-euc-tw, x-eucjp-open, x-ibm1006, x-ibm1025, x-ibm1046, x-ibm1097, x-ibm1098, x-ibm1112, x-ibm1122, x-ibm1123, x-ibm1124, x-ibm1166, x-ibm1364, x-ibm1381, x-ibm1383, x-ibm300, x-ibm33722, x-ibm737, x-ibm833, x-ibm834, x-ibm856, x-ibm874, x-ibm875, x-ibm921, x-ibm922, x-ibm930, x-ibm933, x-ibm935, x-ibm937, x-ibm939, x-ibm942, x-ibm942c, x-ibm943, x-ibm943c, x-ibm948, x-ibm949, x-ibm949c, x-ibm950, x-ibm964, x-ibm970, x-iscii91, x-iso-2022-cn-cns, x-iso-2022-cn-gb, x-iso-8859-11, x-jis0208, x-jisautodetect, x-johab, x-macarabic, x-maccentraleurope, x-maccroatian, x-maccyrillic, x-macdingbat, x-macgreek, x-machebrew, x-maciceland, x-macroman, x-macromania, x-macsymbol, x-macthai, x-macturkish, x-macukraine, x-ms932_0213, x-ms950-hkscs, x-ms950-hkscs-xp, x-mswin-936, x-pck, x-sjis_0213, x-utf-16le-bom, x-utf-32be-bom, x-utf-32le-bom, x-windows-50220, x-windows-50221, x-windows-874, x-windows-949, x-windows-950, x-windows-iso2022jp]}
13:15:14.696 [main] DEBUG LoggingRequestInterceptor - Request body: {"ab":false,"ab_variation":false,"absolute_url":"http://hub2sales-dev-XXXXXXX-XXXXXXX.hs-sites.com/whitelist-tgw","analytics_page_id":"6341724766","a... XXXXXX","author_user_id":XXXXXXX,"author_username":"XX@XXXXXX.com","blueprint_type_id":0,"category":1,"category_id":1,"content_type_category":1,"content_type_category_id":1,"created":1539691309632,"created_by_id":XXXXXXX,"created_time":1539691309632,"css":{},"css_text":"","ctas":{},"current_state":"PUBLISHED","currently_published":true,"deleted_at":0,"domain":"","featured_image":"","featured_image_alt_text":"","featured_image_height":0,"featured_image_length":0,"featured_image_width":0,"flex_areas":{},"freeze_date":1539691932000,"has_user_changes":true,"html_title":"Whitelist-TGW","id":XXXXXXXXXX,"include_default_custom_css":false,"is_draft":false,"is_published":true,"keywords":[],"label":"Whitelist-TGW","landing_page":true,"layout_sections":{},"link_rel_canonical_url":"","live_domain":"hub2sales-dev-XXXXXXX-XXXXXXX.hs-sites.com","mab":false,"mab_master":false,"mab_variant":false,"meta":{"author_email":"XX@XXXXXX.com","author_username":"XX@XXXXXX.com","author_user_id":XXXXXXX,"has_user_changes":true,"last_edit_session_id":null,"last_edit_update_id":null,"css":{},"password":null,"attached_stylesheets":[],"campaign_name":null,"campaign_utm":null,"css_text":"","enable_domain_stylesheets":null,"enable_layout_stylesheets":null,"featured_image":"","featured_image_alt_text":"","footer_html":null,"head_html":null,"html_title":"Whitelist-TGW","include_default_custom_css":false,"layout_sections":{},"link_rel_canonical_url":"","meta_description":null,"page_expiry_date":null,"page_expiry_enabled":null,"page_expiry_redirect_id":null,"page_expiry_redirect_url":null,"public_access_rules":[],"public_access_rules_enabled":false,"publish_immediately":true,"use_featured_image":false},"name":"Whitelist-TGW","page_redirected":false,"page_title":"Whitelist-TGW","personas":[],"placement_guids":[],"portal_id":XXXXXXX,"preview_key":"vWxBGjva","processing_status":"","public_access_rules":[],"public_access_rules_enabled":false,"publish_date":1539691932000,"publish_date_local_time":1539691932000,"publish_immediately":true,"published_url":"http://hub2sales-dev-XXXXXXX-XXXXXXX.hs-sites.com/whitelist-tgw","resolved_domain":"hub2sales-dev-XX... Quelques informations suppl�mentaires sur une ligne","widget_name":"One Line of Text"},"child_css":{},"css":"","id":1539691865286,"label":"One Line of Text","module_id":1843376,"order":0,"smart_type":null,"type":"module"},{"body":{"html":"<h2>�bersetzung</h2>\n<h2>Something Powerful</h2>\n<h3>Tell The Reader More</h3>\n<p>The headline and subheader tells us what you're <a href=\"#\">offering</a>, and the form header closes the deal. Over here you can explain why your offer is so great it's worth filling out a form for.</p>\n<p>Remember:</p>\n<ul>\n<li>Bullets are great</li>\n<li>For spelling out <a href=\"#\">benefits</a> and</li>\n<li>Turning visitors into leads.</li>\n</ul>","module_id":1155639,"tag":"module","type":"module","widget_name":"Rich Text"},"child_css":{},"css":{},"id":1539691881439,"label":"Rich Text","module_id":1155639,"order":1,"smart_type":null,"type":"module"},{"body":{"module_id":1790629,"tag":"module","type":"module","widget_name":"Call-to-Action"},"child_css":{},"css":{},"id":1539691894440,"label":"Call-to-Action","module_id":1790629,"order":2,"smart_type":null,"type":"module"},{"body":{"module_id":1861177,"response_message":"�bersetzung Merci de vous �tre abonn�&nbsp;!","tag":"module","title":"�bersetzung Abonnez-vous ici�!","type":"module","widget_name":"Blog Email Subscription"},"child_css":{},"css":{},"id":1539691904196,"label":"Blog Email Subscription","module_id":1861177,"order":3,"smart_type":null,"type":"module"},{"body":{"module_id":1155231,"tag":"module","type":"module","widget_name":"Image"},"child_css":{},"css":"","id":1539691888550,"label":"Image","module_id":1155231,"order":4,"smart_type":null,"type":"module"}]},"module_1539361318030491":{"widgets":[]},"module_1539361320076493":{"widgets":[]},"module_1539361323171494":{"widgets":[]},"module_1539361325632496":{"widgets":[]},"module_1539361327359497":{"widgets":[]},"module_1539361339373498":{"widgets":[]},"module_1539361341900500":{"widgets":[]},"module_1539361343505501":{"widgets":[]},"module_1539361344882502":{"widgets":[]}},"widgetcontainers":{},"widgets":{"module_1539361207322464":{"body":{"extra_classes":"widget-type-header","field_types":{"header_tag":"choice","value":"text"},"module_id":1155826,"per_widget_wrapper_html":"","tag":"module","type":"module","value":"\n\n\n\n\t\n\n�bersetzung Un titre clair et en gras","widget_name":"Header","wrap_field_tag":"div","wrapping_html":""},"child_css":{},"css":{},"id":"module_1539361207322464","label":"Header","module_id":1155826,"name":"module_1539361207322464","order":3,"smart_type":null,"type":"module"},"module_1539361231667466":{"body":{"extra_classes":"widget-type-logo","field_types":{"img":"logo","link":"text","open_in_new_tab":"boolean"},"module_id":1155232,"per_widget_wrapper_html":"","tag":"module","type":"module","widget_name":"Logo","wrap_field_tag":"div","wrapping_html":""},"child_css":{},"css":{},"id":"module_1539361231667466","label":"Logo","module_id":1155232,"name":"module_1539361231667466","order":1,"smart_type":null,"type":"module"}}}

0 Upvotes