Create or Update Mock API
Endpoint
POST /apiops/projects/{projectName}/mockapis/{mockApiName}/
Authentication
Requires a Personal API Access Token.
Header
Authorization: Bearer YOUR_TOKEN
Content-Type: application/json
Request
Headers
| Header | Value | Required |
|---|---|---|
| Authorization | Bearer {token} | Yes |
| Content-Type | application/json | Yes |
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| projectName | string | Yes | Project name |
| mockApiName | string | Yes | Name of the Mock API to create or update |
Request Body
The body is a full Mock API definition. It has the same fields as the object that Get Mock API returns. The example below is shortened.
{
"description": "Mock of the customer accounts service",
"version": "1.0.0",
"methodDefList": [
{
"id": "3f7c2a4e-7d0b-4a51-9a8e-0c1d2e3f4a5b",
"name": "/customers/{id}",
"httpMethod": "GET",
"description": "Returns one customer",
"responseList": [
{
"uuid": "8b0e5f3a-2c4d-4e6f-8a1b-3c5d7e9f1a2b",
"httpStatusCode": "OK",
"description": "Customer found",
"exampleList": [
{
"uuid": "1d2e3f4a-5b6c-4d7e-8f9a-0b1c2d3e4f5a",
"responseContentType": "application/json",
"responseBody": "{\"id\": 1, \"name\": \"Customer 1\"}"
}
]
}
]
}
]
}
Apinizer sets these fields itself:
| Field | Value |
|---|---|
| name | The mockApiName path parameter. A name in the body is ignored. |
| projectId | The ID of the project in the projectName path parameter |
| id | The ID of the existing Mock API with the same name in the project. If the project has no such Mock API, Apinizer creates a new ID. |
If version is empty, the Mock API returns the version 1.0.
Response
Success Response (200 OK)
The saved Mock API is returned as the single element of resultList.
{
"status": "SUCCESS",
"resultMessage": "MockAPI saved successfully.",
"resultList": [
{
"id": "66f1c0a2e4b0a1b2c3d4e5f6",
"name": "Customer Accounts",
"description": "Mock of the customer accounts service",
"version": "1.0.0",
"projectId": "66f1bf10e4b0a1b2c3d4e5a1",
"methodDefList": [ ... ]
}
]
}
Error Response (400 Bad Request)
The user does not have the required permission, or the project does not exist.
{
"status": "FAILURE",
"resultMessage": "User does not have required permission for this operation!"
}
Error Response (401 Unauthorized)
The token is missing or not valid. For the error format, see Error Handling.
cURL Example
curl -X POST \
"https://demo.apinizer.com/apiops/projects/MyProject/mockapis/Customer%20Accounts/" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d @customer-accounts-mock-api.json
Notes and Warnings
- Full replacement: The body replaces the whole definition of an existing Mock API. Endpoints that are not in the body are removed.
- No validation of endpoints: Apinizer does not check the endpoints in the body. For example, it does not reject two endpoints with the same method and path. Send a definition that you took from Get Mock API.
- No redeploy: Saving does not redeploy the API Proxies of the Mock API. To apply the changes, redeploy these API Proxies.
Permissions
- User must have
API_CREATOR+MANAGEpermission in the project
Related Documentation
- Get Mock API - Get the full definition of a Mock API
- List Mock APIs - List all Mock APIs of a project