How to split a variable value into 2 new variables in Apigee Proxy Assign Policy

Hello,

I have a requirement where I have a variable called kvmextractedvalue which contains value like 121342:yshasj323. I have to create 2 new variables where 1st variable will contain value of kvmextractedvalue(value before colon) and 2nd variable will contain value after colon from kvmextractedvalue variable. How can I achieve this using assign policy or any other policy in APigee Proxy? Kindly suggest. 
I tried this but did not work:

<AssignVariable>
<Name>clientId</Name>
<Value ref="kvmextractedvalue">
<Pattern>^(.*?):(.*?)$</Pattern>
<Group>1</Group>
</Value>
</AssignVariable>
<AssignVariable>
<Name>secret</Name>
<Value ref="kvmextractedvalue">
<Pattern>^(.*?):(.*?)$</Pattern>
<Group>2</Group>
</Value>
</AssignVariable>

2 3 115
3 REPLIES 3

Why are you splitting it? 

You said in a different post that you need to "send that data to the OAuth endpoint."  In What form is the OAuth endpoint expecting the data?  Normally when you need to send a clientid & secret to an OAuth token dispensing endpoint, the OAuth endpoint will expect the clientid and secret to be in the form base64_encode(concat(clientid, ':' , secret)).  In which case , you do not need to split the string. You need to simply base64 encode it.  Which you can do with a static function in the AssignMessage. I showed you that previously, in my response to your other post, but , you didn't acknowledge that information, nor did you explain why what I was suggesting was wrong. 

So did you understand what I wrote previously?  Is it not applicable in your case?  What does the OAuth endpoint expect, in your case? 

To answer your question about splitting, I think you need to use the JavaScript step - and use the string.split function there.

I did acknowledge to your reply in my previous post. I replied to your comment.

In my case KVM already contains entries where Name contains all different shipTo field values which are expected to come in json request body from source. in same kvm Value field contains values in pattern clientid:secret where clientid and secret of target oauth has  already provided to us and we set up the same in kvm. now when we assign kvm value corresponding to shipTo value which comes from json request body to a new private variable. that part is working fine. now to call Oauth service of target with clientid, secret and grant_type to get the access token, we need to assign value to clientid and secret which we already have in kvm. so when we extract kvm value in private variable it contains clientid:secret, so we have to split the clientid and secret and assign them to new variables so that we can reuse these variables to next service callout policy to call Oauth service to target application. I hope I am able to clarify. Kindly suggest now.

I missed to mention, Target application oauth is expecting clientid , secret and grant_type as form value where content-type is application/x-www-form-urlencoded. kindly respond to my previous reply to this post only where i clarified my requirement.