Forum Discussion

jaikumar1's avatar
jaikumar1
Mentor
7 years ago

How to make REST API call

Hi,

 

I just looking into initiate the following REST API call using GET, PUT and DELETE method.

 

https://api.lithium.com/community/2.0/mytenantid/users/5?client-id=your-client-id

Could you please suggest the way to initiate the call. I have tried the rest() and restadmin() method. But it's not helpful, and also tried the ajax and that also not success. So guide me how to proceed on this?

 

    • jaikumar1's avatar
      jaikumar1
      Mentor

      Thank you TariqHussain,

       

      I have tried the endpoint with necessary tenantid and customer id with the following code,

      <#assign responses=http.client.request("https","api.lithium.com","community/2.0/mytenantid/users/5").json().get()/>
      <#if responses.hasError>
        There is some error
      <#else>
        There is no error..
      </#if>

      But unfortunately, i'm getting 

      FreeMarker template error:
      The following has evaluated to null or missing:
      ==> responses.status  [in template "test_endpoint.ftl" at line 3, column 24]
      
      ----
      Tip: It's the step after the last dot that caused this error, not those before it.
      ----
      Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?

      Could you please guide me how to resolve this error?

       

       

      • TariqHussain's avatar
        TariqHussain
        Boss

        jaikumar1 - Why do you want to use OAuth 2.0 process inside lithium, when you can get data using REST API v1 and REST API v2? 

         

        I believe you want to get the user data.  You can simply get it using REST API v2 e.g below. 

        SELECT * from users where id = '5'

        Using API v1. 

        /restapi/vc/users/id/5