public/helper/Send-TwitterMedia_SubtitlesCreate.ps1

function Send-TwitterMedia_SubtitlesCreate {
<#
.SYNOPSIS
    Upload media

.DESCRIPTION
    POST media/subtitles/create
    
    Overview
    
    Use this endpoint to associate uploaded subtitles to an uploaded video. You can associate subtitles to video before or after Tweeting.
    
    Request flow for associating subtitle to video before the video is Tweeted : 1. Upload video using the chunked upload endpoint and get the video media_id. 2. Upload subtitle using the chunked upload endpoint with media category set to “Subtitles” and get the subtitle media_id. 3. Call this endpoint to associate the subtitle to the video. 4. Create Tweet with the video media_id.
    
    Request flow for associating subtitle to video after the video is Tweeted : 1. Upload video using the chunked upload endpoint and get the video media_id. 2. Create Tweet with the video media_id. 3. Upload subtitle using the chunked upload endpoint with media category set to SUBTITLES and get the subtitle media_id. 4. Call this endpoint to associate the subtitle to the video.
    
    Request
    
    Requests should be HTTP POST with a JSON content body, and Content-Type application/json; charset=UTF-8
    
    Note: The domain for this endpoint is upload.twitter.com
    
    Response
    
    This endpoint returns the following HTTP responses:
    
    Status Text Description
    200 OK The request to create the subtitle was successful.
    400 Bad Request Generally, this response occurs due to the presence of invalid JSON in the request, or where the request failed to send any JSON payload. In this case this error could indicate an invalid subtitle file.
    403 Unauthorized HTTP authentication failed due to invalid credentials. Check your OAuth keys and tokens.
    404 Not Found The resource was not found at the URL to which the request was sent, likely because an incorrect media_id
    500 Internal Server Error There was an error on Twitter's side. Retry your request using an exponential backoff pattern.
    503 Service Unavailable There was an error on Twitter's side. Retry your request using an exponential backoff pattern.


.NOTES
    This helper function was generated by the information provided here:
    https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-subtitles-create

#>

    [CmdletBinding()]
    Param(
        
    )
    Begin {

        [hashtable]$Parameters = $PSBoundParameters
                   $CmdletBindingParameters | ForEach-Object { $Parameters.Remove($_) }

        [string]$Method      = 'POST'
        [string]$Resource    = '/media/subtitles/create'
        [string]$ResourceUrl = 'https://upload.twitter.com/1.1/media/subtitles/create.json'

    }
    Process {

        # Find & Replace any ResourceUrl parameters.
        $UrlParameters = [regex]::Matches($ResourceUrl, '(?<!\w):\w+')
        ForEach ($UrlParameter in $UrlParameters) {
            $UrlParameterValue = $Parameters["$($UrlParameter.Value.TrimStart(":"))"]
            $ResourceUrl = $ResourceUrl -Replace $UrlParameter.Value, $UrlParameterValue
        }

        $OAuthSettings = Get-TwitterOAuthSettings -Resource $Resource
        Invoke-TwitterAPI -Method $Method -ResourceUrl $ResourceUrl -Parameters $Parameters -OAuthSettings $OAuthSettings

    }
    End {

    }
}