Expose and API from Appian

Hi All,

  Can anyone help me on, is it possible we can expose an API from Appian Side, which can be accessed by SAP ,

and when the Api is called from SAP side, a Process model will trigger with details.

  Discussion posts and replies are publicly visible

  • Hi Vinneth,

    I ended up answering you in your other thread. 

    But yes, you can achieve what you are looking for using an Web API component. 

    Please check the link below:

    https://docs.appian.com/suite/help/21.2/Designing_Web_APIs.html

    Regards,

    Acacio B,

  • 0
    Certified Lead Developer

    In Appian, when you create a new web api object, this is one of the available templates. Takes about 5 clicks. Did you try this?

  • Hi Stefan/Acacio,

      I have implemented the Mapping to CDT with API Body, but getting the below error, can you please help me out with the same,

      Not a valid Web API Response. Received: [Lcom.appiancorp.core.expr.reaction.ReactionTree;@2617a999.

    Internal Server Error on REST API invocation.
    com.appiancorp.exceptions.LocalizedAppianRuntimeException$LocalizedAppianException: Contact your application administrator for help resolving this issue. Provide them with the following issue identifier: IV82KT3W (APNX-1-4533-000)

    a!localVariables(
      local!jsondata : a!fromJson(
        http!request.body
      ),
      local!cdtdata : a!forEach(items: local!jsondata, expression:{'type!{urn:com:appian:types}PF_Request'(
        requestId: fv!item[fv!index].requestId, 
        destinationCountryID: fv!item[fv!index].destinationCountryID,
        frieghtCurrencyID: fv!item[fv!index].frieghtCurrencyID,
        GBEID: fv!item[fv!index].GBEID,
        LID: fv!item[fv!index].LID,
        LOBID: fv!item[fv!index].LOBID,
        leadSupplyLocationID: fv!item[fv!index].leadSupplyLocationID,
        originCountryID: fv!item[fv!index].originCountryID,
        processID: fv!item[fv!index].processID,
        reasonCodeID: fv!item[fv!index].reasonCodeID,
        regionID: fv!item[fv!index].regionID, 
        rootCauseID: fv!item[fv!index].rootCauseID,
        routingMethodID: fv!item[fv!index].routingMethodID,
        shipmentDirectionID: fv!item[fv!index].shipmentDirectionID,
        shipmentWidth: fv!item[fv!index].shipmentWidth,
        shipperID: fv!item[fv!index].shipperID,
        approvalLevels: fv!item[fv!index].approvalLevels,
        approvalLevelsCompleted: fv!item[fv!index].approvalLevelsCompleted,
        correctiveActionReason: fv!item[fv!index].correctiveActionReason,
        destionationCustomerSupplier: fv!item[fv!index].destionationCustomerSupplier,
        destinationSiteID: fv!item[fv!index].destinationSiteID, 
        fGPartNumber: fv!item[fv!index].fGPartNumber,
        freightCost: fv!item[fv!index].freightCost,
        isFreightRecoverable: fv!item[fv!index].isFreightRecoverable,
        isWeightKnown: fv!item[fv!index].isWeightKnown,
        originCustomerSupplier: fv!item[fv!index].originCustomerSupplier,
        originSiteID: fv!item[fv!index].originSiteID,
        originStateId: fv!item[fv!index].originStateId,
        otherRoutingMethod: fv!item[fv!index].otherRoutingMethod,
        otherShipper: fv!item[fv!index].otherShipper,  
        partNumber: fv!item[fv!index].partNumber, 
        projectNumber: fv!item[fv!index].projectNumber,
        purchaseOrder: fv!item[fv!index].purchaseOrder,
        requestDt: fv!item[fv!index].requestDt,
        requestor: fv!item[fv!index].requestor,
        requiredShipDate: fv!item[fv!index].requiredShipDate,
        revenueAtRisk: fv!item[fv!index].revenueAtRisk,
        rootCauseReason: fv!item[fv!index].rootCauseReason,
        ShipmentHeight: fv!item[fv!index].ShipmentHeight,
        ShipmentLength: fv!item[fv!index].ShipmentLength,
        ShipmentUnits: fv!item[fv!index].ShipmentUnits, 
        ShipmentWeight: fv!item[fv!index].ShipmentWeight,
        ShipperEmail: fv!item[fv!index].ShipperEmail,
        Status: fv!item[fv!index].Status,
        TotalCost: fv!item[fv!index].TotalCost,
        USFreightCost: fv!item[fv!index].USFreightCost,
        WaybillNumber: fv!item[fv!index].WaybillNumber,
        OriginSite: fv!item[fv!index].OriginSite,
        DestinationSite: fv!item[fv!index].DestinationSite,
        /*CompletedOn: fv!item[fv!index].CompletedOn,*/
        ActualFreightCost: fv!item[fv!index].ActualFreightCost,
        FreightRiskPercent: fv!item[fv!index].FreightRiskPercent,
        
      )
      
      }
      ),
      
      {
        
        a!startProcess(
          processModel: cons!Test_Email_WebAPI,
          processParameters: {
            PF_Request : local!cdtdata
          },
          onSuccess: a!httpResponse(
            statusCode: 200,
            headers: {
              a!httpHeader(name: "Content-Type", value: "application/json")
            },
            body: a!toJson(
              fv!processInfo
            )
          ),
          onError: a!httpResponse(
            statusCode: 500,
            headers: {
              a!httpHeader(name: "Content-Type", value: "application/json")
            },
            body: a!toJson(
              {
                error: "There was an error starting the process"
              }
            )
          )
        )
      }
      
    )
    

  • 0
    Certified Lead Developer
    in reply to vineethk0001

    There is a few things here. First, about the error message. Check this

    https://docs.appian.com/suite/help/21.2/Appian_Administration_Console.html#simplified-error-messages

    Then, the foreach(). fv!item already is a single item from the list. There is no need for [fv!index|.

    Next, is the data structure in JSON any different than the CDT? Why recreate the data at all? Appian would happily map the data into your process.

  • Hi Helzle,


        There is no log with the ID V82KT3W (APNX-1-4533-000) in design_error.Csv

        also I changed the mapping as below, as you suggested, still facing the same error.

    processParameters: {
            PF_Request : a!fromJson(
              http!request.body
            )
          },

  • 0
    Certified Lead Developer
    in reply to vineethk0001

    Where do you get the error message? In Appian in the API designer?

  • Hi Vinneth,

    Have you try to pass the body data through the function a!fromJson in a separated rule just for testing? Perhaps your input is not valid.

    Other thing have you consider to use Query Parameters? It seems that you are expecting lots of parameters however if you could give a try with a bear minimum number of parameter, just to see if you manage to do some progress in your issue.

    Acacio B

  • yes Acacio, I have tried with minimum fields, which is for test process, it worked , now am using the below JSON data, and the Process Variable is CDT, and am trying to map this HSON data to The PV.

    {
      "requestId": 29,
      "destinationCountryID": 234,
      "frieghtCurrencyID": 3,
      "GBEID": 2,
      "LID": 4,
      "LOBID": 113,
      "leadSupplyLocationID": null ,
      "originCountryID": 234,
      "processID": 0,
      "reasonCodeID": 6,
      "regionID": 2,
      "rootCauseID": 45,
      "routingMethodID": 52,
      "shipmentDirectionID": 1,
      "shipmentWidth": 0,
      "shipperID": 22,
      "approvalLevels": 0,
      "approvalLevelsCompleted": 0,
      "correctiveActionReason": "corrective action",
      "destionationCustomerSupplier": null,
      "destinationSiteID": 338,
      "destinationStateID": 0,
      "fGPartNumber": null,
      "freightCost": 435534,
      "isFreightRecoverable": 0,
      "isWeightKnown": false,
      "originCustomerSupplier": null,
      "originSiteID": 304,
      "originStateId": 0,
      "otherRoutingMethod": null,
      "otherShipper": null,
      "partNumber": "ffdg",
      "projectNumber": null,
      "purchaseOrder": "sergerg",
      "requestDt": "27-JUN-21",
      "requestor": "H349401",
      "requestorComments": "gdfgdfgd",
      "requiredShipDate": "02-JUL-21",
      "revenueAtRisk": 0,
      "rootCauseReason": "ffdgdfg",
      "shipmentHeight": 0,
      "shipmentLength": 0,
      "shipmentUnits": "KGS/CM",
      "shipmentWeights": 43553,
      "shipperEmail": null,
      "status": null,
      "totalCost": 3423424,
      "usFreightCost": 4264,
      "wayBillNumber": null,
      "originSite": null,
      "destinationSite": null,
      "createdDt": "",
      "updateBy": null,
      "updateDt": "",
      "completedOn": "",
      "actualFreightCost": 0,
      "freightRiskPercent": 0
    }

  • 0
    Certified Lead Developer
    in reply to vineethk0001

    Did you try to start the process without passing any data? Does the constant point to the correct model? Is process model security OK? Is the PV PF_Request configured as parameter?