Back to Collection Items
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoHttp
Boolean iSuccess
Variant vJson
Handle hoJson
Variant vResp
Handle hoResp
Variant vSbResponseBody
Handle hoSbResponseBody
Handle hoJResp
Integer iRespStatusCode
String sAssetId
String sGroupId
String sOrganizationId
String sVersion
String sTemp1
Boolean bTemp1
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// 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"
// }
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateString Of hoJson "main" "api.raml" To iSuccess
Get ComUpdateString Of hoJson "apiVersion" "1.0.0" To iSuccess
Get ComUpdateString Of hoJson "version" "1.0.0" To iSuccess
Get ComUpdateString Of hoJson "assetId" "publish-project-doc" To iSuccess
Get ComUpdateString Of hoJson "groupId" "gid1234" To iSuccess
Get ComUpdateString Of hoJson "classifier" "oas" To iSuccess
Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"
// Adds the "Authorization: Bearer {{token}}" header.
Set ComAuthToken Of hoHttp To "{{token}}"
Send ComSetRequestHeader To hoHttp "X-ANYPNT-ORG-ID" "{{organization_id}}"
Send ComSetRequestHeader To hoHttp "x-owner-id" "{{owner_id}}"
Get pvComObject of hoJson to vJson
Get ComPostJson3 Of hoHttp "https://domain.com/projects/{{project_id}}/branches/{{branch_name}}/publish/exchange" "application/json" vJson To vResp
If (IsComObject(vResp)) Begin
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
Set pvComObject Of hoResp To vResp
End
Get ComLastMethodSuccess Of hoHttp To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
If (Not(IsComObjectCreated(hoJResp))) Begin
Send CreateComObject of hoJResp
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
Set ComEmitCompact Of hoJResp To False
Showln "Response Body:"
Get ComEmit Of hoJResp To sTemp1
Showln sTemp1
Get ComStatusCode Of hoResp To iRespStatusCode
Showln "Response Status Code = " iRespStatusCode
If (iRespStatusCode >= 400) Begin
Showln "Response Header:"
Get ComHeader Of hoResp To sTemp1
Showln sTemp1
Showln "Failed."
Send Destroy of hoResp
Procedure_Return
End
Send Destroy of hoResp
// 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
Get ComStringOf Of hoJResp "assetId" To sAssetId
Get ComStringOf Of hoJResp "groupId" To sGroupId
Get ComStringOf Of hoJResp "organizationId" To sOrganizationId
Get ComStringOf Of hoJResp "version" To sVersion
End_Procedure
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": ""
}
]
}