Difference between revisions of "API: Sample Calls"

From Charitylog Manual
Jump to: navigation, search
Line 1: Line 1:
 
[[API Details|Go to API overview]]
 
[[API Details|Go to API overview]]
 +
 
There are a range of tools that can be used for making API calls. Postman is a popular choise, see https://www.postman.com/
 
There are a range of tools that can be used for making API calls. Postman is a popular choise, see https://www.postman.com/
 +
You will need your keys added to an evironment file. See [[API_Authentication|this page]] 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. You will need your keys added to an evironment file, like this:
 
 
[[File:Postman_environment.png]]
 
[[File:Postman_environment.png]]
 +
 +
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>

Revision as of 11:49, 24 February 2022

Go to API overview

There are a range of tools that can be used for making API calls. Postman is a popular choise, see https://www.postman.com/ You will need your keys added to an evironment file. See this page for more info.

File:Postman environment.png

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": {
		"name": "Sample calls",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"item": [
		{
			"name": "clients",
			"item": [
				{
					"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": {
						"method": "GET",
						"header": [
							{
								"key": "Org",
								"value": "{{org}}"
							},
							{
								"key": "Source",
								"value": "{{source}}"
							},
							{
								"key": "User",
								"value": "{{user}}"
							},
							{
								"key": "XDEBUG_SESSION",
								"value": "PHPSTORM"
							}
						],
						"url": {
							"raw": "https://{{host}}/v2/clients/id/123",
							"protocol": "https",
							"host": [
								"{{host}}"
							],
							"path": [
								"v2",
								"clients",
								"id",
								"123"
							]
						}
					},
					"response": []
				},
				{
					"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": {
						"method": "GET",
						"header": [
							{
								"key": "Org",
								"value": "{{org}}"
							},
							{
								"key": "Source",
								"value": "{{source}}"
							},
							{
								"key": "User",
								"value": "{{user}}"
							},
							{
								"key": "XDEBUG_SESSION",
								"value": "PHPSTORM"
							}
						],
						"url": {
							"raw": "https://{{host}}/v2/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",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.test(\"Status code is 200\", function () {",
									"    pm.response.to.have.status(200);",
									"});"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "Org",
								"value": "{{org}}"
							},
							{
								"key": "Source",
								"value": "{{source}}"
							},
							{
								"key": "User",
								"value": "{{user}}"
							},
							{
								"key": "XDEBUG_SESSION",
								"value": "PHPSTORM"
							}
						],
						"url": {
							"raw": "https://{{host}}/v2/referrals/id/1342",
							"protocol": "https",
							"host": [
								"{{host}}"
							],
							"path": [
								"v2",
								"referrals",
								"id",
								"1342"
							]
						}
					},
					"response": []
				}
			]
		}
	]
}