# FreeSwitch Service

first set your maintenance token as an environment variable for later use.

````bash
export MAINTENANCE_TOKEN=<maintenance-token>

### A note on Authentication

Media Magic utilises Auth0 for authentication, and storing personal information about users. This is for security and compliance reasons, as well as a time saver in not implementing authentication ourselves.

To create a front-end or app that integrates into our Auth0, you will need the public token, which can be provided on request.

### Tokens

#### User Token

There are two separate tokens in use with the Media Magic API's. The first is a short-lived user token, which Auth0 returns. Which expires after three days. This token should be used in mobile apps or web apps. This token should be used for basic actions needed by user interfaces.

The user token uses the following format: `Authorization: Bearer <JWT>`.

#### API Keys

The second is a long-lived token, which is stateful and can be invalidated with immediate effect. This token should be used for programatic use-cases. For example, interacting with the rest API to perform automated tasks. For projects and integrations, you will probably need this token. It's advised to use this token where not for use in web apps, apps, or places where a user logs in via the Auth0 login prompt.

API Keys use the following format: `x-mediamagic-key: <UUID>`.

#### API Keys

The second is a long-lived token, which is stateful and can be invalidated with immediate effect. This token should be used for programatic use-cases. For example, interacting with the rest API to perform automated tasks. For projects and integrations, you will probably need this token. It's advised to use this token where not for use in web apps, apps, or places where a user logs in via the Auth0 login prompt.

API Keys use the following format: `x-mediamagic-key: <UUID>`.

## Examples

For each of these examples, we're using the user or JWT token. But you can also use the API key:

```bash
x-mediamagic-key:<API_KEY>
````

Rather than:

```bash
Authorization:Bearer <JWT>
```

### Authenticate

First we grab a generated login URL from the API. Open the link returned, this will take you through the user authentication process.

Once you've authenticated, a callback url will be called with an access token. Which is then validated and swapped for a user token.

```bash
$ curl -X GET https://mediamagic.dev/api/v2/auth/login -H 'content-type: application/mediamagic.rest.v1+json'

// Example output
// {"access_token":"<token>","refresh_token":"<refresh-token>","id_token":"","token_type":"Bearer"}
```

Now set your auth token as an environment variable for later use.

```bash
export TOKEN=<token>
```

## Assign Number

```bash
curl 'https://mediamagic.dev/api/v2/assign-number' \
--header "Authorization: Bearer $TOKEN" 

 // Output Example 
{
  "role": "user",
  "phone_number": "17036879447",
  "auth0_id": "auth0|6316dd611151a2dd290c2cca",
  "extension": "1006",
  "updated_at": "2022-09-09T15:52:21.485072+05:30",
  "created_at": "2022-09-07T11:01:26.52429+05:30"
}
```

## Call Recording

```bash
curl 'https://mediamagic.dev/api/v2/call-recording' \
--header "Authorization: Bearer $TOKEN" 

// Output Example
[
 {
  "id": 1625,
" provider": 0,
  "call_to": "1005",
  "call_from": "1006",
  "extension": 16,
  "bill_duration": 10,
  "didnumber": 0,
  "domain": "phoneai.boomslang.io",
  "hangup_cause": "NORMAL_CLEARING",
  "recording": "",
  "call_direction": "outbound",
  "call_uuid": "3e926aae-0b03-11ed-a6cf-9dde3cd1ca46",
  "created_at": "2022-07-24T03:47:05.82719Z",
  "started_at": "2022-07-23T20:46:48Z"
 }
]
```

## Call link

```bash
curl 'https://mediamagic.dev/api/v2/call-link?source_number=2762087784&destination_number=2403019517' \
--header "Authorization: Bearer $TOKEN"  
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mediamagic.dev/product-docs/services/freeswitch-service.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
