0

I'm writing a series of Apex webservices that I will be accessing from a third-party application, pulling data from Contacts & related records and creating new records. I've managed the 3rd party configuration to the point that I think I'm getting to my org, but it looks like the two processes are not talking to each other well. (Can you tell I mostly work inside my org, not interacting externally..?)

The request/input is defined as follows:

{
  "requestUrlTemplate": "/services/Soap/c/41.0/0DF2C000000009c/inventory_schema_retrieval/getInventorySchema",
  "requestType": "POST",
  "headers": {},
  "requestTemplate": "{\"contactId\": \"${input.ContactId}\"}"
}

and the webservice method is defined like this:

@HttpPost webservice static InventorySchema getInventorySchema(String contactId) {

Here's the error:

{
  "status": 500,
  "code": "internal.server.error",
  "message": "The server encountered an unexpected condition which prevented it from fulfilling the request.",
  "messageParams": {},
  "contextId": "d4ea9866-286f-43f0-acf5-7ee327b35bbe",
  "details": [],
  "errors": [
    {
      "status": 500,
      "code": "INTERNAL_SERVER_ERROR",
      "message": "REST call for action execute failed. Message:Request to backend service failed.\n<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Client</faultcode><faultstring>content-type of the request should be text/xml</faultstring></soapenv:Fault></soapenv:Body></soapenv:Envelope>\n [d4ea9866-286f-43f0-acf5-7ee327b35bbe] [d4ea9866-286f-43f0-acf5-7ee327b35bbe]",
      "messageParams": {},
      "details": [],
      "errors": []
    }
  ]
}

... (some time passes) ... By adding Content-Type to the request header, the error message has changed

{
  "requestUrlTemplate": "/services/Soap/c/41.0/0DF2C000000009c/inventory_schema_retrieval/getInventorySchema",
  "requestType": "POST",
  "headers": {"Content-Type": "text/xml"},
  "requestTemplate": "{\"contactId\": \"${input.ContactId}\"}"
}

resulting in

{
  "status": 500,
  "code": "internal.server.error",
  "message": "The server encountered an unexpected condition which prevented it from fulfilling the request.",
  "messageParams": {},
  "contextId": "bcd46666-63a5-4995-a8d7-bb197eb9171a",
  "details": [],
  "errors": [
    {
      "status": 500,
      "code": "INTERNAL_SERVER_ERROR",
      "message": "REST call for action execute failed. Message:Request to backend service failed.\n<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Client</faultcode><faultstring>SOAPAction HTTP header missing</faultstring></soapenv:Fault></soapenv:Body></soapenv:Envelope>\n [bcd46666-63a5-4995-a8d7-bb197eb9171a] [bcd46666-63a5-4995-a8d7-bb197eb9171a]",
      "messageParams": {},
      "details": [],
      "errors": []
    }
  ]
}

Bother -- I've added the SOAPAction header, as well as Content-Type, and am now seeing 'Content is not allowed in prolog.' The headers look like this:

"headers": {"Content-Type": "text/xml",
              "SOAPAction": "anything"}, 

[based on SOAPAction discussion missing-soap-action-header

Here is the New, Improved error:

{
  "status": 500,
  "code": "internal.server.error",
  "message": "The server encountered an unexpected condition which prevented it from fulfilling the request.",
  "messageParams": {},
  "contextId": "f8aff33b-c61f-4a44-beaf-3540ae2aca0c",
  "details": [],
  "errors": [
    {
      "status": 500,
      "code": "INTERNAL_SERVER_ERROR",
      "message": "REST call for action execute failed. Message:Request to backend service failed.\n<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Client</faultcode><faultstring>Content is not allowed in prolog.</faultstring></soapenv:Fault></soapenv:Body></soapenv:Envelope>\n [f8aff33b-c61f-4a44-beaf-3540ae2aca0c] [f8aff33b-c61f-4a44-beaf-3540ae2aca0c]",
      "messageParams": {},
      "details": [],
      "errors": []
    }
  ]
}
  • I would just got with restful service if 3rd party supports it. Much easier IMHO. I am assuming since you went soap route it was not possible? – Eric Oct 13 '17 at 21:54
0

The connection/session exists between Purecloud & Salesforce; what I'm working with is the configuration to hook/piggyback my webservices into that. At the moment, there is no option to consume a WSDL to help the process.

  • To close this chapter, I am now getting a valid response, and it's now down to tweaking the configuration to access / manipulate the details. The request config. looks like this: { "requestUrlTemplate": "/services/apexrest/inventory_schema_retrieval/getInventorySchema", "requestType": "POST", "headers": { "Content-Type": "application/json" }, "requestTemplate": "{\"contactId\": \"${input.ContactId}\"}" } – Duncan Stewart Oct 16 '17 at 14:51
0

Why do you reinvent the wheel, hand-craft the messages coming out of this 3rd party? Wouldn't it be easier to consume an Enterprise WSDL & automatically create stubs of the service in this app's language?

Also - do you have a valid session Id somewhere in here (perhaps just cut out of the code you've posted)?

And these context id's look unusual, you're sure it's error message coming from salesforce, not something generated by this app or some proxy for example?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.