Updating a users settings via the Rest API in v10 doesn't seem to work

Hi, 

I'm trying to update the value of "ReceiveEmails" to false and am following the documentation here:

https://community.telligent.com/community/10/w/api-documentation/61739/update-user-rest-endpoint

However I get 404 - File or directory not found.

This is my code as a Powershell script:

$Url = 'https://mysite.com/api.ashx/v2/users/testuser.json';

$Payload = '{"Id": "3012", "ReceiveEmails": false}';

$Response = Invoke-WebRequest -Method POST -URI $Url -Body $Payload -ContentType "application/json";

I can create a user with similar code to the above fine but for some reason I can't get update to work.

I've read a number of forum posts here but not found a solution.

Thanks

Adam

Parents
  • We don't accept a JSON payload, it has to be application/x-www-form-urlencoded.  Secondly its a virtual PUT and needs to have Rest-Method: PUT as a header

  • Thanks Patrick, I did try that encoding instead of Json but it didn't work still. Probably as I was missing the Rest-Method: PUT header.

    I may have missed this in the docs somewhere but I think the example at the link above could use some more field update examples as I don't think it has any (just: data: { 'id': '6'}).

    Have you thought about including example Postman collections also perhaps?

    For anyone who needs to do this here is the export from Postman:

    POST /api.ashx/v2/users/testuser.json HTTP/1.1
    Host: mysite.com
    Rest-User-Token: ZXY5cXdtYmJvY3hxdXA3emZxbnhvOTgzZWQ5OmFzZWFicg==
    Rest-Method: PUT
    Content-Type: application/x-www-form-urlencoded
    Cache-Control: no-cache
    Postman-Token: e977340a-d323-4e0f-a0c7-83c6648bec7f
    
    ReceiveEmails=true

    And also Curl script:

    curl -X POST \
      https://mysite.com/api.ashx/v2/users/testuser.json \
      -H 'Cache-Control: no-cache' \
      -H 'Content-Type: application/x-www-form-urlencoded' \
      -H 'Postman-Token: 354f4a73-4e36-4333-bbfe-00b24c192b39' \
      -H 'Rest-Method: PUT' \
      -H 'Rest-User-Token: ZXY5cXdtYmJvY3hxdXA3emZxbnhvOTgzZWQ5OmFzZWFicg==' \
      -d ReceiveEmails=true

    And also PowerShell:

    $Url = 'https://mysite.com/api.ashx/v2/users/3120.json';
    
    $Payload = 'ReceiveEmails=true';
    
    $Response = Invoke-WebRequest -Method POST -URI $Url -Body $Payload -ContentType "application/x-www-form-urlencoded" -Headers @{"Rest-Method"="PUT"; "Rest-User-Token"="ZXY5cXdtYmJvY3hxdXA3emZxbnhvOTgzZWQ5OmFzZWFicg=="}
    
    $Response;
    
    

  •  Technically, you don't need Id as Id or username(as you are using) are part of the Url.  I don't necessarily disagree, but updates are hard since everything is really optional.  Given that documentation is auto generated, it does not really know what to include.

Reply Children
No Data