# Create or update a provider connection

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://apidocs.cata.sg/pos-integration-service-api/api/v-1/provider-connections/slug/llms.txt.
> For full documentation content, see https://apidocs.cata.sg/pos-integration-service-api/api/v-1/provider-connections/slug/llms-full.txt.

PUT http://localhost:8080/api/v1/provider-connections/{slug}
Content-Type: application/json

Upserts the connection. Validates that the provider slug exists.

Reference: https://apidocs.cata.sg/pos-integration-service-api/api/v-1/provider-connections/slug/create-or-update-a-provider-connection

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: collection
  version: 1.0.0
paths:
  /api/v1/provider-connections/{slug}:
    put:
      operationId: create-or-update-a-provider-connection
      summary: Create or update a provider connection
      description: Upserts the connection. Validates that the provider slug exists.
      tags:
        - >-
          subpackage_api.subpackage_api/v1.subpackage_api/v1/providerConnections.subpackage_api/v1/providerConnections/slug
      parameters:
        - name: slug
          in: path
          description: Provider slug
          required: true
          schema:
            type: string
        - name: X-Api-Key
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/api_v1_provider-connections_{slug}_Create
                  or update a provider connection_Response_200
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/PutApiV1Provider-connectionsSlugRequestBadRequestError
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                status:
                  type: string
                apiKey:
                  type: string
                apiSecret:
                  type: string
                webhookUrl:
                  type: string
                baseUrl:
                  type: string
                config:
                  type: string
              required:
                - status
                - apiKey
                - apiSecret
                - webhookUrl
                - baseUrl
                - config
servers:
  - url: http://localhost:8080
components:
  schemas:
    ApiV1ProviderConnectionsSlugPutResponsesContentApplicationJsonSchemaConnection:
      type: object
      properties:
        id:
          type: integer
        providerSlug:
          type: string
        status:
          type: string
        apiKey:
          type: string
        apiSecret:
          type: string
        webhookUrl:
          type: string
        baseUrl:
          type: string
        config:
          type: string
        lastSyncAt:
          type: string
          format: date-time
        lastError:
          type: string
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
      required:
        - id
        - providerSlug
        - status
        - apiKey
        - apiSecret
        - webhookUrl
        - baseUrl
        - config
        - lastSyncAt
        - lastError
        - createdAt
        - updatedAt
      title: >-
        ApiV1ProviderConnectionsSlugPutResponsesContentApplicationJsonSchemaConnection
    api_v1_provider-connections_{slug}_Create or update a provider connection_Response_200:
      type: object
      properties:
        code:
          type: integer
        isSuccess:
          type: boolean
        message:
          type: string
        connection:
          $ref: >-
            #/components/schemas/ApiV1ProviderConnectionsSlugPutResponsesContentApplicationJsonSchemaConnection
      required:
        - code
        - isSuccess
        - message
        - connection
      title: >-
        api_v1_provider-connections_{slug}_Create or update a provider
        connection_Response_200
    ApiV1ProviderConnectionsSlugPutResponsesContentApplicationJsonSchemaError:
      type: object
      properties:
        code:
          type: integer
        message:
          type: string
        details:
          type: string
        field:
          type: string
      required:
        - code
        - message
        - details
        - field
      title: >-
        ApiV1ProviderConnectionsSlugPutResponsesContentApplicationJsonSchemaError
    PutApiV1Provider-connectionsSlugRequestBadRequestError:
      type: object
      properties:
        error:
          $ref: >-
            #/components/schemas/ApiV1ProviderConnectionsSlugPutResponsesContentApplicationJsonSchemaError
      required:
        - error
      title: PutApiV1Provider-connectionsSlugRequestBadRequestError
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: X-Api-Key

```

## SDK Code Examples

```python api_v1_provider-connections_{slug}_Create or update a provider connection_example
import requests

url = "http://localhost:8080/api/v1/provider-connections/string"

payload = {
    "status": "disconnected",
    "apiKey": "string",
    "apiSecret": "string",
    "webhookUrl": "string",
    "baseUrl": "string",
    "config": "string"
}
headers = {
    "X-Api-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.put(url, json=payload, headers=headers)

print(response.json())
```

```javascript api_v1_provider-connections_{slug}_Create or update a provider connection_example
const url = 'http://localhost:8080/api/v1/provider-connections/string';
const options = {
  method: 'PUT',
  headers: {'X-Api-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"status":"disconnected","apiKey":"string","apiSecret":"string","webhookUrl":"string","baseUrl":"string","config":"string"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go api_v1_provider-connections_{slug}_Create or update a provider connection_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "http://localhost:8080/api/v1/provider-connections/string"

	payload := strings.NewReader("{\n  \"status\": \"disconnected\",\n  \"apiKey\": \"string\",\n  \"apiSecret\": \"string\",\n  \"webhookUrl\": \"string\",\n  \"baseUrl\": \"string\",\n  \"config\": \"string\"\n}")

	req, _ := http.NewRequest("PUT", url, payload)

	req.Header.Add("X-Api-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby api_v1_provider-connections_{slug}_Create or update a provider connection_example
require 'uri'
require 'net/http'

url = URI("http://localhost:8080/api/v1/provider-connections/string")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Put.new(url)
request["X-Api-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"status\": \"disconnected\",\n  \"apiKey\": \"string\",\n  \"apiSecret\": \"string\",\n  \"webhookUrl\": \"string\",\n  \"baseUrl\": \"string\",\n  \"config\": \"string\"\n}"

response = http.request(request)
puts response.read_body
```

```java api_v1_provider-connections_{slug}_Create or update a provider connection_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.put("http://localhost:8080/api/v1/provider-connections/string")
  .header("X-Api-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"status\": \"disconnected\",\n  \"apiKey\": \"string\",\n  \"apiSecret\": \"string\",\n  \"webhookUrl\": \"string\",\n  \"baseUrl\": \"string\",\n  \"config\": \"string\"\n}")
  .asString();
```

```php api_v1_provider-connections_{slug}_Create or update a provider connection_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'http://localhost:8080/api/v1/provider-connections/string', [
  'body' => '{
  "status": "disconnected",
  "apiKey": "string",
  "apiSecret": "string",
  "webhookUrl": "string",
  "baseUrl": "string",
  "config": "string"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'X-Api-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp api_v1_provider-connections_{slug}_Create or update a provider connection_example
using RestSharp;

var client = new RestClient("http://localhost:8080/api/v1/provider-connections/string");
var request = new RestRequest(Method.PUT);
request.AddHeader("X-Api-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"status\": \"disconnected\",\n  \"apiKey\": \"string\",\n  \"apiSecret\": \"string\",\n  \"webhookUrl\": \"string\",\n  \"baseUrl\": \"string\",\n  \"config\": \"string\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift api_v1_provider-connections_{slug}_Create or update a provider connection_example
import Foundation

let headers = [
  "X-Api-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "status": "disconnected",
  "apiKey": "string",
  "apiSecret": "string",
  "webhookUrl": "string",
  "baseUrl": "string",
  "config": "string"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "http://localhost:8080/api/v1/provider-connections/string")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```