How to use REST Web services to Get and Post a record

On my last blog here, we discussed another point about representation and classes.

While there are lot to be learned and discussed, as promised I wanted to take this time and talk about how you can test REST web services with a simple representation we created previously.

Before beginning the topic, if you search, our online help for “Web services integration” you will get to below page.




So as it’s mentioned on the online help you can use Web API which delivers REST web services to update and create records only for modules that are using Classes and representations.

On this example I am going to use Postman, to test REST web services (you can use other applications like SOAPUI as well) and below steps assumes you have installed Postman, for more information related to Postman visit https://www.getpostman.com

First lets use GET request to look at the details of a record.

  1. Launch POSTMAN.
  2. On a new Tab, choose the method you are going to use to interface, I am going to use GET method first to read a record.




  3. For the URL enter http://Servername:8124/api1/x3/erp/SEED/ZCLIENT('ALI')?representation=ZCLIENT.$details



  4. For the Authorization Type, use Basic Auth and enter User name and password.




  5. Click Send.



  6. You will get the JSON response of the server.





  7. This is similar to using the actual front end, and look at the details of an existing record in your representation

As you saw above , it was easy to send a GET request and use the details facet.

Now what if you want to Create a record using REST Web service.

Before I get to the details of how you can create a record using Web service, if you search online help for “Web services creation “ you will see below.



So in order to get a listing of all the properties on your representation you can use a Prototype request by sending http://Servername:8124/sdata/x3/erp/SEED/$prototypes('ZCLIENT.$details')

The result will list all the properties of your representation.




Now in order to Create a record follow below steps.

  1. As the online help mentioned , I am going to use POST.



  2. For the URL , I have entered http://servername:8124/api1/x3/erp/SEED/ZCLIENT?representation=ZCLIENT.$create
  3. On the header tab define Json as the content type.







  4. On the Authorization tab again , I have used Basic.




  5. On the Body tab, select raw and JSON for the input, and enter the properties of your representation.





  6. Click Send.
  7. You will get below response which shows a successful creation.

Conclusion:

You can use REST web services with your Representation to Create records.

What is next:

There are a lot to be discussed with the new style of coding, so stay tuned for more in future.  

 

Anonymous