【Scheduler】Using PayPal Rest API (Transaction:Get)

This time, I will use **PayPal Rest API** to get Transaction data and save it to the file system.
[Sharperlight](https://sharperlight.com/) provides various JavaScript functions for developers. Let's write JavaScript code using those functions and define them as scheduler tasks.
Initially, the underlying code is created with fixed Tokens and query parameters.
Refer to the following pages for authentication and data acquisition methods.
- [PayPal Rest API](https://developer.paypal.com/api/rest)
- [Authentication](https://developer.paypal.com/api/rest/authentication/#link-authentication)
- [Get Transactions](https://developer.paypal.com/docs/api/transaction-search/v1/)

I also used [**Postman**](https://www.postman.com/) to verify authentication and data retrieval requests. At the stage of this article, I get Token with Postman and use it by pasting into JavaScript code.

Now, start **Scheduler** from the [Sharperlight](https://sharperlight.com/) application menu.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/919cbe16-9d36-c608-aad6-9ddb5efeabaf.png)
Once the **Scheduler** is running, start creating tasks with the `New` button.
In the `General` tab of the task dialog, fill in **Code**, **Group** and **Description**, for example like this.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/1a7d6f58-f01b-6cb8-38cb-17a9105ef3d4.png)
Go to the `Actions` tab. Here I actually send a request and get the Transaction data. Start creating a JavaScript action using the `new` icon.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/9a0441fe-c4dd-566f-7801-951de2a19080.png)
A JavaScript action is added like this, so fill in the **code** and **description**. Then write the JavaScript code in the central script field.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/98387ac6-ca7b-6b75-3775-a96358edc9ac.png)
The code this time looks like this. Created a **transaction_Get** function.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/1bfa3e0d-3640-0a30-0225-5dafb0947dc4.png)
The obtained data will be saved in the `Temp` folder of the **C** drive with the file name `PayPal_Transaction.json`.
**Token** is after `Bearer` in the middle of the code. 
I also used the following for the parameters:
**start_date**, **end_date**, **fields**, **page_size**, **page**
The two functions you can see at the bottom of the code, the **lib_sys.urlContent.Get** function, is a function to send a GET request, and the **lib_sys.io.file.WriteAllText** function writes the data got to a file.

Once the code is complete, use the `Test` button to validate the code.
Since I used an expired Token, I got an error like this.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/3ce307dc-eb13-2d17-95dc-8ae69180256a.png)
Get a new Token in Postman and use it.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/f165f10f-4495-10be-e4f1-e8a934836dd4.png)
No errors this time.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/ee943633-4ce9-7771-89cf-e4660c0a0150.png)
Is the file created? Look in the `Temp` folder on the **C** drive.
It's there:thumbsup:
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/721ef68e-d684-f88c-9470-30a7a8fc75ae.png)
Let's open it. If you open it with **Visual Studio Code**, it will be properly formatted and displayed. I was able to get it successfully:clap:
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/920dc859-fba7-f3e2-8a59-7d3a0bc18003.png)
Up to here for this time...

Thank you.