1

I am developing an iOS app using IBM MobileFirst Platform 8.0 that have push notification capabilities

I have manage to send notification via postman, the process was

  1. Obtaining a token from mobile first platform server
  2. Send to notification via rest api along with the token

The tutorial link i have follow is,

Server Side - https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/notifications/sending-notifications/

Client Side - https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/notifications/handling-push-notifications/cordova/

Get Token - https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/authentication-and-security/confidential-clients/#obtaining-an-access-token

For now, i am trying to send a push notification when the app triggers an adapter call

I am currently stuck on getting the token part using WL.Server.invokeHttp, below is more adapter code and connectivity setting

function getToken() {
   var input = {
        method : 'post',
        returnedContentType : 'application/json',       
        path : '/mfp/api/az/v1/token',      
        headers : {
            Authorization:"Basic UHVzaE5asdasdas4444rrraWNhdGlvbjpQdXNoasdasd0aW9u",
            contentType:'application/x-www-form-urlencoded'
        },
        body:{
            grant_type : "client_credentials",
            scope : "push.application.my.app messages.write",

        }

    }; 

    var results =  MFP.Server.invokeHttp(input);
    return results;
}

<connectivity>
       <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
            <protocol>http</protocol>
            <domain>127.0.0.1</domain>
            <port>9080</port>
            <connectionTimeoutInMilliseconds>60000</connectionTimeoutInMilliseconds>
            <socketTimeoutInMilliseconds>60000</socketTimeoutInMilliseconds>
            <maxConcurrentConnectionsPerNode>50</maxConcurrentConnectionsPerNode>
        </connectionPolicy>
    </connectivity>

Do hope for advice, thanks in advance.

S.A.Norton Stanley
  • 1,833
  • 3
  • 23
  • 37
Chris
  • 612
  • 2
  • 9
  • 23

1 Answers1

0

I manage to solve it with these code

var requestStructure = {
        method : 'post',
        returnedContentType : 'json',
        path : '/mfp/api/az/v1/token',      
        headers: {
            "Content-Type" : "application/x-www-form-urlencoded",
            "Authorization" : "Basic UHVzaE5asdasdas4444rrraWNhdGlvbjpQdXNoasdasd0aW9u"
        },
        parameters:{
            "grant_type" : "client_credentials",
            "scope" : "push.application.my.app messages.write"
        }
     };

    var results = MFP.Server.invokeHttp(requestStructure);
    return results;
Chris
  • 612
  • 2
  • 9
  • 23