API
GuidesGet API token
You’re viewing the reference for API version 2021-01.See the latest version, 2021-11 →
Async Batch

Async batch tasks

Most commonly, the response from listing tasks on an async_batch id will be identical to the body of a singular request to standard Recharge API endpoints. However, in some instances there are variations from the standard list task response body. See below for examples corresponding to each batch_type.

Related guides: Examples of async batches

#The Async batch tasks object

Attributes

  • batch_idinteger
    Indicates the batch that the task is contained by
  • bodyobject
    This object contains the body of a standard API request. For example, when creating discounts with a discount_create batch, this parameter contains a standard body for POST /discounts
  • completed_atdatetime
    Indicates the date and time a task was completed
  • created_atdatetime
    Indicates the date and time that a task was created and added to the batch
  • deleted_atdatetime
    Indicates the date and time that a task was deleted from the batch
  • idinteger
    Unique identifier for the task within a batch
  • queued_atdatetime
    Indicates the date and time a task was queued for processing within batch processing
  • resultstring
    Contains the individual response body for the task
  • started_atdatetime
    Indicates the date and time a task was processed
  • statusstring
    Indicates the status of the task within a batch.
    Possible values
    pendingprocessingfailedsuccess
  • updated_atdatetime
    Indicates the date and time a task was most recently updated
The Async batch tasks object
{
  "async_batch_tasks": [
    {
      "id": 22048,
      "batch_id": 16,
      "body": {
        "code": "19476193",
        "discount_type": "shipping",
        "duration": "forever",
        "status": "enabled",
        "value": 100
      },
      "completed_at": "2020-05-29T09:23:07",
      "created_at": "2020-05-29T09:19:38",
      "deleted_at": null,
      "queued_at": "2020-05-29T09:23:06",
      "result": {
        "output": {
          "discount": {
            "id": 28288390,
            "applies_to": null,
            "applies_to_id": null,
            "applies_to_product_type": "ALL",
            "applies_to_resource": null,
            "channel_settings": {
              "api": {
                "can_apply": true
              },
              "checkout_page": {
                "can_apply": true
              },
              "customer_portal": {
                "can_apply": true
              },
              "merchant_portal": {
                "can_apply": true
              }
            },
            "code": "19476193",
            "created_at": "2020-05-29T09:23:06",
            "discount_type": "shipping",
            "duration": "forever",
            "duration_usage_limit": null,
            "ends_at": null,
            "first_time_customer_restriction": null,
            "once_per_customer": false,
            "prerequisite_subtotal_min": null,
            "starts_at": null,
            "status": "enabled",
            "times_used": 0,
            "updated_at": "2020-05-29T09:23:06",
            "usage_limit": null,
            "value": 100
          }
        },
        "status_code": 200
      },
      "started_at": "2020-05-29T09:23:06",
      "status": "success",
      "updated_at": "2020-05-29T09:23:07"
    },
    {
      "id": 22047,
      "batch_id": 16,
      "body": {
        "code": "28831178",
        "discount_type": "shipping",
        "duration": "forever",
        "status": "enabled",
        "value": 100
      },
      "completed_at": "2020-05-29T09:23:07",
      "created_at": "2020-05-29T09:19:38",
      "deleted_at": null,
      "queued_at": "2020-05-29T09:23:06",
      "result": {
        "output": {
          "discount": {
            "applies_to": null,
            "applies_to_id": null,
            "applies_to_product_type": "ALL",
            "applies_to_resource": null,
            "channel_settings": {
              "api": {
                "can_apply": true
              },
              "checkout_page": {
                "can_apply": true
              },
              "customer_portal": {
                "can_apply": true
              },
              "merchant_portal": {
                "can_apply": true
              }
            },
            "code": "28831178",
            "created_at": "2020-05-29T09:23:06",
            "discount_type": "shipping",
            "duration": "forever",
            "duration_usage_limit": null,
            "ends_at": null,
            "first_time_customer_restriction": null,
            "id": 28288389,
            "once_per_customer": false,
            "prerequisite_subtotal_min": null,
            "starts_at": null,
            "status": "enabled",
            "times_used": 0,
            "updated_at": "2020-05-29T09:23:06",
            "usage_limit": null,
            "value": 100
          }
        },
        "status_code": 200
      },
      "started_at": "2020-05-29T09:23:06",
      "status": "success",
      "updated_at": "2020-05-29T09:23:07"
    },
    {}
  ]
}

