Subscription creatpayment link issue

I have created plan and got plan id from response but when i passing that planid in createpaymentlink request that time it is showing something like below.

{
“errors”: [
{
“category”: “INVALID_REQUEST_ERROR”,
“code”: “INVALID_VALUE”,
“detail”: “Invalid object OI6R2HGECR5ETQNXAMI62UHL: incorrect object type SUBSCRIPTION_PLAN.”,
“field”: “subscription_plan_id”
}
]
}

Create Plan request as below

curl https://connect.squareupsandbox.com/v2/catalog/object
-X POST
-H ‘Square-Version: 2023-09-25’
-H ‘Authorization: Bearer ACCESS_TOKEN’
-H ‘Content-Type: application/json’
-d ‘{
“idempotency_key”: “f9ab22ee-5046-4e39-9963-59a02ba875e3”,
“object”: {
“type”: “SUBSCRIPTION_PLAN”,
“id”: “#1990”,
“subscription_plan_data”: {
“name”: “testetstet”,
“phases”: [
{
“cadence”: “MONTHLY”,
“recurring_price_money”: {
“amount”: 1500,
“currency”: “USD”
}
},
{
“cadence”: “MONTHLY”,
“recurring_price_money”: {
“amount”: 1500,
“currency”: “USD”
}
}
],
“all_items”: true
}
}
}’

Create Plan response as below

{
“catalog_object”: {
“type”: “SUBSCRIPTION_PLAN”,
“id”: “OI6R2HGECR5ETQNXAMI62UHL”,
“updated_at”: “2023-10-02T09:29:42.987Z”,
“created_at”: “2023-10-02T09:29:42.987Z”,
“version”: 1696238982987,
“is_deleted”: false,
“present_at_all_locations”: true,
“subscription_plan_data”: {
“name”: “testetstet”,
“all_items”: true
}
},
“id_mappings”: [
{
“client_object_id”: “#189”,
“object_id”: “OI6R2HGECR5ETQNXAMI62UHL”
}
]
}

Createpayment link request as below

curl https://connect.squareupsandbox.com/v2/online-checkout/payment-links
-X POST
-H ‘Square-Version: 2023-09-25’
-H ‘Authorization: Bearer ACCESS_TOKEN’
-H ‘Content-Type: application/json’
-d ‘{
“idempotency_key”: “57291bd7-dce4-4617-ba9a-944ae4d7cd08”,
“quick_pay”: {
“name”: “Gym membership fees”,
“price_money”: {
“amount”: 1500,
“currency”: “USD”
},
“location_id”: “LTBWC2JWZ5WV6”
},
“checkout_options”: {
“subscription_plan_id”: “OI6R2HGECR5ETQNXAMI62UHL”
}
}’

Createpaymentlink response as below

{
“errors”: [
{
“category”: “INVALID_REQUEST_ERROR”,
“code”: “INVALID_VALUE”,
“detail”: “Invalid object OI6R2HGECR5ETQNXAMI62UHL: incorrect object type SUBSCRIPTION_PLAN.”,
“field”: “subscription_plan_id”
}
]
}

Api log request as below

{
“idempotency_key”: “57291bd7-dce4-4617-ba9a-944ae4d7cd08”,
“quick_pay”: {
“name”: “Gym membership fees”,
“price_money”: {
“amount”: 1500,
“currency”: “USD”
},
“location_id”: “LTBWC2JWZ5WV6”
},
“checkout_options”: {
“subscription_plan_id”: “OI6R2HGECR5ETQNXAMI62UHL”
}
}

Your getting this error because of your Square API version. The subscription object shape has changed and any version newer then 2023-06-08 takes the new model. If you set the version of one older then 2023-06-08 it will work as expected. :slightly_smiling_face:

1 Like

So if i want to proceed with the latest version then where/what is should change?

image

Still not working. Same response getting(invalid object type).

I took a look at the API Logs and the API version is being passed in the header which is overriding the API version set in the application.


:slightly_smiling_face:

Hi @Bryan-Square .

I got the same problem in the API Explorer.
I create a subscription plan using Catalog → upsertCatalogObject → SUBSCRIPTION_PLAN (And i fill all needed information). The subscription plan is well created and i can retreive it.

But when I try to create a Payment link using Checkout → Create Payment Link and I add the subscription_plan_id, i got the same error :

 "category": "INVALID_REQUEST_ERROR",
      "code": "INVALID_VALUE",
      "detail": "Invalid object `X55Q3YURTQVDVWCLZM6S3CXF`: incorrect object type `SUBSCRIPTION_PLAN`.",
      "field": "subscription_plan_id"

I use the latest version in teh API Explorer.

