I have a requirement where I have 4 fields in which a user will fill phone numbers. On clicking save it will make a Rest API call. The 4 phone numbers have to go in an array in the URL as shown below. I want to make this dynamic rather than hard-coding as string.string[0], string.string[1]... and so on.


Main URL -

 String endpoint = 'https://ws.castiron.com/Castiron/PhoneVal20/PhoneValidation20/ValidateNumberBatch?LicenseInfo.RegisteredUser.UserID=XXXXXXX&LicenseInfo.RegisteredUser.Password=XXXXXX&'+noOfPhonenumber;

String noOfPhonenumber = 'ValidateNumberBatch.PhoneNumbers.string.string[0]=1234567890&ValidateNumberBatch.PhoneNumbers.string.string[1]=1234567891&format=JSON';
  • 1
    Question - Why not go with POST API call instead of GET? – Kiran Machhewar Mar 18 '19 at 18:32
  • The question is not about GET or POST. The question is how can i make string.string[0] as dynamic...instead of hard-coding.. – learningmode Mar 18 '19 at 18:34
  • Let me rephrase it, why to pass parameters in url, this looks like the case where passing dynamic attribute in payload (body) of POST request would make more sense. – Kiran Machhewar Mar 18 '19 at 18:37
  • If you forcefully want to do dynamic things as url parameters may be you can form the request as domain?phoneData=<fieldName1>$<fieldValue1>,<fie…> Now read phoneData split it via comma and then split individual items. I would still consider rethinking why not go with POST as you might come up new configuration and bundling that up as in url parameters is not a good idea. – Kiran Machhewar Mar 18 '19 at 18:40
  • This was given like this only with GET not with POST... – learningmode Mar 18 '19 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.