This article is a quick tip to harvest the benefit of REST API by performing full extract refresh of a published datasource by calling a set of endpoints.

  1. Sign-In into to Tableau Server

This is must needed step to authenticate any endpoints in Tableau.

curl --location --request POST 'https://tableau-server//api/3.3//auth//signin' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Content-Type: text/plain' \
--data-raw '{
 "credentials": {
  "name":"<server-admin-login>",
  "password":"<password",
 "site": {
  "contentUrl":"<site-id>"
  }
 }
}'

In Response,

{
    "credentials": {
        "site": {
            "id": "<internal-site-id>",
            "contentUrl": "<site-content-url>"
        },
        "user": {
            "id": "<user-Id>"
        },
        "token": "<auth-token>"
    }
}

Store the <internal-site-id> and <auth-token> to supply in subsequent requests.

2. Get Datasource Details

Use the data source name as the value for filter param and internal-site-id in the URL route.

curl --location --request GET 'https://tableau-server//api/3.3//sites/<internal-site-id>/datasources?filter=name:eq:<datasoure-name>' \
--header 'X-Tableau-Auth: <auth-token>' \
--header 'Accept: application/json'

In response,

{
    "pagination": {
        "pageNumber": "1",
        "pageSize": "100",
        "totalAvailable": "1"
    },
    "datasources": {
        "datasource": [
            {
                "project": {
                    "id": "733f0c7d-7e48-42c3-97df-6c6fdba22bcf",
                    "name": "Shared"
                },
                "owner": {
                    "id": "1f5059a6-f3d4-48cb-970e-26b8f133dc0d"
                },
                "tags": {},
                "contentUrl": "Datasource_15689191808770",
                "createdAt": "2019-09-19T18:53:00Z",
                "encryptExtracts": "false",
                "id": "<datasource-id>",
                "isCertified": false,
                "name": "Datasource Name",
                "type": "sqlserver",
                "updatedAt": "2020-05-11T00:32:22Z",
                "webpageUrl": "https://<tableau-server.com>/#/site/<internal-site-id>/datasources/1455"
            }
        ]
    }
}

Store the datasource-id to use in subsequent request.

3. Initiate Full Refresh Extract

curl --location --request POST 'https://tableau-server//api/3.3//sites/<internal-site-id>/datasources/<datasource-id>/refresh' \
--header 'X-Tableau-Auth: <auth-token>' \
--header 'Accept: application/json' \
--header 'Content-Type: application/xml' \
--data-raw '<tsRequest></tsRequest>'

4. Check Refresh Job Status

curl --location --request GET 'https://tableau-server//api/3.3//sites/<internal-site-id>/jobs/<job-id>' \
--header 'X-Tableau-Auth: <auth-token>' \
--header 'Accept: application/json'

In response,

{
"job": {
"extractRefreshJob": {
"notes": "Finished refresh of extracts (new extract id:{0A62BDE7-3683-419C-8EE3-4E8F07FA2E41}) for Data Source '<data soure name>'",
"datasource": {
"id": "aaddd460-1124-472f-98ab-fbdc54ee5ff9",
"name": "<datasource name>"
}
},
"id": "7d7fe8a4-ee46-46f0-8504-d81cab61ee3b",
"mode": "Asynchronous",
"type": "RefreshExtract",
"progress": "100",
"createdAt": "2020-05-18T15:33:30Z",
"startedAt": "2020-05-18T15:33:35Z",
"completedAt": "2020-05-18T15:33:37Z",
"finishCode": "0"
}
}

keep executing this endpoint until the progress value is 100 and finishcode is 0. The progress value is the indication of how much percentage of extract got completed. The finishcode is 1 for errored extracts.

There are a lot more we can do with API, we developed in-house deployment automation with the set of API using .NET Core to make our deployment process simple. Happy programming !!