Created
September 9, 2025 12:06
-
-
Save ankur0101/c7a37658bbc260442acdd121f3bdc534 to your computer and use it in GitHub Desktop.
sap-cpi-upload-iflow-payload.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function getPackageId(name) { | |
| return await $.ajax({ | |
| url: `/itspaces/odata/1.0/workspace.svc/ContentPackages('${name}')?$format=json&$select=reg_id`, | |
| method: 'GET', | |
| headers: { | |
| 'Content-type': 'application/json', | |
| 'x-csrf-token': Global.CSRF_TOKEN.value | |
| }, | |
| success: function(response, satusText) { | |
| //return response.filter(x => x.type === 'IFlow') | |
| } | |
| }) | |
| } | |
| async function getIflows(packageId) { | |
| const promise = await $.ajax({ | |
| url: `/itspaces/api/1.0/contentpackage/${packageId}/artifacts?$resourceinfo=true`, | |
| method: 'GET', | |
| headers: { | |
| 'Content-type': 'application/json', | |
| 'x-csrf-token': Global.CSRF_TOKEN.value | |
| }, | |
| success: function(response, satusText) { | |
| debugger | |
| //return response.filter(x => x.type === 'IFlow') | |
| } | |
| }) | |
| return promise.filter(x => x.type === 'IFlow') | |
| } | |
| async function uploadPayload(_packageId, _iflow, payload) { | |
| const promise = await $.ajax({ | |
| url: `/itspaces/api/1.0/workspace/${_packageId}/artifacts/${_iflow.id}/entities/${_iflow.id}/iflows/${_iflow.name}`, | |
| method: 'PUT', | |
| headers: { | |
| 'Content-type': 'application/json', | |
| 'x-csrf-token': Global.CSRF_TOKEN.value | |
| }, | |
| data: JSON.stringify(payload) | |
| }) | |
| return promise | |
| } | |
| async function start(){ | |
| debugger | |
| const _packageId = await this.getPackageId('<package-name>') | |
| this._iflows = await this.getIflows(_packageId.d.reg_id) | |
| const _iflow = this._iflows.find(x => x.name === '<iflow-name>') | |
| const bUploaded = await this.uploadPayload(_packageId.d.reg_id, _iflow, payload) | |
| alert(bUploaded ? `Uploaded` : `Could not upload`) | |
| } | |
| await start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment