OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to make a script to automate taking the GET data from my wordpress site and POST to another server

  • Thread starter Thread starter CuloAtomico
  • Start date Start date
C

CuloAtomico

Guest
I have this problem and I'm a newbie of REST API world. I have a Wordpress site in which I sell CD Albums, and I have to take every orders of the day and send some specific data (like the bardcode/ean, the name of the album, the sales quantity, etc etc) to a server, sending this data with REST API calls. I have never used it before but I am trying to learn it.

So, to take the data of my Wordpress site I send a GET request with the Wordpress API and receive a JSON file with all the necessary info. But of all this information I just have to extrapolate some of it and then send them all to this server with a POST request. (The server and API are Korean and are from Hanteo Chart).

The main problem is that I have to write a script to automate the whole process and I don't really know where to start. Taking the single request from Wordpress and then send it to the server it's easy, I only have to insert manually the single necessary data and it's done, but taking all the info from the URL (to do the GET request) and send everything processed correctly it's difficult for me.

I learned how to do GET requests from Wordpress, so with this URL I take all of my orders of the day: https://example.com/wp-json/wc/v3/o...d_before=2024-06-26T00:00:00&status=completed

This return a JSON file with a lot of information, in which I have to take only a few fields, like line_items which is an array that contains all the data about the products of an order.

I'm sorry that I can't share with you the entire JSON file (because of sensitive data inside) but I try to explain to you with an example.

For example: The URL returns ten orders, which are incremental ids from 0 to 9. In each of these ids (for example I take the id 0, so the first order) there are info about that specific order such as id_order, status (which of course is always complete), currency, total, etc etc and the one the I need is line_items, which in turn contains 3 ids that are the products ordered. So the id are from 0 to 2. In the product id (in this case I take the first product, so the id 0 again), I have to take this attributes: ean, name (which is the name of the album), product_id, quantity and sku.

To be more clear I have something like that (I put in bold the attributes I'm interested in):

Code:
[
  {
    "id": 44412,
    "parent_id": 0,
    "status": "completed",
    "currency": "EUR",
    "date_created": "2024-06-21T14:25:07",
    "date_modified": "2024-06-21T14:57:54",
    "discount_total": "0.00",
    "discount_tax": "0.00",
    "shipping_total": "6.50",
    "shipping_tax": "0.00",
    "cart_tax": "0.00",
    "total": "75.40",
    "total_tax": "0.00",
     ...
     ...
    "**line_items**": [
      {
        "id": 59401,
        "**name**": "albumName",
        "**product_id**": 38515,
        "variation_id": 0,
        "**quantity**": 1,
        "tax_class": "",
        "subtotal": "68.90",
        "subtotal_tax": "0.00",
        "total": "68.90",
        "total_tax": "0.00",
        "taxes": [],
        "**sku**": "SEV53",
        "price": 68.9,
        "parent_name": null,
        "**ean**": eanOfTheAlbum
      }
      ... and here i have other data for other products, I show only the first one, so the one with id 0 in line_items, but I have to take the bold attributes for every products ...

    ],
  }
]

Next, I have to do a POST request to the server sending all of this data (The POST request it's easy per se, just like the GET request, I can do a single one but my problem is sending more than one data at a time).

The problem is, how can I write a script that does all of this automatically for example every day at 23:00 (or 11 pm)? I don't know where to start, if all of this can be done in Wordpress or not, and if not what's the best programming language and something like that.

Thanks in advance to anyone who answer this question and sorry for my english.
<p>I have this problem and I'm a newbie of REST API world. I have a Wordpress site in which I sell CD Albums, and I have to take every orders of the day and send some specific data (like the bardcode/ean, the name of the album, the sales quantity, etc etc) to a server, sending this data with REST API calls. I have never used it before but I am trying to learn it.</p>
<p>So, to take the data of my Wordpress site I send a GET request with the Wordpress API and receive a JSON file with all the necessary info. But of all this information I just have to extrapolate some of it and then send them all to this server with a POST request. (The server and API are Korean and are from Hanteo Chart).</p>
<p>The main problem is that I have to write a script to automate the whole process and I don't really know where to start. Taking the single request from Wordpress and then send it to the server it's easy, I only have to insert manually the single necessary data and it's done, but taking all the info from the URL (to do the GET request) and send everything processed correctly it's difficult for me.</p>
<p>I learned how to do GET requests from Wordpress, so with this URL I take all of my orders of the day:
<a href="https://example.com/wp-json/wc/v3/o...d_before=2024-06-26T00:00:00&status=completed" rel="nofollow noreferrer">https://example.com/wp-json/wc/v3/o...d_before=2024-06-26T00:00:00&status=completed</a></p>
<p>This return a JSON file with a lot of information, in which I have to take only a few fields, like line_items which is an array that contains all the data about the products of an order.</p>
<p>I'm sorry that I can't share with you the entire JSON file (because of sensitive data inside) but I try to explain to you with an example.</p>
<p>For example: The URL returns ten orders, which are incremental ids from 0 to 9. In each of these ids (for example I take the id 0, so the first order) there are info about that specific order such as id_order, status (which of course is always complete), currency, total, etc etc and the one the I need is line_items, which in turn contains 3 ids that are the products ordered. So the id are from 0 to 2. In the product id (in this case I take the first product, so the id 0 again), I have to take this attributes: ean, name (which is the name of the album), product_id, quantity and sku.</p>
<p>To be more clear I have something like that (I put in bold the attributes I'm interested in):</p>
<pre><code>[
{
"id": 44412,
"parent_id": 0,
"status": "completed",
"currency": "EUR",
"date_created": "2024-06-21T14:25:07",
"date_modified": "2024-06-21T14:57:54",
"discount_total": "0.00",
"discount_tax": "0.00",
"shipping_total": "6.50",
"shipping_tax": "0.00",
"cart_tax": "0.00",
"total": "75.40",
"total_tax": "0.00",
...
...
"**line_items**": [
{
"id": 59401,
"**name**": "albumName",
"**product_id**": 38515,
"variation_id": 0,
"**quantity**": 1,
"tax_class": "",
"subtotal": "68.90",
"subtotal_tax": "0.00",
"total": "68.90",
"total_tax": "0.00",
"taxes": [],
"**sku**": "SEV53",
"price": 68.9,
"parent_name": null,
"**ean**": eanOfTheAlbum
}
... and here i have other data for other products, I show only the first one, so the one with id 0 in line_items, but I have to take the bold attributes for every products ...

],
}
]
</code></pre>
<p>Next, I have to do a POST request to the server sending all of this data (The POST request it's easy per se, just like the GET request, I can do a single one but my problem is sending more than one data at a time).</p>
<p>The problem is, how can I write a script that does all of this automatically for example every day at 23:00 (or 11 pm)?
I don't know where to start, if all of this can be done in Wordpress or not, and if not what's the best programming language and something like that.</p>
<p>Thanks in advance to anyone who answer this question and sorry for my english.</p>
Continue reading...
 

Latest posts

M
Replies
0
Views
1
MusicLovingIndianGirl
M
Q
Replies
0
Views
1
quora question
Q
Top