#Create a batch task

POST/async_batches/{batch_id}/tasks
A batch contains operations of similar type (indicated by batch_type), called tasks. A task is typically representative of a single API request, with a body parameter containing the standard request body for the associated batch_type. A single request to add tasks may contain up to 1,000 tasks, and a batch may contain up to 10,000 tasks.

##HTTP examples

POST /async_batches/<batch_id>/tasks
Batches will only leverage resources from the same version they are created in. e.g. a batch created with 2021-11 will only process tasks from the 2021-11 version.

Body parameters

  • batch_idinteger
    Indicates the batch that the task is contained by
  • bodyobject
    This object contains the body of a standard API request. For example, when creating discounts with a discount_create batch, this parameter contains a standard body for POST /discounts
  • completed_atdatetime
    Indicates the date and time a task was completed
  • created_atdatetime
    Indicates the date and time that a task was created and added to the batch
  • deleted_atdatetime
    Indicates the date and time that a task was deleted from the batch
  • idinteger
    Unique identifier for the task within a batch
  • queued_atdatetime
    Indicates the date and time a task was queued for processing within batch processing
  • resultstring
    Contains the individual response body for the task
  • started_atdatetime
    Indicates the date and time a task was processed
  • statusstring
    Indicates the status of the task within a batch.
    Possible values
    pendingprocessingfailedsuccess
  • updated_atdatetime
    Indicates the date and time a task was most recently updated

Response attributes

  • Indicates the object type and operation required for all tasks in a batch
    Possible values
    address_discount_applyaddress_discount_removediscount_creatediscount_deletediscount_updateproduct_createproduct_updateproduct_deleteonetime_createonetime_deletebulk_subscriptions_createbulk_subscriptions_updatebulk_subscriptions_deletesubscription_cancel
    Batches will only leverage resources from the same version they are created in. e.g. a batch created with 2021-11 will only process tasks from the 2021-11 version.
  • closed_atstring
    Indicates the date and time that processing was completed for a batch
  • Indicates the date and time a batch was created
  • Indicates the number of failed tasks in a batch, during or after processing
  • idstring
    Unique identifier of the batch, used for adding tasks to a batch and to initiate batch processing
  • statusstring
    Indicates the status of the batch. Available statuses are not_started, processing, completed, failed
  • Indicates the date and time that a batch was triggered to process
  • Indicates the number of successful tasks in a batch, during or after processing.
  • Indicates the total number of tasks in a batch
  • Indicates the date and time at which a batch was last updated
  • versionstring
    Indicates the date and time at which a batch was last updated
POST/async_batches/{batch_id}/tasks
curl -X POST 'https://api.rechargeapps.com/async_batches/21/tasks' \
  -H 'X-Recharge-Access-Token: your_api_token' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "tasks": [
    {
      "body": {
        "code": "indexing",
        "discount_type": "shipping",
        "duration": "forever",
        "status": "enabled",
        "value": 100
      }
    },
    {
      "body": {
        "code": "maroon",
        "discount_type": "shipping",
        "duration": "forever",
        "status": "enabled",
        "value": 100
      }
    },
    {
      "body": {
        "code": "web services",
        "value": 100,
        "discount_type": "shipping",
        "duration": "forever",
        "status": "enabled"
      }
    },
    {
      "body": {
        "code": "PCI",
        "discount_type": "shipping",
        "duration": "forever",
        "status": "enabled",
        "value": 100
      }
    },
    {
      "body": {
        "code": "Cheese",
        "discount_type": "shipping",
        "duration": "forever",
        "status": "enabled",
        "value": 100
      }
    },
    {
      "body": {
        "code": "overriding",
        "discount_type": "shipping",
        "duration": "forever",
        "status": "enabled",
        "value": 100
      }
    },
    {
      "body": {
        "code": "bandwidth-monitored",
        "value": 100,
        "discount_type": "shipping",
        "duration": "forever",
        "status": "enabled"
      }
    },
    {
      "body": {
        "code": "Falkland Islands (Malvinas)",
        "discount_type": "shipping",
        "duration": "forever",
        "status": "enabled",
        "value": 100
      }
    },
    {
      "body": {
        "code": "Computer",
        "discount_type": "shipping",
        "duration": "forever",
        "status": "enabled",
        "value": 100
      }
    },
    {
      "body": {
        "code": "digital",
        "discount_type": "shipping",
        "duration": "forever",
        "status": "enabled",
        "value": 100
      }
    }
  ]
}'
Response
{
  "count": 10
}

