Request:
GET intempus.dk/web/v1/work_category/
Headers:
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
Content-Type: application/json
Body: empty
Response:
Statuscode 401
Body: Empty
To help us understand what you need, please also include a short
description your application.
For the quickest response, write your request in
english.
API_KEY
Your key is in the App Data Sharing section in the Intempus admin.USERNAME
Your username for that API key. The username is the one you use to log in to the Intempus Admin interface.ENDPOINT
The endpoint which you want to access. A list of all available endpoints can be found here.#!/usr/bin/env python import json import requests API_URL = 'https://intempus.dk/web/v1' API_KEY = '<your_api_key>' USERNAME = '<your_username>' ENDPOINT = '<your-endpoint>' headers = { 'content-type': 'application/json', 'Authorization': 'ApiKey {user}:{apikey}'.format( user=USERNAME, apikey=API_KEY), } def get_intempus_api(): url = '{api_url}/{endpoint}/'.format(api_url=API_URL, endpoint=ENDPOINT) response = requests.Session().get(url, headers=headers) data = json.loads(response.content) return "Request Status: %s\nData: %s" % (response.status_code, response.content) if __name__ == '__main__': response = get_intempus_api() print response
Once you replace it with the appropriate value save and run this command!
$ python get_endpoint_data.py
You should see similar value below.
Request Status: 200 Data: {"city": "Nuuk", "company": "/web/v1/company/1/", "contact": "John Doe", "country": "Denmark ", "customer_group": null, "email": "sample@gmail.com", "id": 20, "name": "Mary Doe", "notes": "Just another guy", "number": "", "phone": "639xxxxxxxxx", "resource_uri": "/web/v1/customer/20/", "street_address": "Aqqusinersuaq street, Nuuk, Greenland", "zip_code": "1607"}
using System; using System.Net; using System.IO; class read_API_object { public static string API_URL = "https://intempus.dk/web/v1"; public static string API_KEY = "<your_api_key>"; public static string USERNAME = "<your_username>"; public static string ENDPOINT = "customer"; static void Main(string[] args) { string response = CreateAPIObject(); Console.WriteLine (response); } public static string CreateAPIObject() { string url = string.Format("{0}/{1}/", API_URL, ENDPOINT); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.ContentType = "application/json"; //set the content type to JSON. request.Method = "GET"; // add the Authorization header to authenticate on our endpoint. string authorizationheader = string.Format("Authorization: ApiKey {0}:{1}", USERNAME, API_KEY); request.Headers.Add(authorizationheader); // Get the response. var httpResponse = (HttpWebResponse)request.GetResponse(); var statusCode = httpResponse.StatusCode; StreamReader response = new StreamReader(httpResponse.GetResponseStream()); return string.Format("Response Code: {0} - {1}\nData: {2}", (int)statusCode, statusCode.ToString(), response.ReadToEnd()); } }
Once you replace it with the appropriate value. In your monodevelop
editor press F5
A terminal/console will pop up showing the result of your script. Similar values below.
Response Code: 200 - OK Data: {"city": "Copenhagen", "company": "/web/v1/company/1/", "contact": "John Doe", "country": "Denmark", "customer_group": null, "email": "sample@gmail.com", "id": 16, "name": "Mary Doe", "notes": "Just another guy", "number": "", "phone": "639xxxxxxxxx", "resource_uri": "/web/v1/customer/16/", "street_address": "Staunings Pl. 3, 1607 Copenhagen V, Denmark", "zip_code": "1607"} Press any key to continue...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; class GetAPIObject { public static String APIURL = "https://intempus.dk/web/v1"; public static String APIKEY = "<your_api_key>"; public static String USERNAME = "<your_username>"; public static String ENDPOINT = "customer"; public static void main(String[] args) { try { URL url = new URL(String.format("%s/%s", APIURL, ENDPOINT)); String authorizationHeader = String.format("ApiKey %s:%s", USERNAME, APIKEY); // make a request with the required authorization API key hearders. HttpURLConnection request = (HttpURLConnection) url.openConnection(); request.setRequestMethod("GET"); request.setRequestProperty("Accept", "application/json"); request.setRequestProperty("Authorization", authorizationHeader); BufferedReader br = new BufferedReader(new InputStreamReader( (request.getInputStream()))); // read the response String output; System.out.println(String.format("Status Code: (%s)", request.getResponseCode())); output = br.readLine(); System.out.println(output); request.disconnect(); } catch (IOException e) { e.printStackTrace(); } } }
Once you replace it with the appropriate value. In your netbeans
editor press F6
A terminal/console will pop up showing the result of your script. Similar values below.
Status Code: (200) {"city": "", "company": "/web/v1/company/1/", "contact": "Peter Doe", "country": "", "customer_group": null, "email": "", "id": 16, "name": "Edward Doe", "notes": "", "number": "", "phone": "", "resource_uri": "/web/v1/customer/16/", "street_address": "", "zip_code": ""} BUILD SUCCESSFUL (total time: 0 seconds)
#!/usr/bin/env ruby require 'json' require "net/http" API_URL = 'https://intempus.dk/web/v1' API_KEY = '<your_api_key>' USERNAME = '<your_username>' ENDPOINT = 'company' def get_intempus_api(endpoint, username) url = "%{api_url}/%{endpoint}/?format=json&username=%{username}&api_key=%{api_key}" % { :api_url => API_URL, :endpoint => endpoint, :username => username, :api_key => API_KEY } response = Net::HTTP.get_response(URI.parse(url)) data = JSON.parse(response.body) return data end if __FILE__ == $0 response = get_intempus_api(endpoint=ENDPOINT, username = USERNAME) puts response end
Once you replace it with the appropriate value, then save it and run this command!
$ ruby ~/path/to/ruby_read_object.rb
You should see similar value below.
Response Code: 200 - true Data: {"city"=>"Copenhagen", "company"=>"/web/v1/company/1/", "contact"=>"John Doe", "country"=>"Denmark ", "customer_group"=>nil, "email"=>"sample@gmail.com", "id"=>20, "name"=>"Mary Doe", "notes"=>"Just another guy", "number"=>"", "phone"=>"639xxxxxxxxx", "resource_uri"=>"/web/v1/customer/20/", "street_address"=>"Staunings Pl. 3, 1607 Copenhagen V, Denmark", "zip_code"=>"1607"}
Sending POST
request to our API takes few easy steps. Let's say we want to add this sample data.
Name: John Doe City: Copenhagen Company: /web/v1/company/1/ # your company uri Contact: Mary Doe Country: Denmark Email: sample@gmail.com Notes: Just another guy Phone: Number: 639xxxxxxxxx Street Address: Staunings Pl. 3, 1607 Copenhagen V, Denmark Zip Code: 1607
Let's create a simple python request that sends a POST
request on our Customer
API endpoint. We add the sample data on our data dict and update the API_URL
, API_KEY
and USERNAME
.
For example:
#!/usr/bin/env python import json import requests API_URL = 'https://intempus.dk/web/v1' API_KEY = '<your_api_key>' USERNAME = '<your_username>' ENDPOINT = 'customer' headers = { 'content-type': 'application/json', 'Authorization': 'ApiKey {user}:{apikey}' .format(user=USERNAME, apikey=API_KEY), } data = { "city": "Copenhagen", "company": "/web/v1/company/1/", "contact": "John Doe", "country": "Denmark ", "email": "sample@gmail.com", "name": "Mary Doe", "notes": "Just another guy", "phone": "639xxxxxxxxx", "street_address": "Staunings Pl. 3, 1607 Copenhagen V, Denmark", "zip_code": "1607", } def get_intempus_api(): url = '{api_url}/{endpoint}/'.format(api_url=API_URL, endpoint=ENDPOINT) response = requests.post(url, data=json.dumps(data), headers=headers) return "Request Status: %s\nData: %s" % (response.status_code, response.content) if __name__ == '__main__': response = get_intempus_api() print response
Once you're done, save and name it create_customer.py
. On your terminal/console, run this command:
python ~/path/to/create_customer.py
You should see output like this:
Request Status: 201 Data: {"city": "Copenhagen", "company": "/web/v1/company/1/", "contact": "John Doe", "country": "Denmark ", "customer_group": null, "email": "sample@gmail.com", "id": 45, "name": "Mary Doe", "notes": "Just another guy", "number": "", "phone": "639xxxxxxxxx", "resource_uri": "/web/v1/customer/45/", "street_address": "Staunings Pl. 3, 1607 Copenhagen V, Denmark", "zip_code": "1607"}
If request_status
is 201, it means that you're able to create on our Customer
API endpoint.
Sending POST
request to our API takes few easy steps. Let's say we want to add this sample data.
Name: John Doe City: Copenhagen Company: /web/v1/company/1/ # your company uri Contact: Mary Doe Country: Denmark Email: sample@gmail.com Notes: Just another guy Phone: Number: 639xxxxxxxxx Street Address: Staunings Pl. 3, 1607 Copenhagen V, Denmark Zip Code: 1607
Let's create a simple C# request that sends a POST
request on our Customer
API endpoint. We add the sample data on our data dict and update the API_URL
, API_KEY
and USERNAME
.
For example:
using System; using System.Net; using System.IO; using System.Web.Script.Serialization; class create_API_object { public static string API_URL = "https://intempus.dk/web/v1"; public static string API_KEY = "<your_api_key>"; public static string USERNAME = "<your_username>"; public static string ENDPOINT = "customer"; public static string DATA = new JavaScriptSerializer().Serialize(new { city = "Copenhagen", company = "/web/v1/company/1/", contact = "John Doe", country = "Denmark ", email = "sample@gmail.com", name = "Mary Doe", notes = "Just another guy", phone = "639xxxxxxxxx", street_address = "Staunings Pl. 3, 1607 Copenhagen V, Denmark", zip_code = "1607" }); static void Main(string[] args) { string response = CreateAPIObject(); Console.WriteLine (response); } public static string CreateAPIObject() { string url = string.Format("{0}/{1}/", API_URL, ENDPOINT); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.ContentType = "application/json"; //set the content type to JSON. request.Method = "POST"; // add the Authorization header to authenticate on our endpoint. string authorizationheader = string.Format("Authorization: ApiKey {0}:{1}", USERNAME, API_KEY); request.Headers.Add(authorizationheader); //initiate the request. using (var streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write(DATA); streamWriter.Flush(); streamWriter.Close(); } // Get the response. var httpResponse = (HttpWebResponse)request.GetResponse(); var statusCode = httpResponse.StatusCode; StreamReader response = new StreamReader(httpResponse.GetResponseStream()); return string.Format("Response Code: {0} - {1}\nData: {2}", (int)statusCode, statusCode.ToString(), response.ReadToEnd()); } }
Once you replace it with the appropriate value. In your monodevelop
editor press F5
A terminal/console will pop up showing the result of your script. Similar values below.
Response Code: 201 - Created Data: {"city": "Copenhagen", "company": "/web/v1/company/1/", "contact": "John Doe", "country": "Denmark ", "customer_group": null, "email": "sample@gmail.com", "id": 41, "name": "Mary Doe", "notes": "Just another guy", "number": "", "phone": "639xxxxxxxxx", "resource_uri": "/web/v1/customer/41/", "street_address": "Staunings Pl. 3, 1607 Copenhagen V, Denmark", "zip_code": "1607"} Press any key to continue...
Sending POST
request to our API takes few easy steps. Let's say we want to add this sample data.
Name: John Doe City: Copenhagen Company: /web/v1/company/1/ # your company uri Contact: Mary Doe Country: Denmark Email: sample@gmail.com Notes: Just another guy Phone: Number: 639xxxxxxxxx Street Address: Staunings Pl. 3, 1607 Copenhagen V, Denmark Zip Code: 1607
Let's create a simple Java
request that sends a POST
request on our Customer
API endpoint.
We add the sample data on our data dict and update the APIURL
, APIKEY
USERNAME
and ENDPOINT
.
For example:
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.io.OutputStream; import org.json.JSONObject; class CreateAPIObject { public static String APIURL = "https://intempus.dk/web/v1"; public static String APIKEY = "<your_api_key>"; public static String USERNAME = "<your_username>"; public static String ENDPOINT = "customer"; public static void main(String[] args) { try { JSONObject data = new JSONObject(); data.put("city", "Copenhagen"); data.put("company", "/web/v1/company/1/"); data.put("contact", "John Doe"); data.put("country", "Denmark"); data.put("email", "sample@gmail.com"); data.put("name", "Mary Doe"); data.put("notes", "Just another guy"); data.put("phone", "639xxxxxxxxx"); data.put("street_address", "Staunings Pl. 3, 1607 Copenhagen V, " + "Denmark"); data.put("zip_code", "1607"); URL url = new URL(String.format("%s/%s/", APIURL, ENDPOINT)); String authorizationHeader = String.format("ApiKey %s:%s", USERNAME, APIKEY); // make a request with the required authorization API key hearders. HttpURLConnection request = (HttpURLConnection) url.openConnection(); request.setDoOutput(true); request.setDoInput(true); request.setRequestMethod("POST"); request.setRequestProperty("Content-Type", "application/json"); request.setRequestProperty("Authorization", authorizationHeader); // read the output and convert into UTF-8 encoding OutputStream output = request.getOutputStream(); output.write(data.toString().getBytes("UTF-8")); output.close(); BufferedReader br = new BufferedReader(new InputStreamReader( (request.getInputStream()))); // read the response String response; System.out.println(String.format("Status Code: (%s)", request.getResponseCode())); response = br.readLine(); System.out.println(response); request.disconnect(); } catch (IOException e) { e.printStackTrace(); } } }
Once you replace it with the appropriate value. In your netbeans
editor press F6
A terminal/console will pop up showing the result of your script. Similar values below.
Status Code: (201) {"city": "Copenhagen", "company": "/web/v1/company/1/", "contact": **``**"John Doe", "country": "Denmark", "customer_group": null, "email": "sample@gmail.com", "id": 42, "name": "Mary Doe", "notes": "Just another guy", "number": "", "phone": "639xxxxxxxxx", "resource_uri": "/web/v1/customer/42/", "street_address": "Staunings Pl. 3, 1607 Copenhagen V, Denmark", "zip_code": "1607"} BUILD SUCCESSFUL (total time: 0 seconds)
Sending POST
request to our API takes few easy steps. Let's say we want to add this sample data.
Name: John Doe City: Copenhagen Company: /web/v1/company/1/ # your company uri Contact: Mary Doe Country: Denmark Email: sample@gmail.com Notes: Just another guy Phone: Number: 639xxxxxxxxx Street Address: Staunings Pl. 3, 1607 Copenhagen V, Denmark Zip Code: 1607
Let's create a simple ruby request that sends a POST
request on our Customer
API endpoint. We add the sample data on our data dict and update the API_URL
, API_KEY
and USERNAME
.
For example:
#!/usr/bin/env ruby require 'json' require "net/http" API_URL = 'https://intempus.dk/web/v1' API_KEY = '<your_api_key>' USERNAME = '<your_username>' ENDPOINT = 'customer' URL = "%{api_url}/%{endpoint}/" % {:api_url => API_URL, :endpoint => ENDPOINT} JSON_DATA = { city: "Copenhagen", company: "/web/v1/company/1/", contact: "John Doe", country: "Denmark ", email: "sample@gmail.com", name: "Mary Doe", notes: "Just another guy", phone: "639xxxxxxxxx", street_address: "Staunings Pl. 3, 1607 Copenhagen V, Denmark", zip_code: "1607", }.to_json def create_api_object() # response = Net::HTTP.get_response(URI.parse(url))\ uri = URI.parse(URL) http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Post.new(uri.path, 'Content-Type' => 'application/json') request.add_field("Authorization", "ApiKey %{username}:%{api_key}" % { :username => USERNAME, :api_key => API_KEY}) request.body = JSON_DATA response = http.request(request) status = response.kind_of? Net::HTTPSuccess data = JSON.parse(response.body) return "Response Code: #{response.code} - #{status}\nData: #{data}" end if __FILE__ == $0 response = create_api_object() puts response end
Once you're done, save and name it create_api_object.rb
. On your terminal/console, run this command:
ruby ~/path/to/create_api_object.rb
You should see output like this:
Response Code: 201 - true Data: {"city"=>"Copenhagen", "company"=>"/web/v1/company/1/", "contact"=>"John Doe", "country"=>"Denmark ", "customer_group"=>nil, "email"=>"sample@gmail.com", "id"=>43, "name"=>"Mary Doe", "notes"=>"Just another guy", "number"=>"", "phone"=>"639xxxxxxxxx", "resource_uri"=>"/web/v1/customer/43/", "street_address"=>"Staunings Pl. 3, 1607 Copenhagen V, Denmark", "zip_code"=>"1607"}
Note: The PATCH method of updating a record will only update fields that are provided in the request. All fields that are not provided by a request will not be updated. If you would like to ensure a record stored on Intempus is completely set, use the PUT method below.
Sending PATCH
request to our API takes few easy steps. For example we update the Country
and Street Address
.
City: Nuuk Street Address: Aqqusinersuaq street, Nuuk, Greenland
Let's create a simple python code that sends a patch
request on our Customer
API endpoint with an OBJECT_ID
of 1.
Let's add the sample data above City
and Street Address
. then update the API_URL
, API_KEY
and USERNAME
.
For example:
#!/usr/bin/env python import json import requests API_URL = 'https://intempus.dk/web/v1' API_KEY = '<your_api_key>' USERNAME = '<your_username>' ENDPOINT = 'customer' OBJECT_ID = '<object_id>' headers = { 'content-type': 'application/json', 'Authorization': 'ApiKey {user}:{apikey}'.format( user=USERNAME, apikey=API_KEY), } data = { "city": "Nuuk", "street_address": "Aqqusinersuaq street, Nuuk, Greenland", } def get_intempus_api(): url = '{api_url}/{endpoint}/{object_id}/'.format( api_url=API_URL, endpoint=ENDPOINT, object_id=OBJECT_ID) response = requests.patch(url, data=json.dumps(data), headers=headers) return "Request Status: %s\nData: %s" % (response.status_code, response.content) if __name__ == '__main__': response = get_intempus_api() print response
Once you're done, save and name it update_customer.py
. On your terminal/console, run this command:
python ~/path/to/update_customer.py
You should see output like this:
Request Status: 202 Data: {"city": "Nuuk", "company": "/web/v1/company/1/", "contact": "John Doe", "country": "Denmark ", "customer_group": null, "email": "sample@gmail.com", "id": 20, "name": "Mary Doe", "notes": "Just another guy", "number": "", "phone": "639xxxxxxxxx", "resource_uri": "/web/v1/customer/20/", "street_address": "Aqqusinersuaq street, Nuuk, Greenland", "zip_code": "1607"}
If the request status is 202, it means we successfully updated our existing customer data.
Sending PATCH
request to our API takes few easy steps. For example we update the Country
and Street Address
.
City: Nuuk Street Address: Aqqusinersuaq street, Nuuk, Greenland
Let's create a simple C# code that sends a patch
request on our Customer
API endpoint with an OBJECT_ID
of 1.
Let's add the sample data above City
and Street Address
. then update the API_URL
, API_KEY
, OBJECT_ID
and USERNAME
.
For example:
using System; using System.Net; using System.IO; using System.Web.Script.Serialization; class patch_API_object { public static string API_URL = "https://intempus.dk/web/v1"; public static string API_KEY = "<your_api_key>"; public static string USERNAME = "<your_username>"; public static string ENDPOINT = "customer"; public static string OBJECT_ID = "1"; public static string DATA = new JavaScriptSerializer().Serialize(new { city = "Nuuk", street_address = "Aqqusinersuaq street, Nuuk, Greenland" }); static void Main(string[] args) { string response = CreateAPIObject(); Console.WriteLine (response); } public static string CreateAPIObject() { string url = string.Format("{0}/{1}/{2}/", API_URL, ENDPOINT, OBJECT_ID); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.ContentType = "application/json"; //set the content type to JSON. request.Method = "PATCH"; // add the Authorization header to authenticate on our endpoint. string authorizationheader = string.Format("Authorization: ApiKey {0}:{1}", USERNAME, API_KEY); request.Headers.Add(authorizationheader); //initiate the request. using (var streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write(DATA); streamWriter.Flush(); streamWriter.Close(); } // Get the response. var httpResponse = (HttpWebResponse)request.GetResponse(); var statusCode = httpResponse.StatusCode; StreamReader response = new StreamReader(httpResponse.GetResponseStream()); return string.Format("Response Code: {0} - {1}\nData: {2}", (int)statusCode, statusCode.ToString(), response.ReadToEnd()); } }
Once you replace it with the appropriate value. In your monodevelop
editor press F5
A terminal/console will pop up showing the result of your script. Similar values below.
data: Response Code: 202 - Accepted Data: {"city": "Nuuk", "company": "/web/v1/company/1/", "contact": "John Doe", "country": "Denmark", "customer_group": null, "email": "sample@gmail.com", "id": 16, "name": "Mary Doe", "notes": "Just another guy", "number": "", "phone": "639xxxxxxxxx", "resource_uri": "/web/v1/customer/16/", "street_address": "Aqqusinersuaq street, Nuuk, Greenland", "zip_code": "1607"} Press any key to continue...
Sending PATCH
request to our API takes few easy steps. For example we update the Country
and Street Address
.
City: Nuuk Street Address: Aqqusinersuaq street, Nuuk, Greenland
Let's create a simple Java
code that sends a patch
request on our Customer
API endpoint with an OBJECT_ID
of 1.
Let's add the sample data above City
and Street Address
. then update the API_URL
, API_KEY
, OBJECTID
and USERNAME
.
For example:
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.io.OutputStream; import org.json.JSONObject; class UpdateAPIObjectPatch { public static String APIURL = "https://intempus.dk/web/v1"; public static String APIKEY = "<your_api_key>"; public static String USERNAME = "<your_username>"; public static String ENDPOINT = "customer"; public static String OBJECTID = "<object_id>"; public static void main(String[] args) { try { JSONObject data = new JSONObject(); // sample data data.put("city", "Nuuk"); data.put("street_address", "Aqqusinersuaq street, Nuuk, Greenland"); URL url = new URL(String.format("%s/%s/%s/", APIURL, ENDPOINT, OBJECTID)); String authorizationHeader = String.format("ApiKey %s:%s", USERNAME, APIKEY); // make a request with the required authorization API key hearders. HttpURLConnection request = (HttpURLConnection) url.openConnection(); request.setDoOutput(true); request.setDoInput(true); request.setRequestProperty("X-HTTP-Method-Override", "PATCH"); request.setRequestProperty("Content-Type", "application/json"); request.setRequestProperty("Authorization", authorizationHeader); // read the output and convert into UTF-8 encoding OutputStream output = request.getOutputStream(); output.write(data.toString().getBytes("UTF-8")); output.close(); BufferedReader br = new BufferedReader(new InputStreamReader( (request.getInputStream()))); // read the response String response; System.out.println(String.format("Status Code: (%s)", request.getResponseCode())); response = br.readLine(); System.out.println(response); request.disconnect(); } catch (IOException e) { e.printStackTrace(); } } }
Once you replace it with the appropriate value. In your netbeans
editor press F6
A terminal/console will pop up showing the result of your script. Similar values below.
Status Code: (202) {"city": "Nuuk", "company": "/web/v1/company/1/", "contact": "John Doe", "country": "Denmark", "customer_group": null, "email": "sample@gmail.com", "id": 17, "name": "Mary Doe", "notes": "Just another guy", "number": "", "phone": "639xxxxxxxxx", "resource_uri": "/web/v1/customer/17/", "street_address": "Aqqusinersuaq street, Nuuk, Greenland", "zip_code": "1607"} BUILD SUCCESSFUL (total time: 0 seconds)
Sending PATCH
request to our API takes few easy steps. For example we update the Country
and Street Address
.
City: Nuuk Street Address: Aqqusinersuaq street, Nuuk, Greenland
Let's create a simple ruby code that sends a patch
request on our Customer
API endpoint with an OBJECT_ID
of 1.
Let's add the sample data above City
and Street Address
. then update the API_URL
, API_KEY
and USERNAME
.
For example:
#!/usr/bin/env ruby require 'json' require "net/http" API_URL = 'https://intempus.dk/web/v1' API_KEY = '<your_api_key>' USERNAME = '<your_username>' ENDPOINT = 'customer' OBJECT_ID = '<object_id>' URL = "%{api_url}/%{endpoint}/%{object_id}/" % {:api_url => API_URL, :endpoint => ENDPOINT, :object_id => OBJECT_ID} JSON_DATA = { city: "Nuuk", street_address: "Aqqusinersuaq street, Nuuk, Greenland" }.to_json def patch_api_object() # response = Net::HTTP.get_response(URI.parse(url))\ uri = URI.parse(URL) http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Patch.new(uri.path, 'Content-Type' => 'application/json') request.add_field("Authorization", "ApiKey %{username}:%{api_key}" % { :username => USERNAME, :api_key => API_KEY}) request.body = JSON_DATA response = http.request(request) status = response.kind_of? Net::HTTPSuccess data = JSON.parse(response.body) return "Response Code: #{response.code} - #{status}\nData: #{data}" end if __FILE__ == $0 response = patch_api_object() puts response end
Once you're done, save and name it patch_api_object.rb
. On your terminal/console, run this command:
ruby ~/path/to/patch_api_object.rb
You should see output like this:
Response Code: 202 - true Data: {"city"=>"Nuuk", "company"=>"/web/v1/company/1/", "contact"=>"Peter Doe", "country"=>"", "customer_group"=>nil, "email"=>"", "id"=>16, "name"=>"Edward Doe", "notes"=>"", "number"=>"", "phone"=>"", "resource_uri"=>"/web/v1/customer/16/", "street_address"=>"Aqqusinersuaq street, Nuuk, Greenland", "zip_code"=>""}
Note: The PUT method of updating a record requires all fields are provided in the request. If any field is not provided by a request, the record will not be updated. If you would like to partially update a record stored on Intempus, use the PATCH method above.
Sending PUT
request to our API takes few easy steps. For example we update the Name
and Contact
.
Name: Edward Doe Contact: Peter Doe
Let's update our customer data with an OBJECT_ID
of 1. We will use PUT
request on updating our customer data.
Let's create a simple python code that sends a PUT
request.
For example:
#!/usr/bin/env python import json import requests API_URL = 'https://intempus.dk/web/v1' API_KEY = '<your_api_key>' USERNAME = '<your_username>' ENDPOINT = 'customer' OBJECT_ID = '<object_id>' headers = { 'content-type': 'application/json', 'Authorization': 'ApiKey {user}:{apikey}'.format( user=USERNAME, apikey=API_KEY), } data = { "name": "Edward Doe", "contact": "Peter Doe", } def get_intempus_api(): url = '{api_url}/{endpoint}/{object_id}/'.format( api_url=API_URL, endpoint=ENDPOINT, object_id=OBJECT_ID) response = requests.put(url, data=json.dumps(data), headers=headers) return "Request Status: %s\nData: %s" % (response.status_code, response.content) if __name__ == '__main__': response = get_intempus_api() print response
Once you're done, save and name it put_customer.py. On your terminal/console, run this command:
python ~/path/to/put_customer.py
You should see output like this:
user@pc:~$ python put_customer.py {'request_status': 200, 'data': '{"city": "Copenhagen", "company": "/web/v1/company/1/", "contact": "Peter Doe", "country": "Denmark ", "customer_group": null, "email": "sample@gmail.com", "id": 1, "name": "Edward Doe", "notes": "Just another guy", "number": "1", "phone": "639xxxxxxxxx", "pk": "1", "resource_uri": "/web/v1/customer/1/", "street_address": "Staunings Pl. 3, 1607 Copenhagen V, Denmark", "zip_code": "1607"}'}
If request_status is 200 it means that you're able to update on our Customer API endpoint.
Sending PUT
request to our API takes few easy steps. For example we update the Name
and Contact
.
Name: Edward Doe Contact: Peter Doe
Let's update our customer data with an OBJECT_ID
of 1. We will use PUT
request on updating our customer data.
Let's create a simple C# code that sends a PUT
request.
For example:
using System; using System.Net; using System.IO; using System.Web.Script.Serialization; class put_API_object { public static string API_URL = "https://intempus.dk/web/v1"; public static string API_KEY = "<your_api_key>"; public static string USERNAME = "<your_username>"; public static string ENDPOINT = "customer"; public static string OBJECT_ID = "<object_id>"; public static string DATA = new JavaScriptSerializer().Serialize(new { name = "Edward Doe", contact = "Peter Doe" }); static void Main(string[] args) { string response = CreateAPIObject(); Console.WriteLine (response); } public static string CreateAPIObject() { string url = string.Format("{0}/{1}/{2}/", API_URL, ENDPOINT, OBJECT_ID); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.ContentType = "application/json"; //set the content type to JSON. request.Method = "PUT"; // add the Authorization header to authenticate on our endpoint. string authorizationheader = string.Format("Authorization: ApiKey {0}:{1}", USERNAME, API_KEY); request.Headers.Add(authorizationheader); //initiate the request. using (var streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write(DATA); streamWriter.Flush(); streamWriter.Close(); } // Get the response. var httpResponse = (HttpWebResponse)request.GetResponse(); var statusCode = httpResponse.StatusCode; StreamReader response = new StreamReader(httpResponse.GetResponseStream()); return string.Format("Response Code: {0} - {1}\nData: {2}", (int)statusCode, statusCode.ToString(), response.ReadToEnd()); } }
Once you replace it with the appropriate value. In your monodevelop
editor press F5
A terminal/console will pop up showing the result of your script. Similar values below.
Response Code: 200 - OK Data: {"city": "", "company": "/web/v1/company/1/", "contact": "Peter Doe", "country": "", "customer_group": null, "email": "", "id": 16, "name": "Edward Doe", "notes": "", "number": "", "phone": "", "pk": "16", "resource_uri": "/web/v1/customer/16/", "street_address": "", "zip_code": ""} Press any key to continue...
Sending PUT
request to our API takes few easy steps. For example we update the Name
and Contact
.
Name: Edward Doe Contact: Peter Doe
Let's update our customer data with an OBJECTID
of 1. We will use PUT
request on updating our customer data.
Let's create a simple Java
code that sends a PUT
request.
For example:
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.io.OutputStream; import org.json.JSONObject; class UpdateAPIObjectPUT { public static String APIURL = "https://intempus.dk/web/v1"; public static String APIKEY = "<your_api_key>"; public static String USERNAME = "<your_username>"; public static String ENDPOINT = "customer"; public static String OBJECTID = "<object_id>"; public static void main(String[] args) { try { JSONObject data = new JSONObject(); // sample data data.put("name", "Edward Doe"); data.put("contact", "Peter Doe"); URL url = new URL(String.format("%s/%s/%s/", APIURL, ENDPOINT, OBJECTID)); String authorizationHeader = String.format("ApiKey %s:%s", USERNAME, APIKEY); // make a request with the required authorization API key hearders. HttpURLConnection request = (HttpURLConnection) url.openConnection(); request.setDoOutput(true); request.setDoInput(true); request.setRequestProperty("X-HTTP-Method-Override", "PUT"); request.setRequestProperty("Content-Type", "application/json"); request.setRequestProperty("Authorization", authorizationHeader); // read the output and convert into UTF-8 encoding OutputStream output = request.getOutputStream(); output.write(data.toString().getBytes("UTF-8")); output.close(); BufferedReader br = new BufferedReader(new InputStreamReader( (request.getInputStream()))); // read the response String response; System.out.println(String.format("Status Code: (%s)", request.getResponseCode())); response = br.readLine(); System.out.println(response); request.disconnect(); } catch (IOException e) { e.printStackTrace(); } } }
Once you replace it with the appropriate value. In your netbeans
editor press F6
A terminal/console will pop up showing the result of your script. Similar values below.
Status Code: (201) {"city": "", "company": "/web/v1/company/1/", "contact": "Peter Doe", "country": "", "customer_group": null, "email": "", "id": 16, "name": "Edward Doe", "notes": "", "number": "", "phone": "", "pk": "16", "resource_uri": "/web/v1/customer/16/", "street_address": "", "zip_code": ""} BUILD SUCCESSFUL (total time: 0 seconds)
Sending PUT
request to our API takes few easy steps. For example we update the Name
and Contact
.
Name: Edward Doe Contact: Peter Doe
Let's update our customer data with an OBJECT_ID
of 1. We will use PUT
request on updating our customer data.
Let's create a simple ruby code that sends a PUT
request.
For example:
#!/usr/bin/env ruby require 'json' require "net/http" API_URL = 'https://intempus.dk/web/v1' API_KEY = '<your_api_key>' USERNAME = '<your_username>' ENDPOINT = 'customer' OBJECT_ID = '<object_id>' URL = "%{api_url}/%{endpoint}/%{object_id}/" % {:api_url => API_URL, :endpoint => ENDPOINT, :object_id => OBJECT_ID} JSON_DATA = { name: "Edward Doe", contact: "Peter Doe" }.to_json def put_api_object() # response = Net::HTTP.get_response(URI.parse(url))\ uri = URI.parse(URL) http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Put.new(uri.path, 'Content-Type' => 'application/json') request.add_field("Authorization", "ApiKey %{username}:%{api_key}" % { :username => USERNAME, :api_key => API_KEY}) request.body = JSON_DATA response = http.request(request) status = response.kind_of? Net::HTTPSuccess data = JSON.parse(response.body) return "Response Code: #{response.code} - #{status}\nData: #{data}" end if __FILE__ == $0 response = put_api_object() puts response end
Once you're done, save and name it put_api_object.rb
. On your terminal/console, run this command:
ruby ~/path/to/put_api_object.rb
You should see output like this:
Response Code: 200 - true Data: {"city"=>"Nuuk", "company"=>"/web/v1/company/1/", "contact"=>"Peter Doe", "country"=>"", "customer_group"=>nil, "email"=>"", "id"=>16, "name"=>"Edward Doe", "notes"=>"", "number"=>"", "phone"=>"", "pk"=>"16", "resource_uri"=>"/web/v1/customer/16/", "street_address"=>"Aqqusinersuaq street, Nuuk, Greenland", "zip_code"=>""}
Sending DELETE
request to our API takes few easy steps. For example we want to delete our existing customer data with an OBJECT_ID
of 1.
Let's create another simple python request which delete customer data.
For example:
#!/usr/bin/env python import requests API_URL = 'https://intempus.dk/web/v1' API_KEY = '<your_api_key>' USERNAME = '<your_username>' ENDPOINT = 'customer' OBJECT_ID = '<object_id>' headers = { 'content-type': 'application/json', 'Authorization': 'ApiKey {user}:{apikey}'.format( user=USERNAME, apikey=API_KEY), } def get_intempus_api(): url = '{api_url}/{endpoint}/{object_id}/'.format( api_url=API_URL, endpoint=ENDPOINT, object_id=OBJECT_ID) response = requests.delete(url, headers=headers) return "Request Status: %s\nData: %s" % (response.status_code, response.content) if __name__ == '__main__': response = get_intempus_api() print response
Once you're done, save and name it delete_customer.py. On your terminal/console, run this command:
python ~/path/to/delete_customer.py
You should see output like this:
user@pc:~$ python delete_customer.py {'request_status': 204, 'data': ''}
If request_status is 204 it means that you're able to execute the delete request.
Sending DELETE
request to our API takes few easy steps. For example we want to delete our existing customer data with an OBJECT_ID
of 1.
Let's create another simple C# code which delete the customer data.
For example:
using System; using System.Net; using System.IO; class delete_API_object { public static string API_URL = "https://intempus.dk/web/v1"; public static string API_KEY = "<your_api_key>"; public static string USERNAME = "<your_username>"; public static string ENDPOINT = "customer"; public static string OBJECT_ID = "<object_id>"; static void Main(string[] args) { string response = CreateAPIObject(); Console.WriteLine (response); } public static string CreateAPIObject() { string url = string.Format("{0}/{1}/{2}/", API_URL, ENDPOINT, OBJECT_ID); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.ContentType = "application/json"; //set the content type to JSON. request.Method = "DELETE"; // add the Authorization header to authenticate on our endpoint. string authorizationheader = string.Format("Authorization: ApiKey {0}:{1}", USERNAME, API_KEY); request.Headers.Add(authorizationheader); // Get the response. var httpResponse = (HttpWebResponse)request.GetResponse(); var statusCode = httpResponse.StatusCode; StreamReader response = new StreamReader(httpResponse.GetResponseStream()); return string.Format("Response Code: {0} - {1}\nData: {2}", (int)statusCode, statusCode.ToString(), response.ReadToEnd()); } }
Once you replace it with the appropriate value. In your monodevelop
editor press F5
A terminal/console will pop up showing the result of your script. Similar values below.
Response Code: 204 - NoContent Press any key to continue...
Sending DELETE
request to our API takes few easy steps.
For example we want to delete our existing customer data with an OBJECT_ID
of 1.
Let's create another simple Java
code which delete the customer data.
For example:
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; class DeleteAPIObject { public static String APIURL = "https://intempus.dk/web/v1"; public static String APIKEY = "<your_api_key>"; public static String USERNAME = "<your_username>"; public static String ENDPOINT = "customer"; public static String OBJECTID = "<object_id>"; public static void main(String[] args) { try { URL url = new URL(String.format("%s/%s/%s/", APIURL, ENDPOINT, OBJECTID)); String authorizationHeader = String.format("ApiKey %s:%s", USERNAME, APIKEY); // make a request with the required authorization API key hearders. HttpURLConnection request = (HttpURLConnection) url.openConnection(); request.setDoOutput(true); request.setRequestMethod("DELETE"); request.setRequestProperty("Authorization", authorizationHeader); BufferedReader br = new BufferedReader(new InputStreamReader( (request.getInputStream()))); // read the response String response; System.out.println(String.format("Status Code: (%s)", request.getResponseCode())); response = br.readLine(); System.out.println(response); request.disconnect(); } catch (IOException e) { e.printStackTrace(); } } }
Once you replace it with the appropriate value. In your netbeans
editor press F6
A terminal/console will pop up showing the result of your script. Similar values below.
Status Code: (204) null BUILD SUCCESSFUL (total time: 3 seconds)
Sending DELETE
request to our API takes few easy steps. For example we want to delete our existing customer data with an OBJECT_ID
of 1.
Let's create another simple ruby request which delete customer data.
For example:
#!/usr/bin/env ruby require 'json' require "net/http" API_URL = 'https://intempus.dk/web/v1' API_KEY = '<your_api_key>' USERNAME = '<your_username>' ENDPOINT = 'customer' OBJECT_ID = '<object_id>' URL = "%{api_url}/%{endpoint}/%{object_id}/" % {:api_url => API_URL, :endpoint => ENDPOINT, :object_id => OBJECT_ID} def delete_api_object() uri = URI.parse(URL) http = Net::HTTP.new(uri.host, uri.port).start request = Net::HTTP::Delete.new(uri.request_uri) request.add_field("Authorization", "ApiKey %{username}:%{api_key}" % { :username => USERNAME, :api_key => API_KEY}) response = http.request(request) status = response.kind_of? Net::HTTPSuccess return "Response Code: #{response.code} - #{status} - No Content" end if __FILE__ == $0 response = delete_api_object() puts response end
Once you're done, save and name it delete_api_object.rb
. On your terminal/console, run this command:
ruby ~/path/to/delete_api_object.rb
You should see output like this:
Response Code: 204 - true - No Content