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

# Create custom drugs bulk

> Bulk-creates organization-level custom drugs. Accepts a JSON array; returns a per-item success/failure summary.

Bulk-creates **organization-level** custom drugs (the shared org catalog, stored against `ORGANIZATION#{organization_id}`).

## Integration Notes

1. **Scope Requirement**: Your API token must include the `create:custom_drug` scope.
2. **Organization admin/owner required**: The acting user (the token's `user_id`) must be an organization **owner** or **admin**. A token that carries the correct scope but whose user is a non-admin (e.g. a prescriber) is rejected with `401 Unauthorized`. This restriction applies only to the organization-level (bulk) endpoints; the user-level custom-drug endpoints have no such requirement.
3. **Level**: This endpoint creates organization-level drugs. Use the user-level endpoint to add a drug for a specific prescriber.
4. **Body**: A non-empty JSON array of custom drug objects (a single drug is a one-element array).
5. **Partial success**: Each item is processed independently. The response reports `successCount`, `failureCount`, and the first 50 `failures` (with the 1-based `index` and error). HTTP 200 is returned if at least one item succeeded; 400 if all failed.

## Example Request

```json theme={null}
[
  {
    "item_generic_name": "Amoxicillin",
    "item_strength": "500mg",
    "item_form": "Capsule",
    "route_of_administration": "Oral",
    "quantity": "20",
    "max_repeats": "2",
    "poison_class": "S4"
  },
  {
    "item_generic_name": "Ibuprofen",
    "item_strength": "200mg",
    "item_form": "Tablet",
    "route_of_administration": "Oral",
    "quantity": "30",
    "max_repeats": "1",
    "poison_class": "S2"
  }
]
```

## Example Response

```json theme={null}
{
  "success": true,
  "statusCode": 200,
  "message": "Created 2 of 2 custom drugs successfully",
  "code": "SUCCESS",
  "data": { "total": 2, "successCount": 2, "failureCount": 0, "failures": [] },
  "timestamp": "2024-01-25T09:15:00.000Z",
  "requestId": "req_1706171700000_abc123"
}
```


## OpenAPI

````yaml POST /v1/organizations/{organization_id}/custom-drugs
openapi: 3.0.1
info:
  title: Parchment APIs
  description: >-
    Parchments API documentation for partner integrations, enabling secure
    e-prescription services
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.sandbox.parchmenthealth.io/external
  - url: https://api.parchmenthealth.io/external
security:
  - bearerAuth: []
paths:
  /v1/organizations/{organization_id}/custom-drugs:
    post:
      description: >-
        Bulk-creates organization-level custom drugs. Accepts a JSON array;
        returns a per-item success/failure summary.
      parameters:
        - name: x-organization-secret
          in: header
          required: true
          description: Organization secret for authentication - provided by Parchment
          schema:
            type: string
        - name: organization_id
          in: path
          required: true
          description: Organization ID
          schema:
            type: string
            format: uuid
      requestBody:
        description: Non-empty array of custom drugs to create at organization level
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/CustomDrugInput'
      responses:
        '200':
          description: Bulk create processed (at least one succeeded)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CustomDrugBulkResponse'
        '400':
          description: Invalid body, or all items failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExternalApiErrorResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExternalApiErrorResponse'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExternalApiErrorResponse'
components:
  schemas:
    CustomDrugInput:
      type: object
      description: Custom drug fields supplied by a partner when creating a drug.
      required:
        - item_generic_name
        - item_strength
        - item_form
        - route_of_administration
        - quantity
        - poison_class
        - max_repeats
      properties:
        item_generic_name:
          type: string
          maxLength: 280
        item_trade_name:
          type: string
          maxLength: 280
        brand_name:
          type: string
          maxLength: 100
        item_strength:
          type: string
          maxLength: 100
        item_form:
          type: string
          maxLength: 50
        route_of_administration:
          type: string
          maxLength: 50
        quantity:
          type: string
          description: String or number; coerced to string
        max_repeats:
          type: string
          description: String or number; coerced to string
        poison_class:
          type: string
          maxLength: 2
        custom_product_id:
          type: string
          maxLength: 50
        description:
          type: string
          maxLength: 280
        patient_instructions:
          type: string
          maxLength: 250
        doctor_instructions:
          type: string
          maxLength: 50
    CustomDrugBulkResponse:
      type: object
      properties:
        success:
          type: boolean
        statusCode:
          type: integer
        message:
          type: string
        code:
          type: string
          example: SUCCESS
        data:
          type: object
          properties:
            total:
              type: integer
            successCount:
              type: integer
            failureCount:
              type: integer
            failures:
              type: array
              items:
                type: object
                properties:
                  index:
                    type: integer
                    description: 1-based position in the request array
                  error:
                    type: string
        timestamp:
          type: string
        requestId:
          type: string
    ExternalApiErrorResponse:
      type: object
      required:
        - success
        - statusCode
        - error
        - timestamp
        - requestId
      properties:
        success:
          type: boolean
          description: Indicates if the request was successful
          example: false
        statusCode:
          type: integer
          description: HTTP status code
          example: 400
        code:
          type: string
          description: Machine-readable operation code identifying the error
          example: RESOURCE_NOT_FOUND
        error:
          type: object
          description: RFC 7807 compliant error details
          required:
            - type
            - title
            - detail
          properties:
            type:
              type: string
              format: uri
              description: URI identifying the problem type
              example: https://parchment.health/errors/validation-error
            title:
              type: string
              description: Human-readable summary of the problem
              example: Validation failed
            detail:
              type: string
              description: Human-readable explanation of the problem
              example: There were some problems with your input.
            instance:
              type: string
              format: uri
              description: URI reference to the specific occurrence
              example: /patients/123
            validation:
              type: array
              description: Field-level validation errors (for 422 responses)
              items:
                type: object
                properties:
                  field:
                    type: string
                    description: Field name that failed validation
                  message:
                    type: string
                    description: Validation error message
                  code:
                    type: string
                    description: Error code for programmatic handling
        timestamp:
          type: string
          format: date-time
          description: ISO 8601 timestamp of the response
          example: '2024-01-15T10:30:00.000Z'
        requestId:
          type: string
          description: Unique identifier for request tracing
          example: req_1705312200000_def456
        meta:
          type: object
          description: Additional response metadata
          properties:
            apiVersion:
              type: string
              description: API version used
              example: '1.0'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````