I have to submit this Google form whenever new signup is performed on my application, so I have used RestTemplate
in Java Spring Boot to send API request and populate all form data as query params. These query params worked for plan text, but for dropdown selection these are not working properly and I get 400 bad request.
And the strange thing is, I debug the code and copy the generated URL from RestTemplate
API call and paste same URL in browser or Postman, and it's 100% working.
Can anyone look into my code and generated URLR and identify what I'm doing wrong in the code?
Here is my code:
private static final String GOOGLE_FORM_URL_V2 = "https://docs.google.com/forms/d/e/1FAIpQLSeb_QX8rdKD2WOM5-0rZ10C9rzPsMzqlGL-Aduh7_nM0EEutw/formResponse";
public Boolean submitGoogleFormV2(UserDto userDto) {
String sampleWhatsappMessage = "Hi David! Your Order is booked and it will be delivered in two days. Thanks for trusting us.";
String country = new Locale("en", PhoneNumberUtil.getInstance().getRegionCodeForCountryCode(userDto.getCountryCode())).getDisplayCountry();
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(GOOGLE_FORM_URL_V2)
.queryParam("submit", "Submit")
.queryParam("entry.294840288", "Both of the above") // What type of messages will you be sending with WhatsApp?
.queryParam("entry.305369145", userDto.getPhoneNumber()) // phone number
.queryParam("entry.365096862", vonageApiProperties.getMasterKey()) // Vonage API Key
// TODO: Generate new api key for this whatsapp number
.queryParam("entry.400495561", "tbc") // Vonage API key for WhatsApp Traffic
.queryParam("entry.631769330", userDto.getRegion().getText()) // Your Region
.queryParam("entry.901955710", userDto.getFirstName() + " " + userDto.getLastName()) // Your Name
.queryParam("entry.1208336345", "up to 10,000 Messages / month") // Estimated monthly messages volume
.queryParam("entry.1259584144", userDto.getEmail()) // Your Email Address
.queryParam("entry.1489275520", userDto.getBrandName()) // Brand Name
.queryParam("entry.1510504567", country + " " + userDto.getCountryCode().toString()) // Phone number's country code
.queryParam("entry.1595895866", userDto.getCompanyName()) // Company Name
.queryParam("entry.1602423798", userDto.getEmail()) // Email address(s) to be added to the WhatsApp Manager
.queryParam("entry.1731935104", "No") // Is your chosen WhatsApp phone number a Vonage long virtual number (LVN)?
.queryParam("entry.1807529240", "Not sure") // Estimated peak messages per second: indicate daily, weekly, or monthly.
.queryParam("entry.2012164249", "Other/ Don't know") // What is your business vertical?
.queryParam("entry.292494179", "") // Partner Name
.queryParam("entry.565847730", "") // Other Email Addresses to be CC'd
.queryParam("entry.1792374253", "") // Vonage Account Manager's email address
.queryParam("entry.166684008", userDto.getFbBusinessManagerId()) // Company Facebook Business Manager ID
.queryParam("entry.1328375169", "") // Company Facebook URL
.queryParam("entry.1366161341", "") // Company website
.queryParam("entry.1461623644", sampleWhatsappMessage) // Please provide example message(s) you would be sending over WhatsApp
.queryParam("entry.309718730", "1000") // What is your expected monthly spend on this project?
.queryParam("entry.1279938927", ""); // Any Additional Notes
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", "*/*");
headers.set("User-Agent", "Mozilla/5.0");
HttpEntity<?> entity = new HttpEntity<>(headers);
try {
ResponseEntity<String> response = restTemplate.postForEntity(builder.toUriString(), entity, String.class);
log.info("Successfully sent google from to Vonage. Response: {}", response.getBody());
return true;
} catch (Exception e) {
log.error("Unable to send google form to vonage. Error: {}", e.getMessage());
return false;
}
}
Here is the generated URL:
https://docs.google.com/forms/d/e/1FAIpQLSeb_QX8rdKD2WOM5-0rZ10C9rzPsMzqlGL-Aduh7_nM0EEutw/formResponse?submit=Submit&entry.294840288=Both%20of%20the%20above&entry.305369145=3326252240&entry.365096862=38f794d8&entry.400495561=tbc&entry.631769330=South%20East%20Asia%20(SEA)&entry.901955710=Umaid%20Ashraf&entry.1208336345=up%20to%2010,000%20Messages%20/%20month&entry.1259584144=umaidashraf0@gmail.com&entry.1489275520=Devestem&entry.1510504567=Pakistan%2092&entry.1595895866=Devestem&entry.1602423798=umaidashraf@gmail.com&entry.1731935104=No&entry.1807529240=Not%20sure&entry.2012164249=Other/%20Don't%20know&entry.292494179=&entry.565847730=&entry.1792374253=&entry.166684008=121026849979786&entry.1328375169=&entry.1366161341=&entry.1461623644=Hi%20David!%20Your%20Order%20is%20booked%20and%20it%20will%20be%20delivered%20in%20two%20days.%20Thanks%20for%20trusting%20us.&entry.309718730=1000&entry.1279938927=