Forum Discussion

k_auerbach's avatar
7 years ago

HTTP PUT for email_excluded

Hi,

 

I've been trying to change the "Do not Email" setting of an userprofile by setting email_excluded to true/false. 

I already asked Lithium Support for help, they told me to do an HTTP PUT to /api/2.0/users/ with a JSON payload that includes the "email_excluded" like:

{
"data": {
"type": "user",
"email_excluded": false
}
}

 

I've tried an http.client.request like:

<#assign http_client_request = http.client.request.body("https", "myurl", "/api/2.0/users/366").body("{'data':{'type': 'user','email_excluded':false}}", "application/json").put() />

 

But I got this error: 

An error has occurred when reading existing sub-variable "client"; see cause exception! The type of the containing value was: extended_hash+string (lithium.coreapi.webui.template.models.HttpTemplateModel wrapped into f.e.b.StringModel)

 

I would appreciate any help, Thanks!


Bildschirmfoto 2017-11-24 um 14.35.13.png
  • k_auerbach

    First thing I noticed, you need to remove body keyword from  "http.client.request.body". It should be like

    <#assign http_client_request = http.client.request("https", "myurl", "/api/2.0/users/366").body("{'data':{'type': 'user','email_excluded':false}}", "application/json").put() />

     

      • VikasB's avatar
        VikasB
        Boss

        k_auerbach 
        Make sure you are using it in either endpoint or page initialization script. It would not work in the component. 

        http.clientAccess and manipulate the HTTP client requestendpoints
        page initialization