Rest Call best request format JSON/Arrays

Hi,

To the target backend we want to pass a request as a form parameter (POST request). Target backend expects request as a string where we have a delimiter !-! separating each of the values. e.g

STG1sg2713831!-!xxxlove!-!true!-!false

However, i can also have another pattern separted with another delimiter ### and so on...

STG1sg2713832!-!xxxlove2!-!true!-!false

so the request that goes to target backend effectively can -

STG1sg2713831!-!xxxlove!-!true!-!false###STG1sg2713832!-!xxxlove2!-!true!-!false

From the apigee side how should it be handled. As it is an update it will be a PUT requsest.

I have these attributes -

I have identified groupName, groupMessage and flag1 and flag2.

But, these can be repeating attributes and moreover they are to be considered as a group.

What will be the best way to pass this value structure.

a. JSON format - { "key1":{ }, "key2":{ } ..}

b. Pass them as array

If there is any other better way please sugggest.


Solved Solved
1 2 302
1 ACCEPTED SOLUTION

You can use your payload something like below ,

PUT ../{group_id}

{
	"Groups": [{
		"Groupname": "STG1sg2713831",
		"groupMessage": "xxxlove1",
		"flag1": true,
		"flag2": false
	}, {
		"Groupname": "STG1sg2713832",
		"groupMessage": "xxxlove2",
		"flag1": true,
		"flag2": false
	}, {
		"Groupname": "STG1sg2713833",
		"groupMessage": "xxxlove3",
		"flag1": true,
		"flag2": false
	}]
}

This way you can write simple javascript to iterate over array and generate required back-end structure.

hope this will help.

View solution in original post

2 REPLIES 2

You can use your payload something like below ,

PUT ../{group_id}

{
	"Groups": [{
		"Groupname": "STG1sg2713831",
		"groupMessage": "xxxlove1",
		"flag1": true,
		"flag2": false
	}, {
		"Groupname": "STG1sg2713832",
		"groupMessage": "xxxlove2",
		"flag1": true,
		"flag2": false
	}, {
		"Groupname": "STG1sg2713833",
		"groupMessage": "xxxlove3",
		"flag1": true,
		"flag2": false
	}]
}

This way you can write simple javascript to iterate over array and generate required back-end structure.

hope this will help.

thanks,...yes..on similar lines i am using PUT/ <no group id as they are multiple> a form param with json input non-array though.

{ "STG1sg": { ..}, {"STG1sg":{ ..} }