How to solve it ?
Thanks in advance

You’ll want to pass in the subscription_plan_variation_id when creating the link for the subscription. :slightly_smiling_face:

1 Like

Hi @Bryan-Square, I’m experiencing the same issues using both the API explorer online in addition to sending requests locally using the latest Python SDK (30.0.0.20231115) to create the catalog objects using the POST request to create payment links. I tried searching for the subscription_plan_variation_id you mentioned but can’t find it, are you able to point me in the right direction at all?

When you retrieve the subscription with the Catalog API the subscription_variation_id will be included in the response. :slightly_smiling_face:

Thanks for the quick response! I’m currently following the guide here Subscription Plan Checkout. Using the API explorer, I send this POST request:

curl https://connect.squareupsandbox.com/v2/catalog/object \
  -X POST \
  -H 'Square-Version: 2023-11-15' \
  -H 'Authorization: Bearer access_token' \
  -H 'Content-Type: application/json' \
  -d '{
    "idempotency_key": "8219e81b-bc43-4cd6-a826-72fe2552699e",
    "object": {
      "type": "SUBSCRIPTION_PLAN",
      "id": "#test-plan-1",
      "subscription_plan_data": {
        "phases": [
          {
            "cadence": "WEEKLY",
            "recurring_price_money": {
              "amount": 1500,
              "currency": "AUD"
            }
          }
        ],
        "name": "Test Sub for Variation ID"
      }
    }
  }'

And this is the response I get back:

cache-control: max-age=0, private, must-revalidate
content-encoding: gzip
content-type: application/json
date: Tue, 12 Dec 2023 21:51:56 GMT
square-version: 2023-11-15

{
  "catalog_object": {
    "type": "SUBSCRIPTION_PLAN",
    "id": "KVP6GDEADUAJRHC2QLZMM3JW",
    "updated_at": "2023-12-12T21:51:56.359Z",
    "created_at": "2023-12-12T21:51:56.359Z",
    "version": 1702417916359,
    "is_deleted": false,
    "present_at_all_locations": true,
    "subscription_plan_data": {
      "name": "Test Sub for Variation ID"
    }
  },
  "id_mappings": [
    {
      "client_object_id": "#test-plan-1",
      "object_id": "KVP6GDEADUAJRHC2QLZMM3JW"
    }
  ]
}

Running a GET on the list catalog gives me (only a subset posted here for brevity):

{
      "type": "SUBSCRIPTION_PLAN",
      "id": "KVP6GDEADUAJRHC2QLZMM3JW",
      "updated_at": "2023-12-12T21:51:56.359Z",
      "created_at": "2023-12-12T21:51:56.359Z",
      "version": 1702417916359,
      "is_deleted": false,
      "present_at_all_locations": true,
      "subscription_plan_data": {
        "name": "Test Sub for Variation ID"
      }

So far I haven’t seen anything for subscription_variation_id, and when I do a POST for creating the payment link using:

curl https://connect.squareupsandbox.com/v2/online-checkout/payment-links \
  -X POST \
  -H 'Square-Version: 2023-11-15' \
  -H 'Authorization: Bearer access_token' \
  -H 'Content-Type: application/json' \
  -d '{
    "idempotency_key": "c2e30f52-047c-48f5-9f9c-5c7907d288ac",
    "quick_pay": {
      "name": "Gym membership fees",
      "price_money": {
        "amount": 1500,
        "currency": "AUD"
      },
      "location_id": "LFXJE6JW7MHEX"
    },
    "checkout_options": {
      "subscription_plan_id": "KVP6GDEADUAJRHC2QLZMM3JW"
    }
  }'

I get:

cache-control: no-cache
content-length: 200
content-type: application/json
date: Tue, 12 Dec 2023 22:00:27 GMT
square-version: 2023-11-15

{
  "errors": [
    {
      "category": "INVALID_REQUEST_ERROR",
      "code": "INVALID_VALUE",
      "detail": "Invalid object `KVP6GDEADUAJRHC2QLZMM3JW`: incorrect object type `SUBSCRIPTION_PLAN`.",
      "field": "subscription_plan_id"
    }
  ]
}

Is there a step that I’m missing before running the upsert catalog object request?

When you create a subscription you’ll want to create it according to this guide. The guide for the Checkout API is in the process of being updated to support the new subscription model that was released in June of this last year.

Also when sharing examples please be sure to redact your access token. The are essentially the password for the account. :slightly_smiling_face:

1 Like

Thanks again for the speedy response! I’ll use the other guide and go from there, and good pickup re: token, I didn’t realise it got captured in plain text when I copied the request over! I’ve changed it within my sandbox as a precaution as well.