Introduction
In this new article, we will show how to read WordPress data using REST API. REST API is a very popular software architectural style for Web Services.
SSIS is a very popular ETL software used to integrate almost any data (SQL Server, Oracle, Excel, DB2, CSV files, Big Data, Facebook, Gmail, etc).
Requirements
For this example, we will use a popular plug-in. The name is ZappySys PowerPack for SSIS which includes some nice generic connectors to REST API. You can download it here:
Getting started
We will be using this ZappySys SSIS PowerPack component to make things work:
SSIS REST API Web Service Task |
|
SSIS JSON Source (File, REST API, OData Connector) | |
SSIS JSON File Destination (Create JSON File) |
Read WordPress data using SSIS with REST API
REST API is also the name of one of the ZappySys components. These tools can connect to thousands of REST API Servers. In this example, we will connect to WordPress.
- First, drag and drop the REST API task to the design pane.
- Secondly, write the following URL in the REST API task URL:
1http://demo.wp-api.org/wp-json/wp/v2/pages - After that, press Test Request/Response.
- That URL shows the page’s information in WordPress. This is a demo API. For more information about the WordPress links, check here.
- Next, you can also check the Tags, Comments, Categories, Posts, Taxonomies, Media. Here you have some examples:
- To get the tags in WordPress, use this URL:
1http://demo.wp-api.org/wp-json/wp/v2/tags - In order to read comments in WordPress using SSIS and REST API, use this URL:
1http://demo.wp-api.org/wp-json/wp/v2/comments - For the categories, use this URL to read WordPress data using SSIS:
1http://demo.wp-api.org/wp-json/wp/v2/categories
- To get the tags in WordPress, use this URL:
- In addition, for your blog, you need to add /wp-json/wp/v2/ and pages, posts or tags in your WordPress URL.
- Finally, if you want to save the results, in Response Settings, enable save response content and select the option save to file, and specify a file path:
How to read WordPress data using SSIS and store it into a SQL Server database
In the next example, we will use the JSON Source component. This component is similar to the REST API, but this is used in the Data Flow to save the REST API results in any destination of your preference (SQL Server, PostgreSQL, MongoDB, etc). Also, this example will read WordPress data using SSIS and store it into a SQL Server database.
- First of all, in the Control flow, drag and drop the Data Flow:
- Drag and drop the JSON Source in the Data flow with this configuration:
- Finally, you can save to an OLEDB Destination to save into a SQL Database:
How to read WordPress data using SSIS and modify the JSON structure
Sometimes we need to modify the WordPress JSON output to a custom output in SSIS. We will now use the JSON Generator Transform this time, which is a very powerful tool for this purpose.
- First of all, we will use the JSON Source connecting to the following
1URL: http://demo.wp-api.org/wp-json/wp/v2/categories - Secondly, we need to convert the JSON output to the following format:
12345678910{"id" :{"count" : 1474359596826126768,"description" :{"link" : "xxx"}}} - Next, we will add an element first:
- Also, we will select the id attribute:
- In addition, we will add a static element to the id:
- Furthermore, we will add the count element.
- Finally, repeat the same process for the description and link. The JSON structure will be the following:
How to read WordPress data using SSIS and use pagination
If it is a lot of data in REST API, pagination allows showing the results in pages. Let’s take a look at it.
- First of all, we will use page 2. To do it, we will use the following URL in the JSON Source task in the data flow:
1http://demo.wp-api.org/wp-json/wp/v2/posts?per_page=2 - Secondly, there is a pagination tab that can be used to get the data using pagination. For more information about pagination, refer to our ZappySys Pagination article related.
How to write WordPress data using SSIS
- In order to write WordPress data using SSIS, we will use the REST API task with the following URL:
1POST http://demo.wp-api.org/wp-json/wp/v2/posts/ - Secondly, we have the post with id equal to 2 and we will use the body request as follows:
Conclusion
To conclude, in this article, we learned how to write and read WordPress data using SSIS. In addition, we learned also how to get pagination and how to change the format of the JSON results. If you want to try it yourself, do not hesitate to download ZappySys PowerPack!
References
Finally, for more information about how to read WordPress Data using SSIS, refer to these links: