Queries LibraryExport user data to AirTable
Export user data to AirTable
This query retrieves all the users from the WordPress site, and creates records on AirTable, using the AirTable API and personal access tokens for authentication.
Make sure to create a personal access token for your table, and assign it scope data.records:write
.
In this example query, the table has columns Name
, URL
and Email
, and we retrieve and send those data fields for each user.
query ExportUserData {
users {
displayName
email
url
userEntry: _echo(value: {
fields: {
Name: $__displayName,
URL: $__url,
Email: $__email,
}
})
@export(as: "userEntries", type: LIST)
@remove
}
}
query CreateRecordsInAirTable(
$baseId: String!
$tableName: String!
$personalAccessToken: String!
)
@depends(on: "ExportUserData")
{
url: _sprintf(
string: "https://api.airtable.com/v0/%s/%s",
values: [$baseId, $tableName]
)
bearerToken: _sprintf(
string: "Bearer %s",
values: [$personalAccessToken]
)
@remove
response: _sendJSONObjectItemHTTPRequest(input: {
url: $__url,
method: POST,
options: {
headers: [
{
name: "Authorization",
value: $__bearerToken
}
]
json: {
records: $userEntries
}
}
})
}
You must provide the JSON dictionary for the following GraphQL variables:
{
"baseId": "{ your baseId }",
"tableName": "{ your tableName }",
"personalAccessToken": "{ your access token }"
}