
<!-- This policy converts an XML payload to JSON structure -->
<XMLToJSON async="false" continueOnError="false" enabled="true" xmlns='http://www.sap.com/apimgmt'>
<Options>
</Options>
<!-- The variable to which the converted JSON should be assigned to -->
<OutputVariable>response</OutputVariable>
<!-- The variable that we want to convert to JSON -->
<Source>response</Source>
</XMLToJSON>
{
"entry":{
"etag":"W\/\"datetime'2016-06-30T21%3A31%3A20.0000000'\"",
"base":"https:\/\/SAPES4.SAPDEVCENTER.COM:443\/sap\/opu\/odata\/iwbep\/GWSAMPLE_BASIC\/",
"id":"https:\/\/SAPES4.SAPDEVCENTER.COM:443\/sap\/opu\/odata\/iwbep\/GWSAMPLE_BASIC\/BusinessPartnerSet('0100000000')",
"title":{
"type":"text",
"":"BusinessPartnerSet('0100000000')"
},
"updated":"2016-07-01T12:29:41Z",
"category":{
"term":"\/IWBEP\/GWSAMPLE_BASIC.BusinessPartner",
"scheme":"http:\/\/schemas.microsoft.com\/ado\/2007\/08\/dataservices\/scheme"
},
"link":[
{
"href":"BusinessPartnerSet('0100000000')",
"rel":"edit",
"title":"BusinessPartner"
},
{
"href":"BusinessPartnerSet('0100000000')\/ToSalesOrders",
"rel":"http:\/\/schemas.microsoft.com\/ado\/2007\/08\/dataservices\/related\/ToSalesOrders",
"type":"application\/atom+xml;type=feed",
"title":"ToSalesOrders"
},
{
"href":"BusinessPartnerSet('0100000000')\/ToContacts",
"rel":"http:\/\/schemas.microsoft.com\/ado\/2007\/08\/dataservices\/related\/ToContacts",
"type":"application\/atom+xml;type=feed",
"title":"ToContacts"
},
{
"href":"BusinessPartnerSet('0100000000')\/ToProducts",
"rel":"http:\/\/schemas.microsoft.com\/ado\/2007\/08\/dataservices\/related\/ToProducts",
"type":"application\/atom+xml;type=feed",
"title":"ToProducts"
}
],
"content":{
"type":"application\/xml",
"properties":{
"Address":{
"type":"\/IWBEP\/GWSAMPLE_BASIC.CT_Address",
"City":"Walldorf",
"PostalCode":"69190",
"Street":"Dietmar-Hopp-Allee",
"Building":"16",
"Country":"DE",
"AddressType":"02"
},
"BusinessPartnerID":"0100000000",
"CompanyName":"SAP",
"WebAddress":"http:\/\/www.sap.com",
"EmailAddress":"do.not.reply@sap.com",
"PhoneNumber":"0622734567",
"FaxNumber":"0622734004",
"LegalForm":"AG",
"CurrencyCode":"EUR",
"BusinessPartnerRole":"01",
"CreatedAt":"2016-06-30T21:31:20.0000000",
"ChangedAt":"2016-06-30T21:31:20.0000000"
}
}
}
}
<!-- Extract content from the request or response messages, including headers, URI paths, JSON/XML payloads, form parameters, and query parameters -->
<ExtractVariables async="true" continueOnError="false" enabled="true" xmlns='http://www.sap.com/apimgmt'>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<JSONPayload>
<Variable name="city">
<JSONPath>$.entry.content.properties.Address.City</JSONPath>
</Variable>
<Variable name="street">
<JSONPath>$.entry.content.properties.Address.Street</JSONPath>
</Variable>
<Variable name="country">
<JSONPath>$.entry.content.properties.Address.Country</JSONPath>
</Variable>
</JSONPayload>
<Source>response</Source>
</ExtractVariables>
<!-- this policy lets you call to an external service from your API flow -->
<ServiceCallout async="true" continueOnError="false" enabled="true" xmlns="http://www.sap.com/apimgmt">
<!-- The request that gets sent from the API proxy flow to the external service -->
<Request/>
<!-- the variable into which the response from the external service should be stored -->
<Response>LatLongResponse</Response>
<!-- The time in milliseconds that the Service Callout policy will wait for a response from the target before exiting. Default value is 120000 ms -->
<Timeout>30000</Timeout>
<HTTPTargetConnection>
<!-- The URL to the service being called -->
<URL>https://maps.googleapis.com/maps/api/geocode/json?address={street},{city},{country}</URL>
</HTTPTargetConnection>
</ServiceCallout>
{
"results":[
{
"address_components":[
{
"long_name":"Dietmar-Hopp-Allee",
"short_name":"Dietmar-Hopp-Allee",
"types":[
"route"
]
},
{
"long_name":"Walldorf",
"short_name":"Walldorf",
"types":[
"locality",
"political"
]
},
{
"long_name":"Karlsruhe",
"short_name":"KA",
"types":[
"administrative_area_level_2",
"political"
]
},
{
"long_name":"Baden-Württemberg",
"short_name":"BW",
"types":[
"administrative_area_level_1",
"political"
]
},
{
"long_name":"Germany",
"short_name":"DE",
"types":[
"country",
"political"
]
},
{
"long_name":"69190",
"short_name":"69190",
"types":[
"postal_code"
]
}
],
"formatted_address":"Dietmar-Hopp-Allee, 69190 Walldorf, Germany",
"geometry":{
"bounds":{
"northeast":{
"lat":49.2969047,
"lng":8.64724
},
"southwest":{
"lat":49.2911259,
"lng":8.6389405
}
},
"location":{
"lat":49.2939276,
"lng":8.6433734
},
"location_type":"GEOMETRIC_CENTER",
"viewport":{
"northeast":{
"lat":49.2969047,
"lng":8.64724
},
"southwest":{
"lat":49.2911259,
"lng":8.6389405
}
}
},
"place_id":"ChIJ2RBciqS-l0cRNVMdYeMi8jk",
"types":[
"route"
]
}
],
"status":"OK"
}
<!-- Extract content from the request or response messages, including headers, URI paths, JSON/XML payloads, form parameters, and query parameters -->
<ExtractVariables async="true" continueOnError="false" enabled="true" xmlns='http://www.sap.com/apimgmt'>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<JSONPayload>
<Variable name="lat">
<JSONPath>$.results[0].geometry.location.lat</JSONPath>
</Variable>
<Variable name="long">
<JSONPath>$.results[0].geometry.location.lng</JSONPath>
</Variable>
</JSONPayload>
<Source>LatLongResponse</Source>
</ExtractVariables>
"properties":{
"Address":{
"type":"\/IWBEP\/GWSAMPLE_BASIC.CT_Address",
"City":"Walldorf",
"PostalCode":"69190",
"Street":"Dietmar-Hopp-Allee",
"Building":"16",
"Country":"DE",
"AddressType":"02"
},
"BusinessPartnerID":"0100000000",
"CompanyName":"SAP",
"properties":{
"Address":{
"type":"\/IWBEP\/GWSAMPLE_BASIC.CT_Address",
"City":"Walldorf",
"PostalCode":"69190",
"Street":"Dietmar-Hopp-Allee",
"Building":"16",
"Country":"DE",
"AddressType":"02",
"Latitude": xxxx,
"Longitude": yyyy
},
"BusinessPartnerID":"0100000000",
"CompanyName":"SAP",
var payload = JSON.parse(context.getVariable("response.content"));
payload.entry.content.properties.Address.latitude = context.getVariable("lat");
payload.entry.content.properties.Address.longitude = context.getVariable("long");
context.setVariable("response.content",JSON.stringify(payload));
<!-- this policy allows us to execute java script code during execution of an API Proxy -->
<Javascript async="false" continueOnError="false" enabled="true" timeLimit="200" xmlns='http://www.sap.com/apimgmt'>
<!-- contains the name of the main code file -->
<ResourceURL>jsc://addValues.js</ResourceURL>
</Javascript>
{
"entry":{
"etag":"W/\"datetime'2016-07-05T21%3A31%3A29.0000000'\"",
"base":"https://SAPES4.SAPDEVCENTER.COM:443/sap/opu/odata/iwbep/GWSAMPLE_BASIC/",
"id":"https://SAPES4.SAPDEVCENTER.COM:443/sap/opu/odata/iwbep/GWSAMPLE_BASIC/BusinessPartnerSet('0100000000')",
"title":{
"type":"text",
"":"BusinessPartnerSet('0100000000')"
},
"updated":"2016-07-06T11:46:37Z",
"category":{
"term":"/IWBEP/GWSAMPLE_BASIC.BusinessPartner",
"scheme":"http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"
},
"link":[
{
"href":"BusinessPartnerSet('0100000000')",
"rel":"edit",
"title":"BusinessPartner"
},
{
"href":"BusinessPartnerSet('0100000000')/ToSalesOrders",
"rel":"http://schemas.microsoft.com/ado/2007/08/dataservices/related/ToSalesOrders",
"type":"application/atom+xml;type=feed",
"title":"ToSalesOrders"
},
{
"href":"BusinessPartnerSet('0100000000')/ToContacts",
"rel":"http://schemas.microsoft.com/ado/2007/08/dataservices/related/ToContacts",
"type":"application/atom+xml;type=feed",
"title":"ToContacts"
},
{
"href":"BusinessPartnerSet('0100000000')/ToProducts",
"rel":"http://schemas.microsoft.com/ado/2007/08/dataservices/related/ToProducts",
"type":"application/atom+xml;type=feed",
"title":"ToProducts"
}
],
"content":{
"type":"application/xml",
"properties":{
"Address":{
"type":"/IWBEP/GWSAMPLE_BASIC.CT_Address",
"City":"Walldorf",
"PostalCode":"69190",
"Street":"Dietmar-Hopp-Allee",
"Building":"16",
"Country":"DE",
"AddressType":"02",
"latitude":49.2939276,
"longitude":8.6433734
},
"BusinessPartnerID":"0100000000",
"CompanyName":"SAP",
"WebAddress":"http://www.sap.com",
"EmailAddress":"do.not.reply@sap.com",
"PhoneNumber":"0622734567",
"FaxNumber":"0622734004",
"LegalForm":"AG",
"CurrencyCode":"EUR",
"BusinessPartnerRole":"01",
"CreatedAt":"2016-07-05T21:31:29.0000000",
"ChangedAt":"2016-07-05T21:31:29.0000000"
}
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
14 | |
11 | |
7 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
5 |