How can i receive an Array of request and send response for each array value


(DINESH) #1

I have a requirement where user can pass multiple values to a key under an array. i want the app to run the validation for each value in the array and print the response accordingly.

Example input:

{
“ticket”: [
“abc”,
“def”,
“ghi”,
],
“user”: “xyzasb”
}

i want the tickets [abc, def, ghi] to be passed as input variable to a third party api with get method and print the received response one another below.


(Lutz Horn) #2

I don’t quite understand your question. Which part of this requirement are you having problems with? What did you already implement, what is missing?


(DINESH) #3

My current implementation accepts only single value for key “ticket” and gives out the response. Now i want the value for key to be multiple array and return the desired response for each value.


(amnon bc) #4

show us the code


(DINESH) #5

Request Data is something like this

{
“tickets”: [ “INC0012345678”,
“CHG0012345678”,
“CHG0012345679”,
“INC0012345679”
],
“IncludeDetail”: true,
“mwuser”: “abcd”
}

third party api url differs based on ticket type if first 3 character are INC it will call
URL = A
if CHG then URL = B

based on the selected URL i will perform the client.Get

//Third Party SNOW API Call
var snowapiresp *http.Response
if strings.Contains(SnowTicket, “INC”) {
snowapiresp, err = client.Get(fmt.Sprintf(SnowInc + SnowTicket))
if err != nil {
fmt.Println(err.Error())
}
} else {
snowapiresp, _ = client.Get(fmt.Sprintf(SnowChg + SnowTicket))
if err != nil {
fmt.Println(err.Error())
}
}

and print the response for each ticket number