User guides - Example workflow

Example - read and modify JSON to send to another API

Let's first understand the workflow using this flowchart -

1920

this is an imaginary scenario

This is a simple 2 step process, We first get the JSON data from an API, then modify it and post it to another API. The retry block here is default.

{
  "flow": [
    {
      "concurrency": 1,
      "apispec": {
        "url": "<<{{BASEURL}}/json/feed1>>",
        "method": "get",
        "headers": {
          "content_type": "application/json",
          "authorization": "Bearer {{USER.token}}"        }
      },
      "retry": {
        "total": 5,
        "connect": 4,
        "read": 4,
        "redirect": 4,
        "status": 4,
        "other": 0,
        "allowed_methods": [
          "GET",
          "PUT",
          "POST"
        ],
        "status_forcelist": [
          413,
          429,
          502,
          503,
          504
        ],
        "backoff_factor": 1,
        "raise_on_redirect": true,
        "respect_retry_after_header": true,
        "raise_on_status": true
      },
      "name": "getjson"
    }
    {
      "concurrency": 1,
      "input": "[{% for item in STEPS.getjson %}{<modification changes>},{% endfor %}]",
      "apispec": {
        "url": "<<https://graph.feed.com/json/feed>>",
        "method": "post",
        "data": "{{THREADLOCAL}}"
      },
      "name": "modifyandpost"
    }
  ],
  "default_retry": {
    "total": 4,
    "connect": 3,
    "read": 3,
    "redirect": 3,
    "status": 3,
    "other": 0,
    "allowed_methods": [
      "GET",
      "PUT",
      "POST"
    ],
    "status_forcelist": [
      413,
      429,
      503
    ],
    "backoff_factor": 1,
    "raise_on_redirect": true,
    "respect_retry_after_header": true,
    "raise_on_status": true
  }
}

Example - publish a project feed to facebook

Let's first understand the workflow using this flowchart -

1920
{
  "flow": [
    {
      "concurrency": 1,
      "apispec": {
        "url": "{{SYSTEM_APIS.credentials}}",
        "method": "get",
        "headers": {
          "content_type": "application/json",
          "authorization": "Bearer {{USER.token}}",
          "x-kubric-workspace-id": "{{USER.workspace_id}}"
        }
      },
      "retry": {
        "total": 5,
        "connect": 4,
        "read": 4,
        "redirect": 4,
        "status": 4,
        "other": 0,
        "allowed_methods": [
          "GET",
          "PUT",
          "POST"
        ],
        "status_forcelist": [
          413,
          429,
          502,
          503,
          504
        ],
        "backoff_factor": 1,
        "raise_on_redirect": true,
        "respect_retry_after_header": true,
        "raise_on_status": true
      },
      "name": "auth",
      "output": "{{CURRENT_STEP.response.facebook}}"
    },
    {
      "input": "{% if STEPS.auth is none%}{{ FUNCTIONS.raise_value_error(\"facebook token from auth step is empty. have you connected your facebook account?\") }}{% endif %}",
      "apispec": {
        "url": "https://graph.facebook.com/{{INPUT.page_id}}?fields=access_token&access_token={{STEPS.auth.token}}",
        "method": "get",
        "headers": {
          "content_type": "application/json"
        }
      },
      "name": "fb_page_token"
    },
    {
      "concurrency": 2,
      "input": "[{% for item in INPUT.ad_url %}{\"url\": \"{{item}}\",\"published\": False,\"access_token\": \"{{STEPS.fb_page_token.access_token}}\"},{% endfor %}]",
      "apispec": {
        "url": "https://graph.facebook.com/{{INPUT.page_id}}/photos",
        "method": "post",
        "data": "{{THREADLOCAL}}"
      },
      "name": "fb_page_photo_upload"
    },
    {
      "input": "{ {% for item in STEPS.fb_page_photo_upload %}\"attached_media[{{ loop.index0 }}]\": \"{\\\"media_fbid\\\":\\\"{{ item.id }}\\\"}\",{% endfor %}\"message\": \"{{ INPUT.caption }}\",\"access_token\": \"{{STEPS.fb_page_token.access_token}}\",{% if \"schedule_time\" in INPUT %}{% set _ = FUNCTIONS.is_valid_time(INPUT.schedule_time, FUNCTIONS.current_time() + 600, FUNCTIONS.current_time() + 16070400) %}\"published\": False,\"scheduled_publish_time\": {{INPUT.schedule_time}},\"unpublished_content_type\": \"SCHEDULED\"{% endif %}}",
      "apispec": {
        "url": "https://graph.facebook.com/me/feed",
        "method": "post",
        "data": "{{CURRENT_STEP.input}}"
      },
      "name": "fb_page_create_post"
    }
  ],
  "default_retry": {
    "total": 4,
    "connect": 3,
    "read": 3,
    "redirect": 3,
    "status": 3,
    "other": 0,
    "allowed_methods": [
      "GET",
      "PUT",
      "POST"
    ],
    "status_forcelist": [
      413,
      429,
      503
    ],
    "backoff_factor": 1,
    "raise_on_redirect": true,
    "respect_retry_after_header": true,
    "raise_on_status": true
  }
}

(this page is still a work in progress, we're adding more examples for you)