Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert
Hi All,

With part of SAP Cloud Platform Mobile Services for development and operations, REST APIs enable standard HTTP client apps running in any OS to leverage SAP Cloud Platform mobile service security and push features. This platform provides different functionality like


Management and monitoring the apps

Native push notification like APNS , BES, GCM, WNS, MPNS


There is a proper procedure to get start with. First we have to register a client application with proper user information. Once registration is successful, we have follow REST API method to retrieve and update the application.

Create an application



  1. First, sign up for SAP Cloud Platform Trial account, enable "Development and Operations" under Mobile Services (in Neo Trial)




2.  Click on it, then click on "Go to service"

3. In Mobile Service cockpit, navigate to Mobile Applications > Native/Hybrid > Click on "New"

4. provide below info and Save it
















Config Templates (optional) Native
ID com.sap.demo
Name Test App




5. As you can see in below screenshot that we need to add or assign one minimum feature in order to complete application configuration.

Next, we will add a destination/OData end point url to this app. Click on "+" plus icon besides "Assigned Features"



In Mobile service, there is a ready made sample OData service available, you can perform CRUDQ operations against it.

  • use this sample service during development and testing

  • you can generate sample sales orders and purchase orders for multiple entity sets

  • you can view sample data for each entity in a separate text file, reset the sample data

  • this service uses OData V2    






7. It's very important to check if ping connection from Mobile service to backend is successful and if you are able to backend data

Click on "Connectivity" under Assigned Features section and then click on "Ping" , if you see "Ping Successful" that means backend host is reachable from SAP CP Mobile Service.



Now, let's check if backend data can also be accessible, for that click on "OData Application Data Test" icon (before Ping) , Click next , then you would be able to see backend Entity details and corresponding data.



,8. Important thing to note here is, a security configuration of "SAML" provider is assigned (by default) to the newly created application, you can always modify it as per your requirement.



for this blog post, i changed security config to "Basic"



All good with application configuration, let move with on-boarding a user on SAP CP mobile service

On-Boarding a user



  1. Navigate to "APIs" tab, copy Registration URL


2. open REST Client add-on/plugin in your preferred browser,



    • make a POST call







    • Add Header keys:






















Key Value
Content-Type application/xml
Authorization Mobile service id and password





    • Add this xml text in the RAW body section:




<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<content type="application/xml">
<m:properties>
<d:DeviceType>iPhone</d:DeviceType>
</m:properties>
</content>
</entry>

 



    • Here i have added DeviceType as iPhone. That means registration will be for iPhone device.



    • Possible valid values for DeviceType are:


















































DeviceType Device
Android Android Devices
Blackberry Blackberry devices
iOS iOS devices
iPad Apple iPad
iPhone Apple iPhone
iPod Apple iPod
Windows includes desktop or servers with Windows OS such as Windows XP, Windows Vista, Windows 7, and Windows Server series OS


Windows8

Windows81
includes Windows desktop version


WinPhone8

WinPhone81
includes Windows mobile


Also: WinMobile, WinSmartPhone,Rim6

Check here for more details:  https://help.sap.com/viewer/e501bc6206bc4796b69baa3a634da3f3/3.0.13/en-US/7c0aaf8770061014a403e0decc...

Here you go,  click on "Send"

Request:



Response:

    Status as 201 created and in the Response headers you will see the newly created X-SMP-APPCID (ConnectionID)



To Verify the same registration in the Mobile Service cockpit,

navigate to "User Registrations" tab in the same application configuration,



 

CRUD operation for the given OData service via Mobile Service


 Since we have already created one application id for the given Odata service. Now we have to test if we are able to do GET, POST,PUT, DELETE operation for the same.

GET (Reading a record)


Method: GET


under "APIs" tab, copy "Destination" URL



 


Header Sections:






















Key Value
Authorization Mobile service userid and password
Content-Type application/xml
X-SMP-APPCID registrationID value e.g. 23e81...3a5c0




 

Response:

here, all list of collections are showing up.



 

To view a particular collection data, append its "Entityset" value in the URL

e.g. https://hcpms-xxxxtrial.hanatrial.ondemand.com/com.sap.edm.sampleservice/Customers

 




POST (Creating a record)


Lets create a new customer record in customer entity

Method: POST

 

Header Sections:






















Key Value
Authorization Mobile service userid and password
Content-Type application/xml
X-SMP-APPCID registrationID value e.g. 23e81...3a5c0


 

Request: 

  

 

Body Content:
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<content type="application/xml">
<m:properties>
<d:City>Walldorf</d:City>
<d:Country>DE</d:Country>
<d:DateOfBirth>1987-01-01T00:00:00</d:DateOfBirth>
<d:EmailAddress>saptestuser@sap.com</d:EmailAddress>
<d:FirstName>Test</d:FirstName>
<d:HouseNumber>4</d:HouseNumber>
<d:LastName>User</d:LastName>
<d:PhoneNumber>1012697341</d:PhoneNumber>
<d:PostalCode>57490</d:PostalCode>
<d:Street>PlattnerRingRoad</d:Street>
<d:UpdatedTimestamp>2018-01-05T17:33:53.15</d:UpdatedTimestamp>
</m:properties>
</content>
</entry>

Response:

you must get a "201 Created" status code.



 

You can verify data in backend by navigating to Mobile Service>Native/Hybrid> com.sap.demo>Connectivity>OData Application Data Test > select Customers entityset from dropdown



 

PUT (Updating a record)


Method: PUT

Lets update same record with city as "Mannheim"

Header Sections:






















Key Value
Authorization Mobile service userid and password
Content-Type application/xml
X-SMP-APPCID registrationID value e.g. 23e81...3a5c0


    


    

Body Content:
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<content type="application/xml">
<m:properties>
<d:City>Mannheim</d:City>
</m:properties>
</content>
</entry>

Response:

you must get a "204 No Content" status code.


DELETE (deleting a record)


Method: DELETE

 

Header Sections:






















Key Value
Authorization Mobile service userid and password
Content-Type application/xml
X-SMP-APPCID registrationID value e.g. 23e81...3a5c0




Body Content: NA

Response:

you must get a "204 No Content" status code.



For detailed information on REST API topic, check : REST API App Development

You van also follow below tags for blog posts and queries:

I hope this will blog will help you to understand basic concept of on-boarding of a user at SAP Cloud Platform Mobile Service for development and operations using REST client.

Your comments and feedback are most welcome.

Cheers,

Jitendra Kansal

Product Management, SAP Cloud Platform User Experience
SAP SE
83 Comments