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

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.

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?

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.

show us the code

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

can someone help me on this

you can use a Map to relate your ticket with the response.
I mean take the snowapiresp vakue and store in a map, say
m = make(map[string]*Response)
key := fmt.Sprintf(SnowInc + SnowTicket)
m[key] = nil
// process the url and when you got snowapiresp store in your map
m[key] = snowapiresp

Thanks Yamil actually the requirement is based on the ticket type the calls should be selected whether to use INC search or CHG search and print the response of both the tickets one below the other

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.