Webservice Method Rest - Forum - OpenEdge Development - Progress Community
 Forum

Webservice Method Rest

This question is not answered

Hello people.
I'm trying to make a Webservices consumption program with the REST method, but I'm having a runtime error.
Can someone help me with this code?
Follow my code.
Thank you.

block-level on error undo, throw.

using OpenEdge.Core.String.
using OpenEdge.Net.HTTP.ClientBuilder.
using OpenEdge.Net.HTTP.IHttpClient.
using OpenEdge.Net.HTTP.IHttpRequest.
using OpenEdge.Net.HTTP.RequestBuilder.
using OpenEdge.Net.HTTP.IHttpResponse.

/* *************************** Definitions ************************** */
define variable httpClient as IHttpClient no-undo.
define variable emptyReq as IHttpRequest no-undo.
define variable resp as IHttpResponse no-undo.

DEF VAR apiID AS CHAR NO-UNDO.
DEF VAR apiSecret AS CHAR NO-UNDO.
DEF VAR httpmethod AS CHAR NO-UNDO.
DEF VAR apikey AS CHAR NO-UNDO.
DEF VAR httpurl AS CHAR NO-UNDO.
DEF VAR dat_ref AS CHAR NO-UNDO.
DEF VAR stringtosign AS CHAR NO-UNDO.
DEF VAR secretKey AS MEMPTR NO-UNDO.
DEF VAR c_signature AS LONGCHAR NO-UNDO.

DEF VAR x-cod-date AS CHAR NO-UNDO.


ASSIGN apiid = "xmbfouiauy5d"
apisecret = "sxOzKUd3XX6Vc/dAiUvO0retebjOhXI/k6Qjb4JTLggnwIxfTekdvm/pRjC+iTpZB5wOcOsZWZWGVdg+k0uTaA==".

ASSIGN dat_ref = 'x-csod-date:' + STRING(YEAR(TODAY),"9999") + "-" + STRING(MONTH(TODAY),"99") + '-' + STRING(DAY(TODAY),"99") + "T" + STRING(TIME,"HH:MM:SS") + ".000"
x-cod-date = STRING(YEAR(TODAY),"9999") + "-" + STRING(MONTH(TODAY),"99") + '-' + STRING(DAY(TODAY),"99") + "T" + STRING(TIME,"HH:MM:SS") + ".000".

ASSIGN httpMethod = 'POST'
apiKey = 'x-csod-api-key:' + apiId
httpUrl = '/services/api/sts/session'.
stringToSign = httpMethod + "\n" + apiKey + "\n" + dat_ref + "\n" + httpUrl.

ASSIGN secretKey = base64-DECODE(apiSecret).

ASSIGN c_signature = base64-ENCODE(MESSAGE-DIGEST('SHA-512', stringToSign, secretKey)).

/* *************************** Main Block *************************** */
httpClient = ClientBuilder:Build():Client.

emptyReq = RequestBuilder:Post('ype-stg.csod.com/.../session, String:Empty())
:AddHeader("Content-Type", "text/xml")
:AddHeader("x-cod-api", apiid)
:AddHeader("x-cod-date", x-cod-date)
:AddHeader("x-cod-signature", string(c_signature))
:Request.

resp = httpClient:Execute(emptyReq).

catch e as Progress.Lang.Error : 

    message e:GetMessage(1) skip(2)
    e:CallStack
    view-as alert-box.
end catch.

Message Error:

Answer that I should get:

<cornerstoneApi
    xmlns:i="www.w3.org/.../XMLSchema-instance">
    <Validations/>
    <status>201</status>
    <timeStamp>2015-09-08T14:45:02+0000</timeStamp>
    <createdRecords>1</createdRecords>
    <data
        xmlns:a="www.CornerStoneOnDemand.com/Core/">
        <a:Session>
            <a:Token>1v28u30hyoxsn</a:Token>
            <a:Secret>N1mxiOOtzc4BBg7XIX2ROc0aN0d0J6vVy6U02CC+DWZl4GuUNEbMtRmVlP7Sb/+9u12RJM+58YphBIsoOldubA==</a:Secret>
            <a:Alias>soapadmin1</a:Alias>
            <a:ExpiresOn>2015-09-08T14:45:02+0000</a:ExpiresOn>
        </a:Session>
    </data>
</cornerstoneApi>
All Replies
  • Can you change String:Empty() to a ? (question mark)?

  • I put "?" how did you orient and the message below:

  • Are you getting 411 error? I think that refers to Content Length header being required.

  • You seem to be using  a version pre-11.7.0 (in 11.7 code was added to allow character data to be used for application/xml content types.

    You could try, instead of String:Empty() to pass "new OpenEdge.Core.WidgetHandle()"