how to collect text data from response apigee - apigee

I am using serviceCalloutPolicy to get response from some "xyz" api. The response returned by "xyz" api is text data like "abnfhjdkdhrju784hhkfjhbbhg21g3u2u9fdjkfnfddsnrijirry3784yewrgshbsdjbcjsvnvksdnv" which is neither json nor xml . so how can extract this data into variable. I want to use this data as header in another api call.

You can get the response value by using Extract Variable Policy.
Place it after your Service Callout Policy.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="EVTIB-ExtractValueFromJC">
<DisplayName>EVTIB-ExtractValueFromJC"</DisplayName>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<Source clearPayload="false">yourJavaCalloutReponseName</Source>
<VariablePrefix>resp.data</VariablePrefix>
<JSONPayload>
<!--- Extract value from Json or XML , for example Json-->
<Variable name="apiRespData">
<JSONPath>$.data</JSONPath>
</Variable>
</JSONPayload>
</ExtractVariables>
And then use variable name to reference the value.

Related

Redirecting to xml with query string in asp.net

I am doing a Response.Redirect to below given xml document with a query string parameter.
Response.Redirect(#"../temp/output.xml?location=newlocation");
What I want is that the value of location attribute for all the product nodes should be replaced with the value I pass in query string parameter. The problem is when I do a response.redirect to xml the c# server code which modifies the xml document does not executes for the obvious reason that xml file does not runs any server code.
Can anyone please suggest a solution for this.
Xml File
<?xml version="1.0" encoding="utf-8"?>
<products xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="products:noNamespaceSchemaLocation">
<store id="BND088412">
<display-name>test</display-name>
</store>
<product location="test">
<length units="minutes">100</length>
<title>Microsoft Excel</title>
</product>
<product location="test">
<length units="minutes">300</length>
<title>Microsoft VBA</title>
</product>
</products>
Thanks & Regards

Extract form parameter in Extract Variables policy

I am trying to extract a form param in an Extract Variables policy without success. request.formparam.grant_type successfully extracts the form parameter value but when I do the following it doesn't work. I don't understand what I am doing wrong I have made the request with the header Content-Type set to application/x-www-form-urlencoded as specified in the documentation but nothing seems to work. I must be doing something really silly but cannot spot what.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables-1">
<FormParam name="grant_type"/>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<Source clearPayload="false">request</Source>
<VariablePrefix>apigee</VariablePrefix>
</ExtractVariables>
Apigee Support helped me out and the following works:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables-1">
<FormParam name="grant_type"><Pattern>{grantType}</Pattern></FormParam>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<Source clearPayload="false">request</Source>
<VariablePrefix>apigee</VariablePrefix>
</ExtractVariables>
You need to provide the variable in which to save the form parameter:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables-1">
<FormParam name="grant_type">
<Pattern>{grantType}</Pattern>
</FormParam>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<Source clearPayload="false">request</Source>
<VariablePrefix>apigee</VariablePrefix>
</ExtractVariables>
Since you have set your VariablePrefix to "apigee", the form parameter grant_type will be saved in the variable apigee.grantType.

Caching in Apigee using proxy.basepath

I have created a new API /v1/StatusCache to point to my end point /v1/Status. My goal is to be able to cache the data :
based on the uri
for a particular header
So if user 1 sends request to /v1/StatusCache/1234 and the same user sends request to /v1/StatusCache/5678, I should hit my server instead of getting previously cached result from the first request.
Also we user header (Authorization: Bearer ) in the request so my second goal is that if user 1 with header Authorization: Bearer token1 sends a request to /v1/StatusCache/1234 vs a user 2 with header Authorization: Bearer token2 sends a request to /v1/StatusCache/1234, I should get different results (non cached results)
I have this code for proxypath but it just caches every request for 10 seconds. What am I missing
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ResponseCache async="false" continueOnError="false" enabled="true" name="responsecache-1">
<DisplayName>ResponseCache-1</DisplayName>
<FaultRules/>
<Properties/>
<CacheKey>
<Prefix/>
<KeyFragment ref="proxy.pathsuffix" type="string">proxy.pathsuffix</KeyFragment>
</CacheKey>
<Scope>Exclusive</Scope>
<ExpirySettings>
<ExpiryDate/>
<TimeOfDay/>
<TimeoutInSec ref="">10</TimeoutInSec>
</ExpirySettings>
<SkipCacheLookup/>
<SkipCachePopulation/>
</ResponseCache>
My suggestion would be create a variable value combining the header and pathsuffix value (header+pathsuffix) - use this as the key for the response cache.
Try the following:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ResponseCache async="false" continueOnError="false" enabled="true" name="responsecache-1">
<DisplayName>ResponseCache-1</DisplayName>
<FaultRules/>
<Properties/>
<CacheKey>
<Prefix/>
<KeyFragment ref="proxy.pathsuffix" type="string"/>
<KeyFragment ref="request.header.Authorization" type="string"/>
</CacheKey>
<ExpirySettings>
<ExpiryDate/>
<TimeOfDay/>
<TimeoutInSec ref="">60</TimeoutInSec>
</ExpirySettings>
<SkipCacheLookup/>
<SkipCachePopulation/>
</ResponseCache>
I used 60 sec timeout for ease of testing.
This shows an example of proxy.pathsuffix + request.header.Authorization values being a unique cache key. Think of the key now looking like /1234__Bearer token1. The same path suffix and Authorization header value combined are needed to return an entry from cache.
Also, when trying to cache the URI, you may want to try the variable request.uri which includes the querystring-- this can sometimes dictate what the response looks like. If using this, be sure that the querystring does not include unique values like a current timestamp (or at least strip that parameter before using it as a cache key fragment).

Web Deploy parameterization of an XML config file where settings are embedded in CDATA elements

During MSDEPLOY.EXE deployment, I am trying to squirt a parameter into an XML configuration file but the configuration values are stored in CDATA elements. Here are the contents of the file, called paths.xml:
<?xml version="1.0" encoding="UTF-8"?>
<course>
<questionnaires><![CDATA[https://www.site.com/somepage.asp]]></questionnaires>
</course>
I need to transform that URL into something different, but I can't figure out the correct XPATH and syntax for my parameters.xml file, here is what I've got now:
<?xml version="1.0" encoding="utf-8"?>
<parameters>
<parameter name="QuestPath" description="Questionnaires path" defaultValue="<questionnaires><![CDATA[https://www.foo.com/somepage.asp]]></questionnaires>" tags="">
<parameterEntry kind="XmlFile" scope="paths.xml$" match="/course/questionnaires" />
</parameter>
</parameters>
I had very little luck referencing the CDATA element to replace it, so you can see I'm now trying to replace the entire questionnaire element including its CDATA contents. I had to do some escaping of the embedded angle-brackets so parameters.xml wasn't rejected due to invalid XML format.
Now, the resultant paths.xml ends up like:
<?xml version="1.0" encoding="UTF-8"?>
<course>
<questionnaires>https://www.foo.com/somepage.asp</questionnaires>
</course>
So, something has resolved the CDATA element down to its contents only, and CDATA no longer appears in paths.xml which I assume will cause the program that reads it to fail. Help!
Okay - I found a much simpler solution. In conjunction with the developer involved in housing this config XML file on our server, we changed it so the elements just contain the raw URLs, completely dispensing with the CDATA structures.
After testing that the consuming application still appeared to work fine, we agreed they were not needed and therefore I was able to do normal XmlFile replacements on nodes referenced like:
...match="/course/questionnaires/text()"

insert new item in sharepoint list from flex

i m trying to insert new item on sharepoint list from flex using sharepoint-as3-connector (http://code.google.com/p/sharepoint-as3-connector). but i m getting following error.
Response XML:<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<UpdateListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<UpdateListItemsResult>
<Results>
<Result ID="1,UpdateList.NEW">
<ErrorCode>0x8102000a</ErrorCode>
<ErrorText>Invalid URL Parameter
The URL provided contains an invalid Command or Value. Please check the URL again.
below is the header made in soap URL.
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>
TestList
</listName>
<updates>
<Batch OnError="Continue">
<Method ID="1" Cmd="UpdateList.NEW">
<Field Name="ows_LinkTitle">
222222
</Field>
</Method>
</Batch>
</updates>
</UpdateListItems>
please help!
The error message is spot on: you are specifying an invalid command in the Cmd attribute of the Method element.
Per the MSDN article for the Method element, valid values for Cmd are:
Delete
New
Update
I have no experience with the "sharepoint-as3-connector", and I suppose it's there to make your life easier. But it's probably worth reviewing the MSDN documentation for the Lists web service (and specifically the UpdateListItems method) so you know what SharePoint is expecting. SharePoint is a delicate flower that cannot be handled harshly; you must know exactly what it wants to keep it happy.
A good walkthrough on MSDN: How to: Update List Items.

Resources