Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This article will try to explain DevOps “branching” & “merging” using dashboard API calls.

...

  1. Authenicate-GetToken

    • Hover over the folder called Create Branch, click the 3 dots and select Add Request which will create a request stub. Immediately rename it by hovering over the New Request, again click the 3 dots then click Rename and give it a name of Authenicate-GetToken

    • Change it to be a POST request

      Postman Create New Request.png

    • Enter the URL - this is where the variables become useful, simply enter:

      • {{DASHBOARD_URL}}{{DASHBOARD_API_PATH}}/tokens

      • Set the Authentication Type to Basic and enter references to the variables in Username and Password.

        Postman Create New Request-Auth.png
      • Add a little magic ! In the Scripts tab enter the code below which in simple terms grabs the dashboard token from the response of this POST request, which if we have supplied valid credentials, will have a value that we will capture and re-use in all subsequent API requests.

        • Code Block
          languagejava
          const jsonResponse = pm.response.json();
          pm.collectionVariables.set("DASHBOARD_TOKEN", jsonResponse.token);

...

  1. Export Main Data Connection

    • As before, hover over the folder called Create Branch, click the 3 dots and select Add Request which will create a request stub. Immediately rename it by hovering over the New Request, again click the 3 dots then click Rename and give it a name of Export Main Data Connection

    • Enter the URL - this is where the variables super useful, simply enter:

      • {{DASHBOARD_URL}}{{DASHBOARD_API_PATH}}/exportImportConnections/{{MAIN_DC_ID}}?orgId={{MAIN_ORG_ID}}

      • Set the Authentication Type to Bearer Token and enter the bearer token reference variable name.

        image-20241031-130603.png

      • Again, add a little magic to capture the exported output into a variable by way of a script. Click the script tab and enter the text below.

        Code Block
        let response = pm.response.json();
        pm.collectionVariables.set("MAIN_DC_EXPORT_JSON", JSON.stringify(response));

  2. Create Branch-Org

    • As before, hover over the folder called Create Branch, click the 3 dots and select Add Request which will create a request stub. Immediately rename it by hovering over the New Request, again click the 3 dots then click Rename and give it a name of Create Branch-Org

    • Change it to be a POST request (Image above if required)

    • Enter the URL

      • {{DASHBOARD_URL}}{{DASHBOARD_API_PATH}}/organisations

      • Set the Authentication Type to Bearer Token and enter the bearer token reference variable name. (as above)

      • In the Body (tab) enter the following:

        Code Block
        {
          "name":{{BRANCH_NAME}},
          "parentId": 1,
          "detachFromParent": false,
          "position": 1
        }
      • In the Scripts (tab) enter the following :

        Code Block
        const jsonResponse = pm.response.json();
        pm.collectionVariables.set("BRANCH_ID", jsonResponse.id);
        • This simply captures the id of the newly create branch and stores it in the Postman variable BRANCH_ID for later use.

  3. Import Exported DC to Branch

    • As before, hover over the folder called Create Branch, click the 3 dots and select Add Request which will create a request stub. Immediately rename it by hovering over the New Request, again click the 3 dots then click Rename and give it a name of Import Exported DC To Branch

    • Change it to be a POST request (Image above if required)

    • Enter the URL

      • {{DASHBOARD_URL}}{{DASHBOARD_API_PATH}}/exportImportConnections?orgid={{BRANCH_ID}}

      • Set the Authentication Type to Bearer Token and enter the bearer token reference variable name. (as above)

      • In the Body (tab) enter the following:

        Code Block
        {
            "json": {{MAIN_DC_EXPORT_JSON}}
        }

...

  1. Get Branch DC ID

    • Hover over the folder called Merge Branch, click the 3 dots and select Add Request which will create a request stub. Immediately rename it by hovering over the New Request, again click the 3 dots then click Rename and give it a name of Get Branch ID

    • Enter the URL

      • {{DASHBOARD_URL}}{{DASHBOARD_API_PATH}}/dataConnections?orgId={{BRANCH_ID}}

      • Set the Authentication Type to Bearer Token and enter the bearer token reference variable name.

      • Script - Click the script tab and enter the text below.

        Code Block
        let response = pm.response.json();
        pm.collectionVariables.set("BRANCH_DC_ID", response[0].id);
  2. Export Branch DC

    • Hover over the folder called Merge Branch, click the 3 dots and select Add Request which will create a request stub. Immediately rename it by hovering over the New Request, again click the 3 dots then click Rename and give it a name of Merge Branch DC

    • Enter the URL

      • {{DASHBOARD_URL}}{{DASHBOARD_API_PATH}}/exportImportConnections/{{BRANCH_DC_ID}}?orgid={{BRANCH_ID}}

      • Set the Authentication Type to Bearer Token and enter the bearer token reference variable name.

      • Script - Click the script tab and enter the text below which populates the variable BRANCH_DC_EXPORT_JSON with our edited content.

        Code Block
        let response = pm.response.json();
        pm.collectionVariables.set("BRANCH_DC_EXPORT_JSON", JSON.stringify(response));
  3. Export Branch DC

    • Hover over the folder called Merge Branch, click the 3 dots and select Add Request which will create a request stub. Immediately rename it by hovering over the New Request, again click the 3 dots then click Rename and give it a name of Import Branch DC to Main

    • Enter the URL

      • {{DASHBOARD_URL}}{{DASHBOARD_API_PATH}}/exportImportConnections/?orgid={{BRANCH_ID}}

      • Set the Authentication Type to Bearer Token and enter the bearer token reference variable name.

      • Body - The body of this request will pass the content via a variable. Enter the text as below:

        Code Block
        {
            "json": {{MAIN_DC_EXPORT_JSON}}
        }

...

Check out the article on creating N number of users in a dashboard using just 2 postman requests that are employed as part of a Postman Flow

...

Adding Users to a Dashboard with Postman Flows - pi Documentation - Confluence