Brandon Tweed
Brandon Tweed

Reputation: 348

How does the Podio API Endpoint to update a view work?

When I viewed the documentation for the "Update View" endpoint there was very little information available (see https://developers.podio.com/doc/views/update-view-20069949). The current documentation states that the endpoint accepts one parameter, view_id but it seems that an API consumer would also want to be able to supply additional details to modify the view's definition.

Is there any example code available to demonstrate how this endpoint should be used?

Upvotes: 4

Views: 166

Answers (2)

Darin Short
Darin Short

Reputation: 21

Here's a PHP version, authentication performed prior to request:

// UPDATE VIEW

$authorization = 'Authorization: Bearer '.$auth_token;

$json = json_encode(array(
    "sort_desc" => false,
    "filters" => array(
        999994986 => array(
            "to" => 10000,
            "from" => 0.01
        ),
        999999204 => array(
            "to" => $end,
             "from" => $first
        )
    )
));

    $curl = curl_init();

    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://api.podio.com/view/99999909",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "PUT",
      CURLOPT_POSTFIELDS =>$json,
      CURLOPT_HTTPHEADER => array(
        $authorization,
        "Content-Type: application/json"
      ),
    ));

    $response = curl_exec($curl);
    curl_close($curl);

Upvotes: 0

Brandon Tweed
Brandon Tweed

Reputation: 348

The Podio Ruby client provides code that uses this endpoint. If you take a look here you can see that the endpoint expects a JSON body to be supplied in the PUT that specifies the new view's definition. In the Ruby code it's referred to as "attributes" and this is consistent with the API documentation for the other View operations. Here is an example HTTP request:

PUT /view/31011898 HTTP/1.1
Host: api.podio.com
Authorization: OAuth2 your_oauth2_token_here
Content-Type: application/json
Cache-Control: no-cache

{
    "layout": "table",
    "name": "SPAM",
    "rights": [
      "delete",
      "view",
      "update"
    ],
    "fields": {},
    "sort_desc": false,
    "created_by": {
      "user_id": <creator user id>,
      "space_id": null,
      "image": {
        "hosted_by": "podio",
        "hosted_by_humanized_name": "Podio",
        "thumbnail_link":    "https://d2cmuesa4snpwn.cloudfront.net/public/",
        "link": "https://d2cmuesa4snpwn.cloudfront.net/public/",
        "file_id": <some file id>,
        "external_file_id": null,
        "link_target": "_blank"
      },
      "profile_id": <profile id>,
      "org_id": null,
      "link": "https://podio.com/users/<user id>",
      "avatar": <avatar id>,
      "type": "user",
      "last_seen_on": "2016-10-27 19:58:22",
      "name": "Podio TESTER"
    },
    "sort_by": "created_on",
    "items": 0,
    "created_on": "2016-10-27 19:58:26",
    "private": true,
    "filters": [],
    "filter_id": 31011898,
    "groupings": {},
    "type": "private",
    "view_id": 31011898,
    "grouping": {}
}

Upvotes: 5

Related Questions