|
| 1 | +--- |
| 2 | +title:"Analytics API" |
| 3 | +description:"" |
| 4 | +group:api |
| 5 | +toc:true |
| 6 | +--- |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +The Analytics API uses HTTP POST requests with JSON arguments and JSON responses. ???? |
| 11 | + |
| 12 | + |
| 13 | +##Authorization |
| 14 | +To make calls to the Analytics API, you need authorization through an API key passed in the header of the API request. |
| 15 | + |
| 16 | +>**NOTE** |
| 17 | +The user who generates the API token must be an account administrator. |
| 18 | +Currently, you do not need to select specific scopes for the API key. |
| 19 | + |
| 20 | +#####How to get the API key |
| 21 | +1. From your avatar dropdown in the Codefresh toolbar, select**User Settings**. |
| 22 | +1. Do one of the following: |
| 23 | +* If you have an existing API key you have saved, use that key. |
| 24 | +* To generate a new API key, click**Generate**. |
| 25 | +1. In**Key Name**, type a new name for the API key. |
| 26 | + This name is displayed in the UI with random numbers and letters. |
| 27 | +1. Click**Create**. |
| 28 | +1. Copy the API key to a handy location. |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +##Get list of pipelines |
| 34 | + |
| 35 | +Gets the list of |
| 36 | + |
| 37 | + |
| 38 | +###Headers |
| 39 | +The API authorization token must be included in the header of the API request. See[Authorization](#authorization). |
| 40 | + |
| 41 | +``` |
| 42 | +content-type: application/json |
| 43 | +Authorization: <TOKEN> |
| 44 | +``` |
| 45 | + |
| 46 | +###Request body |
| 47 | + |
| 48 | +For a description of the fields, see[Request parameters](#request-parameters). |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | +###Request example |
| 53 | + |
| 54 | +The request is formatted in curl. |
| 55 | + |
| 56 | +``` |
| 57 | +curl -X POST https://codefresh-hosted-gitops-runtime.com/api/promotions/commit \ |
| 58 | + --header "content-type: application/json" \ |
| 59 | + --header "Authorization: 214ffb**************" \ |
| 60 | + --data |
| 61 | +{ |
| 62 | + \"srcAppId\": { |
| 63 | + \"runtime\": \"codefresh\", |
| 64 | + \"namespace\": \"orders-qa\", |
| 65 | + \"name\": \"orders-qa-us-east\" |
| 66 | + }, |
| 67 | + \"destAppId\": { |
| 68 | + \"runtime\": \"codefresh\", |
| 69 | + \"namespace\": \"orders-prod\", |
| 70 | + \"name\": \"orders-prod-us-east\" |
| 71 | + }, |
| 72 | + \"message\": \"Update image tag and bump version\" |
| 73 | +}" |
| 74 | +``` |
| 75 | +###Response example |
| 76 | + |
| 77 | +####Success |
| 78 | +Here's an example of the response for a successful request. |
| 79 | +It includes the: |
| 80 | +* Commit SHA |
| 81 | +* Commit message |
| 82 | +* Name and email of the user who authored the commit |
| 83 | + |
| 84 | +``` |
| 85 | +{"COMMIT_SHA":"ff46cab5a4c94fc2db215b2bd2102da05c5314ba","COMMIT_MESSAGE":"bumped version","COMMIT_AUTHOR":"codefresh-user <codefresh.user@codefresh.io>"} |
| 86 | +``` |
| 87 | +####Failure |
| 88 | +Here's an example of the response for a failed request when there were no changes to promote between the source and the destination applications. |
| 89 | + |
| 90 | +``` |
| 91 | +{"statusCode":400,"message":"no changes found between source and destination applications","error":"Bad Request"} |
| 92 | +``` |
| 93 | + |
| 94 | + |
| 95 | +##POST`/promotions/pullRequest` |
| 96 | + |
| 97 | +Promotes the application from the source environment to the destination or target environment through a`pull request` as the promotion action. |
| 98 | + |
| 99 | +###`pullRequest` request body |
| 100 | + |
| 101 | +``` |
| 102 | +{ |
| 103 | + "srcAppId": { |
| 104 | + "runtime": "<runtime name>", |
| 105 | + "namespace": "<namespace>", |
| 106 | + "name": "<source-application-name>" |
| 107 | + }, |
| 108 | + "destAppId": { |
| 109 | + "runtime": "<runtime-name>", |
| 110 | + "namespace": "<namespace>", |
| 111 | + "name": "<destination-application-name>" |
| 112 | + }, |
| 113 | + "head": "<branch-of-destination-application>", |
| 114 | + "title": "<pr-title>", |
| 115 | + "description": "<pr-description", |
| 116 | + "commitMessage": "<commit-message-when-empty-uses-title>", |
| 117 | + "commitDescription": "<commit-description>", |
| 118 | + }" |
| 119 | +``` |
| 120 | + |
| 121 | +###`pullRequest` request example |
| 122 | +The request is formatted in curl. |
| 123 | + |
| 124 | +``` |
| 125 | +curl -X POST https://codefresh-hosted-gitops-runtime.com/api/promotions/pullRequest \ |
| 126 | + --header "content-type: application/json" \ |
| 127 | + --header "Authorization: 214ffb**************" \ |
| 128 | + --data "{ |
| 129 | + \"srcAppId\": { |
| 130 | + \"runtime\": \"codefresh\", |
| 131 | + \"namespace\": \"membership-staging\", |
| 132 | + \"name\": \"membership-staging\" |
| 133 | + }, |
| 134 | + \"destAppId\": { |
| 135 | + \"runtime\": \"codefresh\", |
| 136 | + \"namespace\": \"membership-prod\", |
| 137 | + \"name\": \"membership-prod\" |
| 138 | + }, |
| 139 | + \"head\": \"main\", |
| 140 | + \"title\": \"Merge new-accounts\", |
| 141 | + \"description\": \"Added new accounts and git sources\", |
| 142 | + \"commitMessage\": \"Merge new-accounts\", |
| 143 | + \"commitDescription\": \"Approved new accounts and git sources\", |
| 144 | + }" |
| 145 | +
|
| 146 | +``` |
| 147 | +###`pullRequest` response example |
| 148 | + |
| 149 | +####Success |
| 150 | +TBD |
| 151 | + |
| 152 | + |
| 153 | +####Failure |
| 154 | +TBD |
| 155 | + |
| 156 | + |
| 157 | + |
| 158 | +##Request query parameters |
| 159 | + |
| 160 | +{: .table .table-bordered .table-hover} |
| 161 | +| Parameter| Description| |
| 162 | +| ----------| --------| |
| 163 | +|`dateRange`| The time frame for which to send report data. This can be in the from-to format for a custom time frame, or a predefined fixed range.<br>For from-to date ranges, the format is`yyyy-mm-dd`. For example,`?dateRange=2024-04-30&dateRange=2023-08-01`. The from date must be earlier than the to date. <br>For fixed date ranges, use one of the following:<br>-`today`: Today's date.<br>-`Last 7 days`: <br>-`Last 30 days`:`dateRange=last%203%20month` (NIMA: need to find what are the fixed date ranges supported and how to add them?)| |
| 164 | +|`filter`|| |
| 165 | +|`granularity`|| |
| 166 | + |
| 167 | + |
| 168 | +<tableclass="table table-bordered table-hover"style="width:100%;"> |
| 169 | + <colgroup> |
| 170 | +<col style="width: 10%;"> |
| 171 | +<col style="width: 70%;"> |
| 172 | +<col style="width: 10%;"> |
| 173 | +<col style="width: 10%;"> |
| 174 | + </colgroup> |
| 175 | + <thead> |
| 176 | +<tr> |
| 177 | + <th style="width: 10%;">Parameter</th> |
| 178 | + <th style="width: 70%;">Description</th> |
| 179 | + <th style="width: 10%;">Data Type</th> |
| 180 | + <th style="width: 10%;">Required/Optional</th> |
| 181 | +</tr> |
| 182 | + </thead> |
| 183 | + <tbody> |
| 184 | +<tr> |
| 185 | + <td rowspan="4"><code class="highlighter-rouge">dateRange</code></td> |
| 186 | + <td colspan="3">The application in the source environment to promote through the <code class="highlighter-rouge">runtime</code>, <code class="highlighter-rouge">namespace</code>, and <code class="highlighter-rouge">name</code> key-value pairs.</td> |
| 187 | +</tr> |
| 188 | +<tr> |
| 189 | + <td><code class="highlighter-rouge">srcAppId.runtime</code>: The name of the GitOps Runtime associated with the source application.</td> |
| 190 | + <td>String</td> |
| 191 | + <td>Required</td> |
| 192 | +</tr> |
| 193 | +<tr> |
| 194 | + <td><code class="highlighter-rouge">srcAppId.namespace</code>: The namespace where the source application is deployed.</td> |
| 195 | + <td>String</td> |
| 196 | + <td>Required</td> |
| 197 | +</tr> |
| 198 | +<tr> |
| 199 | + <td><code class="highlighter-rouge">srcAppId.name</code>: The name of the source application to be promoted.</td> |
| 200 | + <td>String</td> |
| 201 | + <td>Required</td> |
| 202 | +</tr> |
| 203 | +<tr> |
| 204 | + <td rowspan="4"><code class="highlighter-rouge">destAppId</code></td> |
| 205 | + <td colspan="3">The application in the destination environment to be promoted through the <code class="highlighter-rouge">runtime</code>, <code class="highlighter-rouge">namespace</code>, and <code class="highlighter-rouge">name</code> key-value pairs.</td> |
| 206 | +</tr> |
| 207 | +<tr> |
| 208 | + <td><code class="highlighter-rouge">destAppId.runtime</code>: The name of the GitOps Runtime associated with the application in the destination environment.</td> |
| 209 | + <td>String</td> |
| 210 | + <td>Required</td> |
| 211 | +</tr> |
| 212 | +<tr> |
| 213 | + <td><code class="highlighter-rouge">destAppId.namespace</code>: The namespace in the destination environment where the application being promoted is deployed.</td> |
| 214 | + <td>String</td> |
| 215 | + <td>Required</td> |
| 216 | +</tr> |
| 217 | +<tr> |
| 218 | + <td><code class="highlighter-rouge">destAppId.name</code>: The name of the application in the destination environment to be promoted.</td> |
| 219 | + <td>String</td> |
| 220 | + <td>Required</td> |
| 221 | +</tr> |
| 222 | +<tr> |
| 223 | + <td><code class="highlighter-rouge">message</code></td> |
| 224 | + <td>Applies to <code class="highlighter-rouge">commit</code> promotion actions.<br>The commit message to associate for the commit promotion action.(limits)</td> |
| 225 | + <td>String</td> |
| 226 | + <td>Required</td> |
| 227 | +</tr> |
| 228 | +<tr> |
| 229 | + <td><code class="highlighter-rouge">head</code></td> |
| 230 | + <td>Applies to <code class="highlighter-rouge">pull request</code> promotion actions.<br>The branch of the application in the destination environment on which to open the PR.</td> |
| 231 | + <td>String</td> |
| 232 | + <td>Required</td> |
| 233 | +</tr> |
| 234 | +<tr> |
| 235 | + <td><code class="highlighter-rouge">title</code></td> |
| 236 | + <td>Applies to <code class="highlighter-rouge">pull request</code> promotion actions.<br>The title of the pull request.</td> |
| 237 | + <td>String</td> |
| 238 | + <td>Required</td> |
| 239 | +</tr> |
| 240 | +<tr> |
| 241 | + <td><code class="highlighter-rouge">description</code></td> |
| 242 | + <td>Applies to <code class="highlighter-rouge">pull request</code> promotion actions.<br>Additional information describing the pull request.</td> |
| 243 | + <td>String</td> |
| 244 | + <td>Optional</td> |
| 245 | +</tr> |
| 246 | +<tr> |
| 247 | + <td><code class="highlighter-rouge">commitMessage</code></td> |
| 248 | + <td>Applies to <code class="highlighter-rouge">pull request</code> promotion actions.<br>The commit message when the pull request is approved.<br>If omitted, uses <code class="highlighter-rouge">title</code> instead. </td> |
| 249 | + <td>String</td> |
| 250 | + <td>Optional</td> |
| 251 | +</tr> |
| 252 | +<tr> |
| 253 | + <td><code class="highlighter-rouge">commitDescription</code></td> |
| 254 | + <td>Applies to <code class="highlighter-rouge">pull request</code> promotion actions.<br>Additional information on the commit message when the pull request is approved. </td> |
| 255 | + <td>String</td> |
| 256 | + <td>Optional</td> |
| 257 | +</tr> |
| 258 | + </tbody> |
| 259 | +</table> |
| 260 | + |
| 261 | + |
| 262 | + |
| 263 | + |
| 264 | + |
| 265 | + |