REST method PUT

0
I currently have a form that shows my profile data comming from another application (via REST call). Now I want to be able to edit this data and update my profile on the other application by using the PUT method. However, I can’t figure out how to to this exactly. What I did was the following: Location: endpoint HTTP Method: PUT Custom HTTP Headers for authorization In request-tab → select “form-data”  Create a key-value pair. → I checked the JSON naming E.g. key = “weight”, value={1}            → {1}: This is the value I edited in the form. In the response-tab → apply importing mapping with the correct values.   Result: After sending the data to strava the data doesn’t update.  I can’t find any good information on how to use the PUT-method in Mendix properly.  So how do I need configure the PUT-method?
asked
4 answers
3

If i look at the strava api documentation it appears you can only update the weight of an athlete by which requireds a Float, in the endpoint path instead of the request body.
Are you sending the whole object in the putrequest in the requestbody? Or did you copy paste it under the request instead of response by accident?

From the documentation: you can only update the athlete if you have the profile:write scope on your access token/refresh token. And i think this would be the issue atm, the mendix rest call seems to be fine.

https://developers.strava.com/docs/reference/#api-Athletes-updateLoggedInAthlete
https://developers.strava.com/docs/oauth-updates/

answered
3

Hey Jannes,

It’s hard to say why your call isn’t working because there's not any info to go on. But here's some stuff you can check.

Does the Rest call action give you an error, and if so what is the error? (check the LatestHttpResponse object which you can access if you set an error handler on the rest call action) .
You might call the wrong endpoint, or the authorization doesn't work. Maybe they need additional headers etc.

If you do get a statuscode 200 in return maybe you can find an answer by setting your ‘Rest Consume’ loglevel to Trace to more easily check the exact request that you sent to the endpoint.

answered
1

I got 2 log messages for my PUT request:

  1. Request content for PUT request to https://www.strava.com/api/v3/athlete HTTP/1.1
    Authorization: (omitted)

    {"id":000000,
     "username":null,
     "resource_state":2,
     "firstname":"test",
     "lastname":"test",
     "city":"someCity",
     "state":"test",
     "country":"test",
     "sex":"M",
     "premium":false,
     "summit":false,
     "created_at":"2019-10-25T09:00:36Z",
     "updated_at":"2020-03-05T12:52:20Z",
     "badge_type_id":0,
     "profile_medium":"avatar/athlete/medium.png",
     "profile":"avatar/athlete/large.png",
     "friend":null,
     "follower":null
    }

  2. Response content for PUT request to https://www.strava.com/api/v3/athlete
    HTTP/1.1 200 OK
    Date: Thu, 05 Mar 2020 14:05:32 GMT
    Content-Type: application/json; charset=utf-8
    Transfer-Encoding: chunked
    Connection: keep-alive
    Cache-Control: max-age=0, private, must-revalidate
    Via: 1.1 linkerd
    X-Download-Options: noopen
    Status: 200 OK
    X-RateLimit-Limit: 600,30000
    X-Request-Id: 3c35b741-13ad-4578-9d15-43e2b150f9cc
    Referrer-Policy: strict-origin-when-cross-origin
    ETag: W/"ba4115aa21e1465434a6ddf3e9aea42f"
    X-Frame-Options: SAMEORIGIN,DENY
    X-RateLimit-Usage: 5,53
    X-Content-Type-Options: nosniff
    X-Permitted-Cross-Domain-Policies: none
    Vary: Origin
    X-XSS-Protection: 1; mode=block

- Looking at the first log-message I guess that I don’t have write access? Which is weird cuz I did put it in the scope.

- Looking at the second message, I do get info back but it is the original (unchanged) data. 


 

answered
0

Here is more information about how to configure the REST action.
https://docs.mendix.com/refguide/call-rest-action

Make sure the value in the form-data is a variable/value defined in your microflow – example $value – or is a constant.

Can also try setting the log level of the “REST Consume” to Trace, to see what the response of the PUT call is.

answered