Push data from one API to another API

Hi, glad to be here & learn all about API’s and Postman :slight_smile:

Here’s what I’m trying to accomplish:

  1. GET data from Timing App’s API (DONE, testing only)
  2. POST that data into my invoicing app Wave to create an invoice. (DONE, testing only)

What I am unclear on is how to migrate/transfer/move the data (duration of hours, title or client name) from the GET in step 1 to the POST in step 2. I can POST to Wave and an invoice is created but only with testing code. I am yet to actually merge the GET & POST data from actual tracked hours to an actual new invoice.

GET
https://web.timingapp.com/api/v1/time-entries?include_project_data=true
Below is an example of GET results from Timing App’s API docs.

{
    "data": [
        {
            "self": "/time-entries/3466676958206930176",
            "start_date": "2021-02-25T23:17:26.550757+00:00",
            "end_date": "2021-02-25T23:32:48.353939+00:00",
            "duration": 921.803182,
            "project": {
                "self": "/projects/1582482660025863380",
                "membership_id": null,
                "title": "CLIENT NAME",
                "title_chain": [
                    "CLIENT NAME"
                ],
                "color": "#8C4F00FF",
                "productivity_score": 1,
                "is_archived": false,
                "parent": null
            },
            "title": null,
            "notes": null,
            "is_running": false,
            "creator_name": "example@example.com"
        }, . . .

POST
https://gql.waveapps.com/graphql/public
Below is an example of POST results from Wave API Create Invoice docs.

{
    "data": {
        "invoiceCreate": {
            "didSucceed": true,
            "inputErrors": null,
            "invoice": {
                "id": "QnVzaW5lc3M6YTgyMmRlZDktNjBhYS00NGE2LWJiN2EtYzAxM2VjNjRmMmJkO0ludm9pY2U6MTE0MzYzNjU5MTc2ODYxMjAwMQ==",
                "createdAt": "2021-02-26T16:12:19.584Z",
                "modifiedAt": "2021-02-26T16:12:19.641Z",
                "pdfUrl": "https://example.com",
                "viewUrl": "https://example.com",
                "status": "DRAFT",
                "title": "Invoice",
                "subhead": "",
                "invoiceNumber": "149",
                "invoiceDate": "2021-02-26",
                "poNumber": "",
                "customer": {
                    "id": "QnVzaW5lc3M6YTgyMmRlZDktNjBhYS00NGE2LWJiN2EtYzAxM2VjNjRmMmJkO0N1c3RvbWVyOjI1NDk3MzAx",
                    "name": "CLIENT NAME"
                },
                "currency": {
                    "code": "USD"
                },
                "dueDate": "2021-03-13",
                "amountDue": {
                    "value": "1.00",
                    "currency": {
                        "symbol": "$"
                    }
                },
                "amountPaid": {
                    "value": "0.00",
                    "currency": {
                        "symbol": "$"
                    }
                },
                "taxTotal": {
                    "value": "0.00",
                    "currency": {
                        "symbol": "$"
                    }
                },
                "total": {
                    "value": "45.00",
                    "currency": {
                        "symbol": "$"
                    }
                },
                "exchangeRate": "1",
                "footer": "Thank you very much!",
                "memo": "",
                "disableCreditCardPayments": true,
                "disableBankPayments": false,
                "itemTitle": "Services",
                "unitTitle": "Hours",
                "priceTitle": "Per Hour",
                "amountTitle": "Total",
                "hideName": false,
                "hideDescription": false,
                "hideUnit": false,
                "hidePrice": false,
                "hideAmount": false,
                "items": [
                    {
                        "product": {
                            "id": "QnVzaW5lc3M6YTgyMmRlZDktNjBhYS00NGE2LWJiN2EtYzAxM2VjNjRmMmJkO1Byb2R1Y3Q6MzA1MzA5NzM=",
                            "name": "Plugin Issues"
                        },
                        "description": "Hrs from 02/27/19 to 05/30/19",
                        "quantity": "1",
                        "price": "1",
                        "subtotal": {
                            "value": "1.00",
                            "currency": {
                                "symbol": "$"
                            }
                        },
                        "total": {
                            "value": "1.00",
                            "currency": {
                                "symbol": "$"
                            }
                        },
                        "account": {
                            "id": "QWNjb3VudDo0MjMxMTU1NTE2MzI1NjQ0Njc7QnVzaW5lc3M6YTgyMmRlZDktNjBhYS00NGE2LWJiN2EtYzAxM2VjNjRmMmJk",
                            "name": "Sales",
                            "subtype": {
                                "name": "Income",
                                "value": "INCOME"
                            }
                        },
                        "taxes": []
                    }
                ],
                "lastSentAt": null,
                "lastSentVia": "NOT_SENT",
                "lastViewedAt": null
            }
        }
    }
}

I hope my explanation makes sense of what I’m trying to do :upside_down_face:

Thank you for your help!

Hi @luke, Welcome to the community!

It seems you are trying to do the integration and transformation logic from POSTMAN.

One way to do is, to have 2 requests created (GET, POST). Within GET request you, transform your response to the request structure of POST request using javascript and then store it to either, global, environment or collection variables.

const mark1 = <JSON Transformed DATA>;
pm.set.environment("inputToPOST",mark1);

In the POST request you may use the same variable set in the previous response from GET response, as body.
{{inputToPOST}}

Hope it helps!

make sure you stringify the request as the request body expects a string

  pm.set.environment("inputToPOST",JSON.stringify(mark1));
1 Like

Thank you @praveendvd for correcting that one

1 Like

Hi guys, I am new to apis and postman, so I would love any blog resources or anything really that can help explain moving information from an old crm to a new hubspot account. Looking forward to your input.