Skip to main content

Hi,

I am using a REST API (CData source) to get source data. Is it possible to specify that you want to do a POST rather than GET in a CData source?

If so is there any Guide?

 

REST calls are usually based on GET commands.  However, it is possible to make POST commands. You may finds some examples here https://www.cdata.com/kb/articles/rest-overview.rst


First, explore in a tool like Postman, then test using the CData provider.  
 
When using CData provider, generate a log file with Verbosity = 3 to review.


Hi @mwr1991 can you please explain what you are trying to achieve using the POST command? Have you been able to extract the desired data output using a POST command in Postman?


Hi @Syed Yousuf and @Christian Hauggaard Christian,

In Postman is working. I am trying to get json data from POST api.

In TX i am getting this error. 

 

ERROR

 

 


Hi Waqas

You can run post calls in RSD files, but they need to be put into the main Get function.

	<api:script method="GET">
<api:set attr="tmp.token" value="" />
<api:set attr="method" value="POST"/>
<api:set attr="URI" value="https://rest.api.com/v2/generateToken" />
<api:set attr="JSONPath" value="$" />
<api:set attr="contenttype" value="application/x-www-form-urlencoded" />
<api:set attr="EncodePostData" value="false" />
<api:set attr="data">username=usere&password=1234567</api:set>
<api:call op="jsonproviderGet" out="login">
<api:set attr="tmp.token" value="[login.token]" />
</api:call>

<api:set attr="method" value="GET"/>
<api:set attr="URI" value="[BASEURI | replace('{token}', '[tmp.token | urlencode()]')]"/>
<api:set attr="JSONPath" value="[BASEJSONPath]"/>
<api:call op="jsonproviderGet">
<api:push/>
</api:call>
</api:script>

The above is for adding url encoded options in the call. What is it you need to do?


Hi Waqas

Just for reference. The way to do this post call can be done with a file set up like this.

<api:script xmlns:api="http://apiscript.com/ns?v1" xmlns:xs="http://www.w3.org/2001/XMLSchema">

<!-- See Column Definitions to specify column behavior and use XPaths to extract column values from JSON. -->
<api:info title="order" desc="Generated schema file." xmlns:other="http://apiscript.com/ns?v1">
<!-- You can modify the name, type, and column size here. -->
<attr name="klant" xs:type="string" readonly="false" other:xPath="/json/order/klant" />
<attr name="kvk" xs:type="string" readonly="false" other:xPath="/json/order/kvk" />
<attr name="leverancier" xs:type="string" readonly="false" other:xPath="/json/order/leverancier" />
<attr name="OIN" xs:type="string" readonly="false" other:xPath="/json/order/OIN" />
<attr name="omschrijving" xs:type="string" readonly="false" other:xPath="/json/order/omschrijving" />
<attr name="orderdatum" xs:type="datetime" readonly="false" other:xPath="/json/order/orderdatum" />
<attr name="ordernummer" xs:type="string" readonly="false" other:xPath="/json/order/ordernummer" />
<attr name="routering" xs:type="string" readonly="false" other:xPath="/json/order/routering" />
<attr name="status" xs:type="string" readonly="false" other:xPath="/json/order/status" />
</api:info>

<api:set attr="DataModel" value="DOCUMENT" />
<api:set attr="URI" value="https://api.staging.rest.com/webservices/orders/lijst" />

<api:set attr="JSONPath" value="$.order" />

<!-- The GET method corresponds to SELECT. Here you can override the default processing of the SELECT statement. The results of processing are pushed to the schema's output. See SELECT Execution for more information. -->
<api:script method="GET">
<api:set attr="method" value="POST"/>
<api:set attr="contenttype" value="application/json" />
<api:set attr="data">{"order": \[ {} \] }</api:set>
<api:call op="jsonproviderGet">
<api:push/>
</api:call>
</api:script>

</api:script>

This also required an username and password for authentication and it was added to the setup of the data source along with the Auth Scheme type set to Basic Authentication.


Reply