#List batch tasks

GET/async_batches/{batch_id}/tasks
Returns a list of all tasks in the indicated batch, using batch id. For batches with many tasks, pagination is supported when listing tasks. Use this function to evaluate the task-level results of a batch during, or after processing. Task results will be contained in the results object of each task.

Query parameters

  • idsstring
    Filter tasks by id. If passing multiple values, must be comma separated. Non-integer values will result in a 422 error
GET/async_batches/{batch_id}/tasks
curl 'https://api.rechargeapps.com/async_batches/16/tasks' \
  -H 'X-Recharge-Access-Token: your_api_token' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json'
Response
{
  "async_batch_tasks": [
    {
      "id": 22048,
      "batch_id": 16,
      "body": {
        "code": "19476193",
        "discount_type": "shipping",
        "duration": "forever",
        "status": "enabled",
        "value": 100
      },
      "completed_at": "2020-05-29T09:23:07",
      "created_at": "2020-05-29T09:19:38",
      "deleted_at": null,
      "queued_at": "2020-05-29T09:23:06",
      "result": {
        "output": {
          "discount": {
            "id": 28288390,
            "applies_to": null,
            "applies_to_id": null,
            "applies_to_product_type": "ALL",
            "applies_to_resource": null,
            "channel_settings": {
              "api": {
                "can_apply": true
              },
              "checkout_page": {
                "can_apply": true
              },
              "customer_portal": {
                "can_apply": true
              },
              "merchant_portal": {
                "can_apply": true
              }
            },
            "code": "19476193",
            "created_at": "2020-05-29T09:23:06",
            "discount_type": "shipping",
            "duration": "forever",
            "duration_usage_limit": null,
            "ends_at": null,
            "first_time_customer_restriction": null,
            "once_per_customer": false,
            "prerequisite_subtotal_min": null,
            "starts_at": null,
            "status": "enabled",
            "times_used": 0,
            "updated_at": "2020-05-29T09:23:06",
            "usage_limit": null,
            "value": 100
          }
        },
        "status_code": 200
      },
      "started_at": "2020-05-29T09:23:06",
      "status": "success",
      "updated_at": "2020-05-29T09:23:07"
    },
    {
      "id": 22047,
      "batch_id": 16,
      "body": {
        "code": "28831178",
        "discount_type": "shipping",
        "duration": "forever",
        "status": "enabled",
        "value": 100
      },
      "completed_at": "2020-05-29T09:23:07",
      "created_at": "2020-05-29T09:19:38",
      "deleted_at": null,
      "queued_at": "2020-05-29T09:23:06",
      "result": {
        "output": {
          "discount": {
            "applies_to": null,
            "applies_to_id": null,
            "applies_to_product_type": "ALL",
            "applies_to_resource": null,
            "channel_settings": {
              "api": {
                "can_apply": true
              },
              "checkout_page": {
                "can_apply": true
              },
              "customer_portal": {
                "can_apply": true
              },
              "merchant_portal": {
                "can_apply": true
              }
            },
            "code": "28831178",
            "created_at": "2020-05-29T09:23:06",
            "discount_type": "shipping",
            "duration": "forever",
            "duration_usage_limit": null,
            "ends_at": null,
            "first_time_customer_restriction": null,
            "id": 28288389,
            "once_per_customer": false,
            "prerequisite_subtotal_min": null,
            "starts_at": null,
            "status": "enabled",
            "times_used": 0,
            "updated_at": "2020-05-29T09:23:06",
            "usage_limit": null,
            "value": 100
          }
        },
        "status_code": 200
      },
      "started_at": "2020-05-29T09:23:06",
      "status": "success",
      "updated_at": "2020-05-29T09:23:07"
    },
    {}
  ]
}