Fetch Json data from API and instert it as a wordpress page

924 Views Asked by At

so I am working with Clickup API, there we have a number of lists we would like to fetch the data from and insert that data as a wordpress post for our website.

I have tested all the API requests with Postman and the data i get back is similar to this, basically would need to fetch the data with "custom fields", but I am not sure how to work it out with PHP, any help would be appreciated.

"custom_fields": [
                {
                    "id": "39ed2191-443e-4d45-84d4-de9eff89cc97",
                    "name": "Cost",
                    "type": "currency",
                    "type_config": {
                        "default": null,
                        "precision": 2,
                        "currency_type": "USD"
                    },
                    "date_created": "1616008796860",
                    "hide_from_guests": false,
                    "required": false
                },
                {
                    "id": "bcca51b8-a903-4194-8d24-8e663de0618e",
                    "name": "Deadline",
                    "type": "short_text",
                    "type_config": {},
                    "date_created": "1613070997077",
                    "hide_from_guests": false,
                    "required": false
                },
                {
                    "id": "35af20c5-5469-40b6-afc7-d7e9d5f3c451",
                    "name": "Industry",
                    "type": "drop_down",
                    "type_config": {
                        "default": 0,
                        "placeholder": null,
                        "new_drop_down": true,
                        "options": [
                            {
                                "id": "227658be-5cc6-4c33-a539-029c13a18416",
                                "name": "Agriculture",
                                "color": null,
                                "orderindex": 0
                            },
                            {
                                "id": "2d5041ff-e557-42ae-859a-51698d01d2f7",
                                "name": "Automation",
                                "color": null,
                                "orderindex": 1
                            },
                            {
                                "id": "d2c33aa5-de68-4f16-ad79-5308893c66a6",
                                "name": "Beauty",
                                "color": null,
                                "orderindex": 2
                            },
                            {
                                "id": "bcbf40c4-bcb8-41c4-81ed-7afffca9eccd",
                                "name": "Construction",
                                "color": null,
                                "orderindex": 3
                            },
                            {
                                "id": "47bc5b7d-0fb9-4c64-8887-249e55d31f85",
                                "name": "Sanitation",
                                "color": null,
                                "orderindex": 4
                            },
                            {
                                "id": "10b0e274-4996-4cc9-9c1e-4d44f78694d1",
                                "name": "Travel",
                                "color": null,
                                "orderindex": 5
                            }
                        ]
                    },
                    "date_created": "1639080879165",
                    "hide_from_guests": false,
                    "required": false
                },
1

There are 1 best solutions below

0
On

Here's a very abstract description of the possible steps you'll need to take:

  1. Fetch the data using wp_remote_request()
  2. Parse the data using json_decode()
  3. Get all the data you need from the object(-s)
  4. Create a post using wp_insert_post()
  5. Save all the additional data in the post(-s) meta fields using update_post_meta()