PowerBuilder / Anypoint Platform APIs / Publish Project to Exchange
Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_AssetId
string ls_GroupId
string ls_OrganizationId
string ls_Version
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "main": "api.raml",
// "apiVersion": "1.0.0",
// "version": "1.0.0",
// "assetId": "publish-project-doc",
// "groupId": "gid1234",
// "classifier": "oas"
// }
loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateString("main","api.raml")
loo_Json.UpdateString("apiVersion","1.0.0")
loo_Json.UpdateString("version","1.0.0")
loo_Json.UpdateString("assetId","publish-project-doc")
loo_Json.UpdateString("groupId","gid1234")
loo_Json.UpdateString("classifier","oas")
loo_Http.SetRequestHeader("Content-Type","application/json")
// Adds the "Authorization: Bearer {{token}}" header.
loo_Http.AuthToken = "{{token}}"
loo_Http.SetRequestHeader("X-ANYPNT-ORG-ID","{{organization_id}}")
loo_Http.SetRequestHeader("x-owner-id","{{owner_id}}")
loo_Resp = loo_Http.PostJson3("https://domain.com/projects/{{project_id}}/branches/{{branch_name}}/publish/exchange","application/json",loo_Json)
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Json
return
end if
loo_SbResponseBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Resp.GetBodySb(loo_SbResponseBody)
loo_JResp = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")
loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0
Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()
li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
Write-Debug "Response Header:"
Write-Debug loo_Resp.Header
Write-Debug "Failed."
destroy loo_Resp
destroy loo_Http
destroy loo_Json
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
destroy loo_Resp
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "assetId": "test-publish-doc",
// "groupId": "6a2f41a3-c54c-fce8-32d2-0324e1c32e22",
// "organizationId": "6a2f41a3-c54c-fce8-32d2-0324e1c32e22",
// "version": "1.0.0"
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
ls_AssetId = loo_JResp.StringOf("assetId")
ls_GroupId = loo_JResp.StringOf("groupId")
ls_OrganizationId = loo_JResp.StringOf("organizationId")
ls_Version = loo_JResp.StringOf("version")
destroy loo_Http
destroy loo_Json
destroy loo_SbResponseBody
destroy loo_JResp
Curl Command
curl -X POST
-H "x-owner-id: {{owner_id}}"
-H "X-ANYPNT-ORG-ID: {{organization_id}}"
-H "Content-Type: application/json"
-H "Authorization: Bearer {{token}}"
-d '{
"main": "api.raml",
"apiVersion": "1.0.0",
"version": "1.0.0",
"assetId": "publish-project-doc",
"groupId": "gid1234",
"classifier": "oas"
}'
https://domain.com/projects/{{project_id}}/branches/{{branch_name}}/publish/exchange
Postman Collection Item JSON
{
"name": "Publish Project to Exchange",
"request": {
"method": "POST",
"header": [
{
"description": "(Required) User's ownerId, which identifies the user performing the operation. \nThis is NOT the username, but an UUID that can be found in the users page by the organization administrator.\n",
"key": "x-owner-id",
"value": "{{owner_id}}"
},
{
"description": "(Required) OrganizationId, which identifies the organization to which perform the operation. \nThis can be found in the organizations page by the organization administrator.\n",
"key": "X-ANYPNT-ORG-ID",
"value": "{{organization_id}}"
},
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{token}}",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"main\": \"api.raml\",\n \"apiVersion\": \"1.0.0\",\n \"version\": \"1.0.0\",\n \"assetId\": \"publish-project-doc\",\n \"groupId\": \"gid1234\",\n \"classifier\": \"oas\"\n}"
},
"url": {
"raw": "{{url}}/projects/{{project_id}}/branches/{{branch_name}}/publish/exchange",
"host": [
"{{url}}"
],
"path": [
"projects",
"{{project_id}}",
"branches",
"{{branch_name}}",
"publish",
"exchange"
]
},
"description": "Publish project to Exchange. As a result, an Exchange asset is created."
},
"response": [
{
"name": "Successful response",
"originalRequest": {
"method": "POST",
"header": [
{
"description": "(Required) User's ownerId, which identifies the user performing the operation. \nThis is NOT the username, but an UUID that can be found in the users page by the organization administrator.\n",
"key": "x-owner-id",
"value": "{{owner_id}}"
},
{
"description": "(Required) OrganizationId, which identifies the organization to which perform the operation. \nThis can be found in the organizations page by the organization administrator.\n",
"key": "X-ANYPNT-ORG-ID",
"value": "{{organization_id}}"
},
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{token}}",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"main\": \"api.raml\",\n \"apiVersion\": \"1.0.0\",\n \"version\": \"1.0.0\",\n \"assetId\": \"publish-project-doc\",\n \"groupId\": \"gid1234\",\n \"classifier\": \"oas\"\n}"
},
"url": {
"raw": "{{url}}/projects/{{project_id}}/branches/{{branch_name}}/publish/exchange",
"host": [
"{{url}}"
],
"path": [
"projects",
"{{project_id}}",
"branches",
"{{branch_name}}",
"publish",
"exchange"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"assetId\": \"test-publish-doc\",\n \"groupId\": \"6a2f41a3-c54c-fce8-32d2-0324e1c32e22\",\n \"organizationId\": \"6a2f41a3-c54c-fce8-32d2-0324e1c32e22\",\n \"version\": \"1.0.0\"\n}"
},
{
"name": "401 - Authorization failed",
"originalRequest": {
"method": "POST",
"header": [
{
"description": "(Required) User's ownerId, which identifies the user performing the operation. \nThis is NOT the username, but an UUID that can be found in the users page by the organization administrator.\n",
"key": "x-owner-id",
"value": "{{owner_id}}"
},
{
"description": "(Required) OrganizationId, which identifies the organization to which perform the operation. \nThis can be found in the organizations page by the organization administrator.\n",
"key": "X-ANYPNT-ORG-ID",
"value": "{{organization_id}}"
},
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer 00001",
"type": "text",
"description": "Generate error with a invalid token "
}
],
"body": {
"mode": "raw",
"raw": "{\n \"main\": \"api.raml\",\n \"apiVersion\": \"1.0.0\",\n \"version\": \"1.0.0\",\n \"assetId\": \"publish-project-doc\",\n \"groupId\": \"gid1234\",\n \"classifier\": \"oas\"\n}"
},
"url": {
"raw": "{{url}}/projects/{{project_id}}/branches/{{branch_name}}/publish/exchange",
"host": [
"{{url}}"
],
"path": [
"projects",
"{{project_id}}",
"branches",
"{{branch_name}}",
"publish",
"exchange"
]
}
},
"status": "Unauthorized",
"code": 401,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/plain"
}
],
"cookie": [
],
"body": ""
}
]
}