How can I add a new carrier service using API?

Hi Everyone

Today I switched to annual plan and as per documentation with annual subscription, I can create new Carrier Service using API.

When I am using API (/admin/api/2020-07/carrier_services.json) to create Service, its returning me a link to authorize app.

Can someone guide, how to add new service.

What docs have you been following?

In those docs, what step are you stuck on?

Following following doc
https://shopify.dev/docs/admin-api/rest/reference/shipping-and-fulfillment/carrierservice#create-2020-07

when i try to create a new service using

POST /admin/api/2020-07/carrier_services.json
{
“carrier_service”: {
“name”: “Shipping Rate Provider”,
“callback_url”: “http://shippingrateprovider.com”,
“service_discovery”: true
}
}

response is

Continue

and when i click on link, it take me to login page and login login i see shopify error page (we will be back soon)

Hi, I just had the same issue when trying to register a carrier service using Postman.

I was able to get around it by doing it from a python script instead:

from requests_toolbelt.sessions import BaseUrlSession

cfg = {
    "apikey": "my_api_key",
    "password": "my_api_pwd",
    "storeid": "my_store_id",
    "api_version": "2021-04"
}

shop = BaseUrlSession(
    "https://{store}.myshopify.com/admin/api/{api_version}/".format(
        store=cfg["storeid"], api_version=cfg["api_version"]
    )
)
shop.auth = (cfg['apikey'], cfg['password'])

print(
    shop.post(
        "carrier_services.json",
        json={
            "carrier_service": {
                "name": "My Shipping Rate Provider",
                "callback_url": "https://my.domain/a/path",
                "service_discovery": False
            }
        }
    ).text
)

print(shop.get("carrier_services.json").text)

Best guess I have re why this didn’t work in Postman is something to do with headers. Once I had it working in Python, I moved on to the next pressing matter on my todo list.

I had the same issue. Yes, seems to be related to Postman. I was able to fix it by clearing the “cookies” in my Postman Headers request:

  • go to your request Headers

  • click on the “x hidden” headers to reveal hidden headers

  • find the “cookie” and click on “go to cookies”

Then I deleted all the cookies for the domain I was posting to. Now when I run the query again it no longer returns the HTML authorization in the body! Success!

Note: if anyone else runs into this issue, you can only create one CarrierService per Private App / Custom App. So if you try to create a new CarrierService (with a Custom App that has already created one) you’ll receive an error saying “[name of carrier] is already configured”.