Forum Discussion

ADS_PSI's avatar
ADS_PSI
Mentor
8 years ago

Create a endpoint which is of POST type

Hi,

 

Normally when we create endpoint and expose it to third party it is of method GET. Can we create endpoint for POST type ?

10 Replies

  • ADS_PSI's avatar
    ADS_PSI
    Mentor
    8 years ago

    We can have post call to endpoints but we want to create endpoint which will be of POST type , exposed to third party. How can we make it ?

  • VikasB's avatar
    VikasB
    Boss
    8 years ago

    ADS_PSI  What I am getting here is that you are trying to use post-call on third-party inside the endpoint. Correct me if I am wrong. 
    You can use post call in endpoint also. Make sure you are sending the content type also to avoid the roadblocks. Content type "application/x-www-form-urlencoded" means that your POST body will need to be URL encoded just like a GET parameter string.

    Here is the syntax

    <#assign http_client_request = http.client.request("https", "base_path", "api_url").body("param1=${value}","application/x-www-form-urlencoded").post() />
    <#if http_client_request.hasError>
    ${http_client_request.error.message}
    <#else>
    ${http_client_request.content}
    </#if>
  • ADS_PSI's avatar
    ADS_PSI
    Mentor
    8 years ago

    VikasB No we are not making post call from studio endpoint to third party. We want to make such an endpoint which will be exposed to third party and it should be avialable to them as POST type call only. 
    kind of flow :

                                          POST call  to modify some data in lithium

    (endpoint on lithium) <------------------------------------------------------(third party xyz)

  • him_varma's avatar
    him_varma
    Advisor
    8 years ago
    Hi ADS_PSI,

    You want to expose the lithium endpoint to third party and make users subscribe from third party module?

    Is this the expected flow:
    subscribe button in third party -> call to lithium endpoint(having the subscribing code)
  • ADS_PSI I have heard someone has used PHP CURL function to make a http POST action to the lithium endpoint. It should work. If you are using chrome Postman extension for testing, it may not work. You may need to ask Lithium support to enable something. I believe there may be a whitelist IP table.
  • ADS_PSI's avatar
    ADS_PSI
    Mentor
    8 years ago

    him_varma yes similar kind of flow . But only condition that it should be allowed for POST method.

  • him_varma's avatar
    him_varma
    Advisor
    8 years ago
    You can create the endpoint in lithium and can call that endpoint from the third party server. It will allow both GET and POST method. It cannot be restricted to any specific type (POST or GET).

    You can also achieve this by hitting the V1 call for subscribing a user to thread.

    Api Call http://community.lithium.com/community-name/restapi/vc/boards/id/[id] /subscriptions/users/self/add
    Parameters: subscription.type (required)

    The call can be hit by Jquery(ajax function) or PHP(curl). It is not mandatory to achieve this through enpoint.
  • luk's avatar
    luk
    Boss
    8 years ago

    I think you might be able to restrict to POST only with the FreeMarker http.request context object (only available in page init script and endpoints), e.g. something like this as a wrapper of your endpoint code:

     

    <#if http.request.method == "POST">
    // execute your POST only code here
    <#else>
    // was another request method than POST, return error or whatever is suitable
    </#if>

    see here for more info: https://community.lithium.com/t5/Developer-Documentation/bd-p/dev-doc-portal?section=freemarker#l::{"p":"%2Frefer%2FcontextObjects","h":"%23httpRequest"}