Skip to content

Commit 26d80d4

Browse files
committed
Bulk User support
1 parent d6e976c commit 26d80d4

File tree

4 files changed

+118
-1
lines changed

4 files changed

+118
-1
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,3 +533,26 @@ foreach ($iterator as $contact) {
533533
print_r($contact);
534534
}
535535
```
536+
537+
#### Bulk API
538+
539+
The [Bulk APIs](https://doc.intercom.io/api/#bulk-apis) are themselves in Beta:
540+
541+
```php
542+
// Create or update a batch of users
543+
$result = $intercom->bulkUsers(
544+
[
545+
'items' => [
546+
[
547+
'data_type' => 'user',
548+
'method' => 'post', // can be 'delete'
549+
'data' => [
550+
'email' => '[email protected]',
551+
'name' => 'Pi'
552+
]
553+
],
554+
...
555+
]
556+
]);
557+
```
558+

src/Intercom/Service/config/intercom_public_user.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,60 @@
240240
"responseType": "model",
241241
"summary": "Deletes a user given id, email or user_id",
242242
"uri": "/users"
243+
},
244+
"bulkUsers": {
245+
"httpMethod": "POST",
246+
"parameters": {
247+
"items": {
248+
"location": "json",
249+
"required": true,
250+
"type": "array"
251+
}
252+
},
253+
"responseClass": "JobModel",
254+
"responseType": "model",
255+
"summary": "Updates users in bulk, asynchronously",
256+
"uri": "/bulk/users"
243257
}
244258
},
245259
"models": {
260+
"JobModel": {
261+
"type": "object",
262+
"properties": {
263+
"id": {
264+
"location": "json",
265+
"type": "string"
266+
},
267+
"app_id": {
268+
"location": "json",
269+
"type": "string"
270+
},
271+
"name": {
272+
"location": "json",
273+
"type": "string"
274+
},
275+
"state": {
276+
"location": "json",
277+
"type": "string"
278+
},
279+
"updated_at": {
280+
"location": "json",
281+
"type": "integer"
282+
},
283+
"created_at": {
284+
"location": "json",
285+
"type": "integer"
286+
},
287+
"completed_at": {
288+
"location": "json",
289+
"type": "integer"
290+
},
291+
"links": {
292+
"location": "json",
293+
"type": "object"
294+
}
295+
}
296+
},
246297
"UserModel": {
247298
"type": "object",
248299
"properties": {

tests/Intercom/Resources/UserTest.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,30 @@
44

55
class UserTest extends IntercomTestCase
66
{
7+
public function testBulk()
8+
{
9+
$this->setMockResponse($this->client, 'User/UserJob.txt');
10+
$response = $this->client->bulkUsers(
11+
[
12+
'items' => [
13+
[
14+
'data_type' => 'user',
15+
'method' => 'post', // can be 'delete'
16+
'data' => [
17+
'email' => '[email protected]',
18+
'name' => 'Pi'
19+
]
20+
]
21+
]
22+
]);
23+
24+
$this->assertRequest('POST', '/bulk/users');
25+
$this->assertRequestJson(['items' => [['data_type' => 'user', 'method' => 'post', 'data' =>['email' => '[email protected]', 'name' => 'Pi']]]]);
26+
27+
$this->assertInstanceOf('\Guzzle\Service\Resource\Model', $response);
28+
$this->assertEquals('job_5ca1ab1eca11ab1e', $response['id']);
29+
}
30+
731
public function testGetUserByID()
832
{
933
$this->setMockResponse($this->client, 'User/User.txt');
@@ -122,7 +146,7 @@ public function testUpdateUserNoID()
122146
{
123147
$this->setMockResponse($this->client, 'User/User.txt');
124148
$response = $this->client->updateUser(['user_id' => '1234', 'hi' => 'hello', 'new_session' => true]);
125-
149+
126150
$this->assertRequest('POST', '/users');
127151
$this->assertRequestJson(['user_id' => '1234', 'new_session' => true]);
128152
}

tests/Mock/User/UserJob.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
HTTP/1.1 200 OK
2+
Cache-Control: max-age=0, private, must-revalidate
3+
Content-Type: application/json; charset=utf-8
4+
Date: Mon, 25 Aug 2014 23:57:54 GMT
5+
Server: nginx
6+
7+
{
8+
"id": "job_5ca1ab1eca11ab1e",
9+
"app_id": "pi3243fa",
10+
"name": "api bulk job",
11+
"state": "running",
12+
"updated_at": 1438944983,
13+
"created_at": 1438944983,
14+
"completed_at": null,
15+
"links": {
16+
"error": "https://api.intercom.io/jobs/job_5ca1ab1eca11ab1e/error",
17+
"self": "https://api.intercom.io/jobs/job_5ca1ab1eca11ab1e"
18+
}
19+
}

0 commit comments

Comments
 (0)