Skip to content

bigfunctions > post

post

Call or Deploy post ?

✅ You can call this post bigfunction directly from your Google Cloud Project (no install required).

  • This post function is deployed in bigfunctions GCP project in 39 datasets for all of the 39 BigQuery regions. You need to use the dataset in the same region as your datasets (otherwise you may have a function not found error).
  • Function is public, so it can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
  • You may prefer to deploy the BigFunction in your own project if you want to build and manage your own catalog of functions. This is particularly useful if you want to create private functions (for example calling your internal APIs). Discover the framework

Public BigFunctions Datasets:

Region Dataset
eu bigfunctions.eu
us bigfunctions.us
europe-west1 bigfunctions.europe_west1
asia-east1 bigfunctions.asia_east1
... ...

Description

Signature

post(url, data, headers)

Description

POST data to url. response is a json formatted as {status_code, content}

Examples

Without headers

select bigfunctions.eu.post('https://httpbin.org/post', json '{"hello": "world"}', null)
select bigfunctions.us.post('https://httpbin.org/post', json '{"hello": "world"}', null)
select bigfunctions.europe_west1.post('https://httpbin.org/post', json '{"hello": "world"}', null)
+-----------------------------------------------+
| response                                      |
+-----------------------------------------------+
| {
  "content": {...},
  "status_code": 200
}
 |
+-----------------------------------------------+

Need help using post?

The community can help! Engage the conversation on Slack

For professional suppport, don't hesitate to chat with us.

Found a bug using post?

If the function does not work as expected, please

  • report a bug so that it can be improved.
  • or open the discussion with the community on Slack.

For professional suppport, don't hesitate to chat with us.

Use cases

This post BigQuery function could be used in several scenarios:

1. Sending Data to a Webhook:

Imagine you have a BigQuery table that tracks user sign-ups. You could use the post function to send real-time notifications to a Slack channel or other messaging platform via a webhook every time a new user registers. The data parameter would contain the user information you want to send in the notification.

SELECT bigfunctions.us.post('YOUR_WEBHOOK_URL', TO_JSON_STRING(new_users), NULL)
FROM project.dataset.new_users;

2. Interacting with an API:

You could use post to interact with REST APIs from within BigQuery. For example, you might want to enrich your data with information from a third-party service. After performing some transformations on your data in BigQuery, you could use the post function to send the transformed data to the API endpoint, receive the response, and then process it further within BigQuery.

SELECT bigfunctions.us.post('https://api.example.com/data', TO_JSON_STRING(t), NULL)
FROM (
  SELECT user_id, SUM(order_value) as total_spent
  FROM project.dataset.orders
  GROUP BY user_id
) AS t;

3. Triggering Actions in External Systems:

Suppose you have a BigQuery table that monitors key performance indicators (KPIs). If a KPI falls below a certain threshold, you could use the post function to trigger an action in an external system. This could be anything from sending an alert email to initiating a process in a workflow automation tool.

SELECT bigfunctions.us.post('https://api.example.com/alert', TO_JSON_STRING(t), NULL)
FROM (
  SELECT *
  FROM project.dataset.kpis
  WHERE kpi_value < threshold
) AS t;

4. Sending Data to a Real-time Dashboard:

If you are using a real-time dashboarding tool, you could use the post function to send data updates directly from BigQuery. This would allow you to keep your dashboards up-to-date with the latest information without needing to build complex data pipelines.

SELECT bigfunctions.us.post('https://api.dashboard.com/update', TO_JSON_STRING(t), NULL)
FROM (
  SELECT COUNT(*) AS active_users
  FROM project.dataset.users
  WHERE last_seen > TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 HOUR)
) AS t;

Key Considerations:

  • Data Format: The data parameter must be a valid JSON string. You can use the TO_JSON_STRING function in BigQuery to convert your data into the required format.
  • Headers: The headers parameter allows you to set custom HTTP headers for your request. This can be useful for authentication or setting content types. Pass NULL if no headers are needed.
  • Error Handling: You should implement proper error handling to ensure that your queries are resilient to network issues or API errors. Check the status_code in the response to determine if the request was successful.
  • Rate Limiting: Be mindful of rate limits imposed by the API you are interacting with. You might need to implement retry mechanisms or introduce delays to avoid exceeding these limits.
  • Security: If you are sending sensitive data, ensure that the connection to the API is secure (HTTPS) and consider using appropriate authentication methods.

By leveraging the post function, you can extend the functionality of BigQuery and seamlessly integrate it with other systems and services. This opens up a wide range of possibilities for automating tasks, enriching data, and building more dynamic data-driven applications.

Spread the word

BigFunctions is fully open-source. Help make it a success by spreading the word!

Share on Add a on