0

I cannot change the hourly_rate of Project or Client object via API (Using JavaScript/Google Script):

var responseObject = [];
  var payload = {
    "name": "Test project 125",
    "hourly_rates": {"45": 222}
  }
  var response = UrlFetchApp.fetch("https://app.activecollab.com/218040/api/v1/projects", {
                                   "method": "post",
                                   "headers": {
                                   'X-Angie-AuthApiToken': api_token
                                   },
                                   "payload" : payload,   
                                   "followRedirects" : true,
                                   "muteHttpExceptions": true
                                   });

  if (response.getResponseCode() == 200) {
    responseObject = JSON.parse(response.getContentText());
  }

  console.log(responseObject);

returns:

hourly_rates={45=100, 24=20, 3=100, 38=50, 17=15, 31=50, 10=100}

I get the same result if i use PUT method. Everything else is saved, but hourly rates not.

karelk
  • 1
  • 1

1 Answers1

0

have you tried the ActiveCollab SDK? I'm not sure which company or which job-type you target.

Once you download the package from git, run composer update

Here's an example:

<?php

/*
 * This library is free software, and it is part of the Active Collab SDK project. Check LICENSE for details.
 *
 * (c) A51 doo <info@activecollab.com>
 */

require_once __DIR__ . '/vendor/autoload.php';

$authenticator = new \ActiveCollab\SDK\Authenticator\Cloud('ACME Inc', 'My Awesome Application', 'YOUR-EMAIL', 'YOUR-PASSWORD');

// Show all Active Collab 5 and up account that this user has access to
print_r($authenticator->getAccounts());

// Show user details (first name, last name and avatar URL)
print_r($authenticator->getUser());

// Issue a token for account #123456789
$token = $authenticator->issueToken(176178);

if ($token instanceof \ActiveCollab\SDK\TokenInterface) {
    print $token->getUrl() . "\n";
    print $token->getToken() . "\n";
} else {
    print "Invalid response\n";
    die();
}

// Create a client instance
$client = new \ActiveCollab\SDK\Client($token);

// Make a request
print_r($client->get('/job-types/5')->getJson());
try {
    $client->put('/job-types/5', [
        'single' => [
            'default_hourly_rate' => 300
        ]
    ]);

} catch(AppException $e) {
    print $e->getMessage() . '<br><br>';
}

This is an example of how to change the hourly rate directly, you can do that from the /projects/ID-OF-THE-PROJECT

Please refer to the API documentation: https://developers.activecollab.com/api-documentation/v1/people/companies/custom-hourly-rates.html

Elvis S.
  • 362
  • 1
  • 3
  • 13
  • I am notu sure how the PHP SDK would solve my problem, since this is Javascript / Google Script app. – karelk Nov 06 '19 at 12:41
  • The problem is not with default_hourly_rate, but with custom hour rate on the project. I am using the [documentation](https://developers.activecollab.com/api-documentation/v1/people/companies/custom-hourly-rates.html) where it suggests `PUT /projects/1` with payload `{ "hourly_rates": { "1": 250 } } ` (ie I know I have job type with id 1, and I want to change the rate on this project to 250. And this does not work) – karelk Nov 06 '19 at 12:51
  • POST request does not work, only PUT. Sending you screenshots of successful PUT request: https://ibb.co/CQmR1vj https://ibb.co/BtWtL6H – Elvis S. Nov 06 '19 at 14:04
  • For some unspecified reason it only works for me if the payload looks like this: `{ "hourly_rates[45]": 1234, "hourly_rates[31]": 4321 }` thanks for helping me! – karelk Nov 06 '19 at 16:06