> ## Documentation Index
> Fetch the complete documentation index at: https://docs.loopreturns.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate Label

> Queue label generation for a return. This endpoint triggers an asynchronous label generation
process for the specified return.

#### Required API key scope
- Returns

#### Retrieving the Generated Label

After the label generation is queued (202 response), the label will be processed asynchronously.
Once generation is complete, you can retrieve the label data by calling the
[Get Return Details](/api-reference/latest/return-data/get-return-details) endpoint:

```
GET /warehouse/return/details?return_id={returnId}
```

The response will include a `labels` array containing the generated label with:
- `url`: The link to the shipping label PDF
- `tracking_number`: The tracking number for the shipment
- `carrier`: The shipping carrier (e.g., USPS, UPS)
- `status`: The current status of the label
- `rate`: The shipping cost

#### Successful Response
Returns HTTP 202 (Accepted) when the label generation has been successfully queued.

#### Error Responses
- **404 Not Found** (`return_not_found`): The specified return does not exist
- **409 Conflict** (`label_already_exists`): A label has already been generated for this return
- **422 Unprocessable Entity** (`return_cannot_receive_label`): The return is not in a valid state to
  receive a label
- **422 Unprocessable Entity** (`label_generation_failed`): A previous label generation attempt failed
- **500 Internal Server Error** (`internal_error`): An unexpected error occurred




## OpenAPI

````yaml post /returns/{returnId}/labels
openapi: 3.1.0
info:
  title: Labels API
  description: API for managing label requests
  version: v1
servers:
  - url: https://api.loopreturns.com/api/v1
security: []
tags:
  - name: Label Requests
paths:
  /returns/{returnId}/labels:
    post:
      tags:
        - Label Requests
      summary: Generate Label
      description: >
        Queue label generation for a return. This endpoint triggers an
        asynchronous label generation

        process for the specified return.


        #### Required API key scope

        - Returns


        #### Retrieving the Generated Label


        After the label generation is queued (202 response), the label will be
        processed asynchronously.

        Once generation is complete, you can retrieve the label data by calling
        the

        [Get Return
        Details](/api-reference/latest/return-data/get-return-details) endpoint:


        ```

        GET /warehouse/return/details?return_id={returnId}

        ```


        The response will include a `labels` array containing the generated
        label with:

        - `url`: The link to the shipping label PDF

        - `tracking_number`: The tracking number for the shipment

        - `carrier`: The shipping carrier (e.g., USPS, UPS)

        - `status`: The current status of the label

        - `rate`: The shipping cost


        #### Successful Response

        Returns HTTP 202 (Accepted) when the label generation has been
        successfully queued.


        #### Error Responses

        - **404 Not Found** (`return_not_found`): The specified return does not
        exist

        - **409 Conflict** (`label_already_exists`): A label has already been
        generated for this return

        - **422 Unprocessable Entity** (`return_cannot_receive_label`): The
        return is not in a valid state to
          receive a label
        - **422 Unprocessable Entity** (`label_generation_failed`): A previous
        label generation attempt failed

        - **500 Internal Server Error** (`internal_error`): An unexpected error
        occurred
      operationId: generate-label
      parameters:
        - in: path
          name: returnId
          schema:
            type: integer
            example: 12345
          required: true
          description: The unique identifier for the return, created by Loop.
      responses:
        '202':
          description: Label generation queued successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateLabelResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/GenerateLabelNotFound'
        '409':
          $ref: '#/components/responses/GenerateLabelConflict'
        '422':
          $ref: '#/components/responses/GenerateLabelUnprocessableEntity'
        '500':
          $ref: '#/components/responses/GenerateLabelInternalError'
      security:
        - oauth2:
            - returns
        - returns: []
components:
  schemas:
    GenerateLabelResponse:
      type: object
      properties:
        message:
          type: string
          description: Confirmation message that label generation has been queued.
          example: Label generation queued
        returnId:
          type: integer
          format: int64
          description: The return ID for which label generation was queued.
          example: 12345
      required:
        - message
        - returnId
  responses:
    Unauthorized:
      description: The request could not be authorized.
      content:
        application/json:
          schema:
            type: object
            properties:
              error:
                type: object
                properties:
                  code:
                    type: string
                    example: '401'
                  http_code:
                    type: string
                    example: GEN-UNAUTHORIZED
                  message:
                    type: string
                    example: Unauthorized.
    GenerateLabelNotFound:
      description: The specified return could not be found.
      content:
        application/json:
          schema:
            type: object
            properties:
              code:
                type: string
                example: return_not_found
              errors:
                type: array
                items:
                  type: string
                example:
                  - Return not found.
    GenerateLabelConflict:
      description: A label already exists for this return.
      content:
        application/json:
          schema:
            type: object
            properties:
              code:
                type: string
                example: label_already_exists
              errors:
                type: array
                items:
                  type: string
                example:
                  - Label already exists for return [12345].
    GenerateLabelUnprocessableEntity:
      description: The return cannot receive a label or label generation has failed.
      content:
        application/json:
          schema:
            type: object
            properties:
              code:
                type: string
                enum:
                  - return_cannot_receive_label
                  - label_generation_failed
                example: return_cannot_receive_label
              errors:
                type: array
                items:
                  type: string
                example:
                  - The return is not in a valid state to receive a label.
    GenerateLabelInternalError:
      description: An internal server error occurred.
      content:
        application/json:
          schema:
            type: object
            properties:
              code:
                type: string
                example: internal_error
              errors:
                type: array
                items:
                  type: string
                example:
                  - Error processing label request.
  securitySchemes:
    oauth2:
      type: oauth2
      flows:
        authorizationCode:
          authorizationUrl: https://oauth.loopreturns.com/authorize
          tokenUrl: https://oauth.loopreturns.com/oauth/token
          scopes:
            labels:read: Read access to labels
            labels:write: Create and modify labels
            label_requests:read: Read access to label requests
            label_requests:write: Create and modify label requests
            returns: Access to returns operations
    returns:
      name: X-Authorization
      type: apiKey
      in: header
      description: 'API Scope: "Returns"'
      x-scope: Returns

````