arazzo: 1.0.1 info: title: Google Analytics Reuse or Create an Audience Export summary: List a property's audience exports and create a new one only when none can be reused. description: >- An idempotent audience export flow on the GA4 Data API. Audience exports are snapshots of the users in an audience, and the same audience can have many exports, so this workflow first lists the existing exports for a property and branches: when at least one export already exists it ends and reuses the first match, and when none exist it creates a fresh audience export and returns the long-running operation name. Each request is spelled out inline, including the OAuth bearer authorization. version: 1.0.0 sourceDescriptions: - name: analyticsDataApi url: ../openapi/google-analytics-data-api.yaml type: openapi workflows: - workflowId: audience-export-create-or-reuse summary: Reuse an existing audience export for a property, or create one if none exist. description: >- Lists the audience exports for a property and either reuses the first match or creates a new audience export for the supplied audience. inputs: type: object required: - accessToken - property - audience properties: accessToken: type: string description: OAuth 2.0 bearer access token with an analytics read scope. property: type: string description: 'GA4 property resource name (e.g. properties/1234).' audience: type: string description: 'Audience resource name to export (e.g. properties/1234/audiences/5678).' dimensionName: type: string description: API name of the audience dimension to include in a newly created export. default: deviceId steps: - stepId: listAudienceExports description: >- List the existing audience exports for the property so an export can be reused rather than creating an unnecessary new one. operationId: analyticsdata.properties.audienceExports.list parameters: - name: Authorization in: header value: Bearer $inputs.accessToken - name: parent in: path value: $inputs.property - name: pageSize in: query value: 200 successCriteria: - condition: $statusCode == 200 outputs: audienceExports: $response.body#/audienceExports reusedExportName: $response.body#/audienceExports/0/name onSuccess: - name: reuseExisting type: end criteria: - context: $response.body condition: $.audienceExports.length > 0 type: jsonpath - name: noneToReuse type: goto stepId: createAudienceExport criteria: - context: $response.body condition: $.audienceExports.length == 0 type: jsonpath - stepId: createAudienceExport description: >- Create a new audience export for the supplied audience, returning the long-running operation that forms the export. operationId: analyticsdata.properties.audienceExports.create parameters: - name: Authorization in: header value: Bearer $inputs.accessToken - name: parent in: path value: $inputs.property requestBody: contentType: application/json payload: audience: $inputs.audience dimensions: - dimensionName: $inputs.dimensionName successCriteria: - condition: $statusCode == 200 outputs: operationName: $response.body#/name done: $response.body#/done outputs: audienceExports: $steps.listAudienceExports.outputs.audienceExports reusedExportName: $steps.listAudienceExports.outputs.reusedExportName operationName: $steps.createAudienceExport.outputs.operationName