Difference between revisions of "API: Sample Calls"

From Charitylog Manual
Jump to: navigation, search
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[API Details|Go to API overview]]
 
[[API Details|Go to API overview]]
  
Copy and paste the the code below into a text editor, and save with a .json extension. The file can then be imported into Postman (see https://www.postman.com/) or similar tool.
+
There are a range of tools that can be used for making API calls. Postman is a popular choice, see https://www.postman.com/
 +
Create an environment so don't need to add the keys to the header of every call you make. If your tool lets you create the environment from JSON, copy and paste the code below and add your keys. Note that the host will be "https<nowiki/>://api-staging.dizions.co.uk/v2" if you are using early release features.
 +
<pre>
 +
{
 +
"host": "https://api.dizions.co.uk/v2",
 +
"source": YOUR_SOURCE_KEY,
 +
"org": YOUR_ORG_KEY,
 +
"user": YOUR_USER_KEY
 +
}
 +
</pre>
 +
Depending on the tool, you may have a 2 column table to enter keys and values instead. See [[API_Authentication|API Authentication]] for more info.
 +
 
 +
 
 +
 
 +
Copy and paste the the code below into a text editor, and save with a .json extension. The file can then be imported into Postman.
 +
 
 
<pre>
 
<pre>
 
{
 
{
 
"info": {
 
"info": {
 +
"_postman_id": "10bed371-4395-442e-9a66-6a780d834776",
 
"name": "Sample calls",
 
"name": "Sample calls",
 
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
 
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
 
},
 
},
 
"item": [
 
"item": [
 +
{
 +
"name": "Getting Started",
 +
"item": [
 +
{
 +
"name": "Get Business Configuration",
 +
"request": {
 +
"method": "GET",
 +
"header": [
 +
{
 +
"key": "Source",
 +
"value": "{{source}}",
 +
"type": "default"
 +
},
 +
{
 +
"key": "Org",
 +
"value": "{{org}}",
 +
"type": "default"
 +
},
 +
{
 +
"key": "User",
 +
"value": "{{user}}",
 +
"type": "default"
 +
}
 +
],
 +
"url": {
 +
"raw": "{{host}}/business/configuration",
 +
"protocol": "https",
 +
"host": [
 +
"{{host}}"
 +
],
 +
"path": [
 +
"v2",
 +
"business",
 +
"configuration"
 +
]
 +
}
 +
},
 +
"response": []
 +
}
 +
]
 +
},
 
{
 
{
 
"name": "clients",
 
"name": "clients",
Line 14: Line 71:
 
{
 
{
 
"name": "Client by ID with default fields",
 
"name": "Client by ID with default fields",
"event": [
 
{
 
"listen": "test",
 
"script": {
 
"exec": [
 
"pm.test(\"Status code is 200\", function () {",
 
"    pm.response.to.have.status(200);",
 
"});",
 
"pm.test(\"Client found\", function () {",
 
"    var jsonData = pm.response.json();",
 
"    pm.expect(jsonData.length).to.eql(1);",
 
"    pm.expect(jsonData[0].surname).to.eql('Elliott');",
 
"});"
 
],
 
"type": "text/javascript"
 
}
 
}
 
],
 
 
"request": {
 
"request": {
 
"method": "GET",
 
"method": "GET",
Line 53: Line 92:
 
],
 
],
 
"url": {
 
"url": {
"raw": "https://{{host}}/v2/clients/id/123",
+
"raw": "{{host}}/clients/id/123",
 
"protocol": "https",
 
"protocol": "https",
 
"host": [
 
"host": [
Line 70: Line 109:
 
{
 
{
 
"name": "Client by ID with specific fields",
 
"name": "Client by ID with specific fields",
"event": [
 
{
 
"listen": "test",
 
"script": {
 
"exec": [
 
"pm.test(\"Status code is 200\", function () {",
 
"    pm.response.to.have.status(200);",
 
"});",
 
"pm.test(\"Client found\", function () {",
 
"    var jsonData = pm.response.json();",
 
"    pm.expect(jsonData.length).to.eql(1);",
 
"    pm.expect(jsonData[0].surname).to.eql('Elliott');",
 
"});"
 
],
 
"type": "text/javascript"
 
}
 
}
 
],
 
 
"request": {
 
"request": {
 
"method": "GET",
 
"method": "GET",
Line 109: Line 130:
 
],
 
],
 
"url": {
 
"url": {
"raw": "https://{{host}}/v2/clients/id/123/field/name;id;living_arrangements;accommodation",
+
"raw": "{{host}}/clients/id/123/field/name;id;living_arrangements;accommodation",
 
"protocol": "https",
 
"protocol": "https",
 
"host": [
 
"host": [
Line 133: Line 154:
 
{
 
{
 
"name": "Referral by ID with default fields",
 
"name": "Referral by ID with default fields",
"event": [
 
{
 
"listen": "test",
 
"script": {
 
"exec": [
 
"pm.test(\"Status code is 200\", function () {",
 
"    pm.response.to.have.status(200);",
 
"});"
 
],
 
"type": "text/javascript"
 
}
 
}
 
],
 
 
"request": {
 
"request": {
 
"method": "GET",
 
"method": "GET",
 
"header": [
 
"header": [
 +
{
 +
"key": "Source",
 +
"value": "{{source}}"
 +
},
 
{
 
{
 
"key": "Org",
 
"key": "Org",
 
"value": "{{org}}"
 
"value": "{{org}}"
},
 
{
 
"key": "Source",
 
"value": "{{source}}"
 
 
},
 
},
 
{
 
{
Line 167: Line 175:
 
],
 
],
 
"url": {
 
"url": {
"raw": "https://{{host}}/v2/referrals/id/1342",
+
"raw": "{{host}}/referrals/id/1342",
 
"protocol": "https",
 
"protocol": "https",
 
"host": [
 
"host": [

Latest revision as of 11:01, 19 July 2024

Go to API overview

There are a range of tools that can be used for making API calls. Postman is a popular choice, see https://www.postman.com/ Create an environment so don't need to add the keys to the header of every call you make. If your tool lets you create the environment from JSON, copy and paste the code below and add your keys. Note that the host will be "https://api-staging.dizions.co.uk/v2" if you are using early release features.

{
	"host": "https://api.dizions.co.uk/v2",
	"source": YOUR_SOURCE_KEY,
	"org": YOUR_ORG_KEY,
	"user": YOUR_USER_KEY
}

Depending on the tool, you may have a 2 column table to enter keys and values instead. See API Authentication for more info.


Copy and paste the the code below into a text editor, and save with a .json extension. The file can then be imported into Postman.

{
	"info": {
		"_postman_id": "10bed371-4395-442e-9a66-6a780d834776",
		"name": "Sample calls",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"item": [
		{
			"name": "Getting Started",
			"item": [
				{
					"name": "Get Business Configuration",
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "Source",
								"value": "{{source}}",
								"type": "default"
							},
							{
								"key": "Org",
								"value": "{{org}}",
								"type": "default"
							},
							{
								"key": "User",
								"value": "{{user}}",
								"type": "default"
							}
						],
						"url": {
							"raw": "{{host}}/business/configuration",
							"protocol": "https",
							"host": [
								"{{host}}"
							],
							"path": [
								"v2",
								"business",
								"configuration"
							]
						}
					},
					"response": []
				}
			]
		},
		{
			"name": "clients",
			"item": [
				{
					"name": "Client by ID with default fields",
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "Org",
								"value": "{{org}}"
							},
							{
								"key": "Source",
								"value": "{{source}}"
							},
							{
								"key": "User",
								"value": "{{user}}"
							},
							{
								"key": "XDEBUG_SESSION",
								"value": "PHPSTORM"
							}
						],
						"url": {
							"raw": "{{host}}/clients/id/123",
							"protocol": "https",
							"host": [
								"{{host}}"
							],
							"path": [
								"v2",
								"clients",
								"id",
								"123"
							]
						}
					},
					"response": []
				},
				{
					"name": "Client by ID with specific fields",
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "Org",
								"value": "{{org}}"
							},
							{
								"key": "Source",
								"value": "{{source}}"
							},
							{
								"key": "User",
								"value": "{{user}}"
							},
							{
								"key": "XDEBUG_SESSION",
								"value": "PHPSTORM"
							}
						],
						"url": {
							"raw": "{{host}}/clients/id/123/field/name;id;living_arrangements;accommodation",
							"protocol": "https",
							"host": [
								"{{host}}"
							],
							"path": [
								"v2",
								"clients",
								"id",
								"123",
								"field",
								"name;id;living_arrangements;accommodation"
							]
						}
					},
					"response": []
				}
			]
		},
		{
			"name": "referrals",
			"item": [
				{
					"name": "Referral by ID with default fields",
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "Source",
								"value": "{{source}}"
							},
							{
								"key": "Org",
								"value": "{{org}}"
							},
							{
								"key": "User",
								"value": "{{user}}"
							},
							{
								"key": "XDEBUG_SESSION",
								"value": "PHPSTORM"
							}
						],
						"url": {
							"raw": "{{host}}/referrals/id/1342",
							"protocol": "https",
							"host": [
								"{{host}}"
							],
							"path": [
								"v2",
								"referrals",
								"id",
								"1342"
							]
						}
					},
					"response": []
				}
			]
		}
	]
}